Skip to content
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

[SPARK-27442][SQL] Remove check field name when reading/writing data in parquet #35229

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -434,7 +434,8 @@ case class DataSource(
hs.partitionSchema,
"in the partition schema",
equality)
DataSourceUtils.verifySchema(hs.fileFormat, hs.dataSchema)
DataSourceUtils.verifySchema(hs.fileFormat, hs.dataSchema,
!hs.fileFormat.isInstanceOf[ParquetFileFormat])
Copy link
Member

Choose a reason for hiding this comment

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

Hmm I think this doesn't compile?

case _ =>
SchemaUtils.checkSchemaColumnNameDuplication(
relation.schema,
Expand Down
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
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.
12 changes: 12 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Expand Up @@ -4243,6 +4243,18 @@ 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, 4, 5, 6) :: Row(2, 4, 6, 8, 10, 12) :: Nil)
assert(df.schema.names.sameElements(Array("max(t)", "a b", "{", ".", "a.b", "a")))
checkAnswer(df.select("`max(t)`", "`a b`", "`{`", "`.`", "`a.b`")
, Row(1, 2, 3, 4, 5) :: Row(2, 4, 6, 8, 10) :: Nil)
checkAnswer(df.where("`a.b` > 8"),
Row(2, 4, 6, 8, 10, 12) :: Nil)
}
}
}

case class Foo(bar: Option[String])