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 @@ -434,7 +434,7 @@ case class DataSource(
hs.partitionSchema,
"in the partition schema",
equality)
DataSourceUtils.verifySchema(hs.fileFormat, hs.dataSchema)
DataSourceUtils.checkFieldType(hs.fileFormat, hs.dataSchema)
case _ =>
SchemaUtils.checkSchemaColumnNameDuplication(
relation.schema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,16 @@ object DataSourceUtils extends PredicateHelper {
* in a driver side.
*/
def verifySchema(format: FileFormat, schema: StructType): Unit = {
checkFieldType(format, schema)
checkFieldNames(format, schema)
Copy link
Member

Choose a reason for hiding this comment

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

Does this PR change anything? it looks like a refactoring by pulling out part of verifySchema as a separate method checkFieldType.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this PR change anything? it looks like a refactoring by pulling out part of verifySchema as a separate method checkFieldType.

oh, sorry, one file was not chosen when commit change

}

def checkFieldType(format: FileFormat, schema: StructType): Unit = {
schema.foreach { field =>
if (!format.supportDataType(field.dataType)) {
throw QueryCompilationErrors.dataTypeUnsupportedByDataSourceError(format.toString, field)
}
}
checkFieldNames(format, schema)
}

// SPARK-24626: Metadata files and temporary files should not be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ trait FileFormat {
def supportDataType(dataType: DataType): Boolean = true

/**
* Returns whether this format supports the given filed name in read/write path.
* Returns whether this format supports the given filed name in write path.
* By default all field name is supported.
*/
def supportFieldName(name: String): Boolean = true
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4243,6 +4243,14 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession with AdaptiveSpark
checkAnswer(df3, df4)
}
}

test("SPARK-27442: Spark support read parquet file with invalid char in field name") {
withResourceTempPath("test-data/field_with_invalid_char.snappy.parquet") { dir =>
Copy link
Contributor

Choose a reason for hiding this comment

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

We can write the parquet file in the test, instead of generating it ahead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can write the parquet file in the test, instead of generating it ahead.

Updated

val df = spark.read.parquet(dir.getAbsolutePath)
checkAnswer(df, Row(1, 2, 3) :: Nil)
assert(df.schema.names.sameElements(Array("max(t)", "a b", "{")))
Copy link
Contributor

@cloud-fan cloud-fan Jan 18, 2022

Choose a reason for hiding this comment

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

can we include dot as well? I'm wondering if the parquet lib forbids dot or not during writing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can we include dot as well? I'm wondering if the parquet lib forbids dot or not during writing.

Added

}
}
}

case class Foo(bar: Option[String])