-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-11679][SQL] Invoking method " apply(fields: java.util.List[StructField])" in "StructType" gets ClassCastException #9649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
1208354
647bf2b
c639ab4
4496753
2ebeb4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -328,7 +328,8 @@ object StructType extends AbstractDataType { | |
| def apply(fields: Seq[StructField]): StructType = StructType(fields.toArray) | ||
|
|
||
| def apply(fields: java.util.List[StructField]): StructType = { | ||
| StructType(fields.toArray.asInstanceOf[Array[StructField]]) | ||
| import scala.collection.JavaConverters._ | ||
| StructType(fields.asScala) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this change, was there any issue when we use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| protected[sql] def fromAttributes(attributes: Seq[Attribute]): StructType = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -209,6 +209,12 @@ public void testCreateDataFromFromList() { | |
| Assert.assertEquals(1, result.length); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCreateStructTypeFromList(){ | ||
| StructType schema = StructType$.MODULE$.apply(Arrays.asList(createStructField("i", IntegerType, true))); | ||
| Assert.assertEquals(0, schema.fieldIndex("i")); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried this test case locally, but can't reproduce the bug. However, the code snippet you provided in the JIRA do reproduce the bug. Can you investigate this and improve the test? Thanks! |
||
| } | ||
|
|
||
| private static final Comparator<Row> crosstabRowComparator = new Comparator<Row>() { | ||
| @Override | ||
| public int compare(Row row1, Row row2) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related, we should just deprecate this. Its weird to have an
applyfor java.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Yes, a java friendly API is preferred.