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-38094][SQL][FOLLOWUP] Fix exception message and add a test case #35700

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -140,7 +140,7 @@ object ParquetReadSupport extends Logging {
"Spark read schema expects field Ids, " +
"but Parquet file schema doesn't contain any field Ids.\n" +
"Please remove the field ids from Spark schema or ignore missing ids by " +
"setting `spark.sql.parquet.fieldId.ignoreMissing = true`\n" +
"setting `spark.sql.parquet.fieldId.read.ignoreMissing = true`\n" +
s"""
|Spark read schema:
|${catalystRequestedSchema.prettyJson}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.apache.spark.SparkException
import org.apache.spark.sql.{QueryTest, Row}
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.test.SharedSparkSession
import org.apache.spark.sql.types.{IntegerType, Metadata, MetadataBuilder, StringType, StructType}
import org.apache.spark.sql.types.{ArrayType, IntegerType, MapType, Metadata, MetadataBuilder, StringType, StructType}

class ParquetFieldIdIOSuite extends QueryTest with ParquetTest with SharedSparkSession {

Expand Down Expand Up @@ -107,6 +107,35 @@ class ParquetFieldIdIOSuite extends QueryTest with ParquetTest with SharedSparkS
}
}

test("absence of field ids: reading nested schema") {
withTempDir { dir =>
// now with nested schema/complex type
val readSchema =
new StructType()
.add("a", IntegerType, true, withId(1))
.add("b", ArrayType(StringType), true, withId(2))
.add("c", new StructType().add("xx", IntegerType, true, withId(6)), true, withId(3))
.add("d", MapType(StringType, StringType), true, withId(4))
.add("e", IntegerType, true, withId(5))

val writeSchema =
new StructType()
.add("a", IntegerType, true, withId(5))
.add("randomName", StringType, true)

val writeData = Seq(Row(100, "text"), Row(200, "more"))

spark.createDataFrame(writeData.asJava, writeSchema)
.write.mode("overwrite").parquet(dir.getCanonicalPath)

withAllParquetReaders {
checkAnswer(spark.read.schema(readSchema).parquet(dir.getCanonicalPath),
// a, b, c, d all couldn't be found
Row(null, null, null, null, 100) :: Row(null, null, null, null, 200) :: Nil)
}
}
}

test("multiple id matches") {
withTempDir { dir =>
val readSchema =
Expand Down