Skip to content

Commit

Permalink
Fixed MOR schema-pruning seq to prune only columns required for mergi…
Browse files Browse the repository at this point in the history
…ng (and not ones required for incremental reads for ex)
  • Loading branch information
Alexey Kudinkin committed Apr 26, 2022
1 parent e494e1f commit 0c4b09e
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MergeOnReadSnapshotRelation(sqlContext: SQLContext,
override type FileSplit = HoodieMergeOnReadFileSplit

/**
* NOTE: These are the fields that are required to properly fulfil Hudi's Merge-on-Read
* NOTE: These are the fields that are required to properly fulfil Merge-on-Read (MOR)
* semantic:
*
* <ol>
Expand All @@ -65,9 +65,11 @@ class MergeOnReadSnapshotRelation(sqlContext: SQLContext,
* of primary-key or pre-combine-key are required to be fetched from storage (unless requested
* by the query), therefore saving on throughput
*/
override lazy val mandatoryFields: Seq[String] =
protected lazy val mandatoryFieldsForMerging: Seq[String] =
Seq(recordKeyField) ++ preCombineFieldOpt.map(Seq(_)).getOrElse(Seq())

override lazy val mandatoryFields: Seq[String] = mandatoryFieldsForMerging

protected val mergeType: String = optParams.getOrElse(DataSourceReadOptions.REALTIME_MERGE.key,
DataSourceReadOptions.REALTIME_MERGE.defaultValue)

Expand Down Expand Up @@ -188,7 +190,7 @@ class MergeOnReadSnapshotRelation(sqlContext: SQLContext,
}

protected def pruneSchemaForMergeSkipping(requiredSchema: HoodieTableSchema): HoodieTableSchema = {
val mandatoryFieldNames = mandatoryFields.map(fieldName => HoodieAvroUtils.getRootLevelFieldName(fieldName))
val mandatoryFieldNames = mandatoryFieldsForMerging.map(fieldName => HoodieAvroUtils.getRootLevelFieldName(fieldName))
val prunedStructSchema = StructType(
requiredSchema.structTypeSchema.fields.filterNot(f => mandatoryFieldNames.contains(f.name))
)
Expand Down

0 comments on commit 0c4b09e

Please sign in to comment.