-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-3215] Solve UT for Spark 3.2 #4565
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,14 +28,15 @@ import org.apache.hudi.exception.HoodieException | |
| import org.apache.hudi.hadoop.config.HoodieRealtimeConfig | ||
| import org.apache.hudi.hadoop.utils.HoodieInputFormatUtils.HOODIE_RECORD_KEY_COL_POS | ||
| import org.apache.spark.rdd.RDD | ||
| import org.apache.spark.sql.avro.{HoodieAvroSerializer, HoodieAvroDeserializer} | ||
| import org.apache.spark.sql.avro.{HoodieAvroDeserializer, HoodieAvroSerializer} | ||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.catalyst.expressions.{SpecificInternalRow, UnsafeProjection} | ||
| import org.apache.spark.sql.execution.datasources.PartitionedFile | ||
| import org.apache.spark.sql.vectorized.ColumnarBatch | ||
| import org.apache.spark.{Partition, SerializableWritable, SparkContext, TaskContext} | ||
|
|
||
| import java.io.Closeable | ||
| import java.util.Properties | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
| import scala.collection.mutable | ||
|
|
@@ -54,15 +55,18 @@ class HoodieMergeOnReadRDD(@transient sc: SparkContext, | |
| private val preCombineField = tableState.preCombineField | ||
| private val recordKeyFieldOpt = tableState.recordKeyFieldOpt | ||
| private val payloadProps = if (preCombineField.isDefined) { | ||
| Some(HoodiePayloadConfig.newBuilder.withPayloadOrderingField(preCombineField.get).build.getProps) | ||
| HoodiePayloadConfig.newBuilder | ||
| .withPayloadOrderingField(preCombineField.get) | ||
| .build.getProps | ||
| } else { | ||
| None | ||
| new Properties() | ||
| } | ||
| override def compute(split: Partition, context: TaskContext): Iterator[InternalRow] = { | ||
| val mergeOnReadPartition = split.asInstanceOf[HoodieMergeOnReadPartition] | ||
| val iter = mergeOnReadPartition.split match { | ||
| case dataFileOnlySplit if dataFileOnlySplit.logPaths.isEmpty => | ||
| read(dataFileOnlySplit.dataFile.get, requiredSchemaFileReader) | ||
| val rows = read(dataFileOnlySplit.dataFile.get, requiredSchemaFileReader) | ||
| extractRequiredSchema(rows) | ||
| case logFileOnlySplit if logFileOnlySplit.dataFile.isEmpty => | ||
| logFileIterator(logFileOnlySplit, getConfig) | ||
| case skipMergeSplit if skipMergeSplit.mergeType | ||
|
|
@@ -118,6 +122,18 @@ class HoodieMergeOnReadRDD(@transient sc: SparkContext, | |
| rows | ||
| } | ||
|
|
||
| private def extractRequiredSchema(iter: Iterator[InternalRow]): Iterator[InternalRow] = { | ||
| val tableAvroSchema = new Schema.Parser().parse(tableState.tableAvroSchema) | ||
| val requiredAvroSchema = new Schema.Parser().parse(tableState.requiredAvroSchema) | ||
|
Member
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. this is not used?
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. yes, i should remove this. |
||
| val requiredFieldPosition = tableState.requiredStructSchema | ||
| .map(f => tableAvroSchema.getField(f.name).pos()).toList | ||
| val unsafeProjection = UnsafeProjection.create(tableState.requiredStructSchema) | ||
| val rows = iter.map { row => | ||
| unsafeProjection(createRowWithRequiredSchema(row, requiredFieldPosition)) | ||
| } | ||
| rows | ||
| } | ||
|
|
||
| private def logFileIterator(split: HoodieMergeOnReadFileSplit, | ||
| config: Configuration): Iterator[InternalRow] = | ||
| new Iterator[InternalRow] with Closeable { | ||
|
|
@@ -188,7 +204,8 @@ class HoodieMergeOnReadRDD(@transient sc: SparkContext, | |
| @scala.annotation.tailrec | ||
| override def hasNext: Boolean = { | ||
| if (baseFileIterator.hasNext) { | ||
| recordToLoad = baseFileIterator.next() | ||
| val curRow = baseFileIterator.next() | ||
| recordToLoad = unsafeProjection(createRowWithRequiredSchema(curRow, requiredFieldPosition)) | ||
| true | ||
| } else { | ||
| if (logRecordsKeyIterator.hasNext) { | ||
|
|
@@ -272,7 +289,7 @@ class HoodieMergeOnReadRDD(@transient sc: SparkContext, | |
| } | ||
| } else { | ||
| // No merge needed, load current row with required schema | ||
| recordToLoad = unsafeProjection(createRowWithRequiredSchema(curRow)) | ||
| recordToLoad = unsafeProjection(createRowWithRequiredSchema(curRow, requiredFieldPosition)) | ||
| true | ||
| } | ||
| } else { | ||
|
|
@@ -317,32 +334,29 @@ class HoodieMergeOnReadRDD(@transient sc: SparkContext, | |
| } | ||
| } | ||
|
|
||
| private def createRowWithRequiredSchema(row: InternalRow): InternalRow = { | ||
| val rowToReturn = new SpecificInternalRow(tableState.requiredStructSchema) | ||
| val posIterator = requiredFieldPosition.iterator | ||
| var curIndex = 0 | ||
| tableState.requiredStructSchema.foreach( | ||
| f => { | ||
| val curPos = posIterator.next() | ||
| val curField = if (row.isNullAt(curPos)) null else row.get(curPos, f.dataType) | ||
| rowToReturn.update(curIndex, curField) | ||
| curIndex = curIndex + 1 | ||
| } | ||
| ) | ||
| rowToReturn | ||
| } | ||
|
|
||
| private def mergeRowWithLog(curRow: InternalRow, curKey: String) = { | ||
| val historyAvroRecord = serializer.serialize(curRow).asInstanceOf[GenericRecord] | ||
| if (payloadProps.isDefined) { | ||
| logRecords.get(curKey).getData.combineAndGetUpdateValue(historyAvroRecord, | ||
| tableAvroSchema, payloadProps.get) | ||
| } else { | ||
| logRecords.get(curKey).getData.combineAndGetUpdateValue(historyAvroRecord, tableAvroSchema) | ||
| } | ||
| logRecords.get(curKey).getData.combineAndGetUpdateValue( | ||
| historyAvroRecord, tableAvroSchema, payloadProps) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private def createRowWithRequiredSchema(row: InternalRow, requiredFieldPosition: Seq[Int]): InternalRow = { | ||
| val rowToReturn = new SpecificInternalRow(tableState.requiredStructSchema) | ||
| val posIterator = requiredFieldPosition.iterator | ||
| var curIndex = 0 | ||
| tableState.requiredStructSchema.foreach( | ||
| f => { | ||
| val curPos = posIterator.next() | ||
| val curField = if (row.isNullAt(curPos)) null else row.get(curPos, f.dataType) | ||
| rowToReturn.update(curIndex, curField) | ||
| curIndex = curIndex + 1 | ||
| } | ||
| ) | ||
| rowToReturn | ||
| } | ||
|
|
||
| } | ||
|
|
||
| private object HoodieMergeOnReadRDD { | ||
| val CONFIG_INSTANTIATION_LOCK = new Object() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
the name could imply returning schema