-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: support reading tables partitioned on a nested column #19123
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
49ab365
30b1874
8e064fa
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 |
|---|---|---|
|
|
@@ -210,7 +210,9 @@ class HoodieFileGroupReaderBasedFileFormat(tablePath: String, | |
| } | ||
| originalVectorTypes.map { | ||
| o: Seq[String] => o.zipWithIndex.map(a => { | ||
| if (a._2 >= requiredSchema.length && mandatoryFields.contains(partitionSchema.fields(a._2 - requiredSchema.length).name)) { | ||
| if (a._2 >= requiredSchema.length | ||
|
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. 🤖 nit:
Contributor
Author
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. Done in 30b1874 — pulled the repeated |
||
| && mandatoryFields.contains(partitionSchema.fields(a._2 - requiredSchema.length).name) | ||
| && !isNestedPartitionField(partitionSchema.fields(a._2 - requiredSchema.length).name)) { | ||
| regularVectorType | ||
| } else { | ||
| a._1 | ||
|
|
@@ -253,7 +255,11 @@ class HoodieFileGroupReaderBasedFileFormat(tablePath: String, | |
| val augmentedStorageConf = new HadoopStorageConfiguration(hadoopConf).getInline | ||
| setSchemaEvolutionConfigs(augmentedStorageConf) | ||
| augmentedStorageConf.set(ENABLE_LOGICAL_TIMESTAMP_REPAIR, hasTimestampMillisFieldInTableSchema.toString) | ||
| val (remainingPartitionSchemaArr, fixedPartitionIndexesArr) = partitionSchema.fields.toSeq.zipWithIndex.filter(p => !mandatoryFields.contains(p._1.name)).unzip | ||
| // Nested partition columns (e.g. "nested_record.level") are never read from the data file: the | ||
| // flattened dotted name is not a valid top-level field and the value is materialized from the | ||
| // partition path. Always keep them in the appended ("remaining") partition fields so they are | ||
| // not converted into a top-level Avro field below, which would fail Avro name validation. | ||
| val (remainingPartitionSchemaArr, fixedPartitionIndexesArr) = partitionSchema.fields.toSeq.zipWithIndex.filter(p => !mandatoryFields.contains(p._1.name) || isNestedPartitionField(p._1.name)).unzip | ||
|
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. 🤖 Now that a nested partition field can be appended (remaining) while a top-level partition field is still read from the file, the snapshot/MOR path hits
Contributor
Author
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. Both To cover exactly the mixed scenario you describe (a top-level partition column read from the file + a nested partition column appended from the path), I added |
||
|
|
||
| // The schema of the partition cols we want to append the value instead of reading from the file | ||
| val remainingPartitionSchema = StructType(remainingPartitionSchemaArr) | ||
|
|
@@ -265,9 +271,9 @@ class HoodieFileGroupReaderBasedFileFormat(tablePath: String, | |
| val exclusionFields = new java.util.HashSet[String]() | ||
| exclusionFields.add("op") | ||
| partitionSchema.fields.foreach(f => exclusionFields.add(f.name)) | ||
| val requestedStructType = StructType(requiredSchema.fields ++ partitionSchema.fields.filter(f => mandatoryFields.contains(f.name))) | ||
| val requestedStructType = StructType(requiredSchema.fields ++ partitionSchema.fields.filter(f => mandatoryFields.contains(f.name) && !isNestedPartitionField(f.name))) | ||
|
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. 🤖 A partition field lands in
Contributor
Author
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. Good question, but there is no regression here for a nested partition field specifically. A nested partition column ( The precombine/merge value is unaffected: it is read from the Note the guard is scoped to nested (dotted) names — top-level mandatory partition columns (incl. variable timestamp/custom-keygen columns) are still read from the file exactly as before. Covered by the two regression tests added in 30b1874.
Contributor
Author
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. @yihua Have a question to clarify here - required nested partitioning fields will be read via the data file or will be parsed from the partition path? That's the bug this PR is trying to fix.
Contributor
Author
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. The "mandatory AND not-nested" (i.e. read-from-file) predicate is now duplicated here, at L279, and in private def partitionFieldReadFromFile(field: StructField): Boolean =
mandatoryFields.contains(field.name) && !isNestedPartitionField(field.name)and reusing it in all four spots. That keeps the negated form at L265 from silently drifting out of sync with the positive forms if the condition ever changes. Non-blocking. |
||
| val requestedSchema = HoodieSchemaUtils.pruneDataSchema(schema, HoodieSchemaConversionUtils.convertStructTypeToHoodieSchema(requestedStructType, sanitizedTableName), exclusionFields) | ||
| val dataStructTypeWithMandatoryPartitionFields = StructType(dataStructType.fields ++ partitionSchema.fields.filter(f => mandatoryFields.contains(f.name))) | ||
| val dataStructTypeWithMandatoryPartitionFields = StructType(dataStructType.fields ++ partitionSchema.fields.filter(f => mandatoryFields.contains(f.name) && !isNestedPartitionField(f.name))) | ||
|
Contributor
Author
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. When the nested partition column is also the precombine/ordering field, it's now excluded from the |
||
| val dataSchema = HoodieSchemaUtils.pruneDataSchema(schema, HoodieSchemaConversionUtils.convertStructTypeToHoodieSchema(dataStructTypeWithMandatoryPartitionFields, sanitizedTableName), exclusionFields) | ||
|
|
||
| spark.sessionState.conf.setConfString("spark.sql.parquet.enableVectorizedReader", supportVectorizedRead.toString) | ||
|
|
@@ -548,6 +554,14 @@ class HoodieFileGroupReaderBasedFileFormat(tablePath: String, | |
| }.asInstanceOf[Iterator[InternalRow]] | ||
| } | ||
|
|
||
| /** | ||
| * A partition column whose name is a nested field path (e.g. "nested_record.level") cannot be | ||
| * read from the data file as a flat top-level column, nor converted into a top-level Avro field | ||
| * (Avro rejects '.' in names). Its value is always materialized from the partition path, so such | ||
| * fields are treated as appended partition fields rather than read from the file. | ||
| */ | ||
| private def isNestedPartitionField(name: String): Boolean = name.contains(".") | ||
|
Contributor
Author
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. nit: |
||
|
|
||
| private def getFixedPartitionValues(allPartitionValues: InternalRow, partitionSchema: StructType, fixedPartitionIndexes: Set[Int]): InternalRow = { | ||
| InternalRow.fromSeq(allPartitionValues.toSeq(partitionSchema).zipWithIndex.filter(p => fixedPartitionIndexes.contains(p._2)).map(p => p._1)) | ||
| } | ||
|
|
||
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.
🤖 Line 429: Following up on the earlier thread — I don't think this call site passes the full
partitionSchema. At line 341appendPartitionAndProjectis invoked withremainingPartitionSchemaas itspartitionSchemaarg, so herepartitionSchemais the remaining schema, whereasreadBaseFile(line 532) passes the full one. With a mix of one top-level mandatory field (read from file) + one nested field (appended), e.g. partitioncountry,nested_record.levelboth ordering fields: remaining=[nested_record.level] (len 1), indices={1}, partitionValues.numFields=2 → line 424 is false →getFixedPartitionValues(partitionValues, remaining, {1})doestoSeq(remaining)which materializes only ordinal 0 (country's value, as StringType) then filters to {1} → empty, so the nested value is dropped. The new tests are COW-only so they hitreadBaseFile(correct) and never this MOR branch. Could you confirm whether this should pass the fullpartitionSchematogetFixedPartitionValueshere (while keepingremainingPartitionSchemafor the join projection)?