Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {

Copy link
Copy Markdown
Contributor

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 apply for java.

Copy link
Copy Markdown
Contributor Author

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.

StructType(fields.toArray.asInstanceOf[Array[StructField]])
import scala.collection.JavaConverters._
StructType(fields.asScala)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this change, was there any issue when we use org.apache.spark.sql.types.DataTypes.createStructType? Or, the problem only appear when we use this apply method directly?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DataTypes.createStructType works well because it use fields.toArray(new StructField[0]). However, I think it's bad to create an empty StructField array every time we call that method.
You remind me that we should also update DataTypes.createStructType to use this apply method.

}

protected[sql] def fromAttributes(attributes: Seq[Attribute]): StructType =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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) {
Expand Down