yihua commented on code in PR #13694:
URL: https://github.com/apache/hudi/pull/13694#discussion_r2268297362
##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/cdc/CDCFileGroupIterator.scala:
##########
@@ -489,24 +500,22 @@ class CDCFileGroupIterator(split: HoodieCDCFileGroupSplit,
.withProps(readerProperties)
.withLatestCommitTime(split.changes.last.getInstant)
.build()
-
CloseableIteratorListener.addListener(fileGroupReader.getClosableIterator).asScala
+
CloseableIteratorListener.addListener(fileGroupReader.getClosableBufferedRecordIterator).asScala
}
private def loadLogFile(logFile: HoodieLogFile, instant: String):
Iterator[BufferedRecord[InternalRow]] = {
val partitionPath =
FSUtils.getRelativePartitionPath(metaClient.getBasePath,
logFile.getPath.getParent)
- val readerContext = new
SparkFileFormatInternalRowReaderContext(baseFileReader, Seq.empty, Seq.empty,
- conf, metaClient.getTableConfig)
readerContext.setLatestCommitTime(instant)
readerContext.setHasBootstrapBaseFile(false)
readerContext.setHasLogFiles(true)
- readerContext.initRecordMerger(readerProperties)
readerContext.setSchemaHandler(
new FileGroupReaderSchemaHandler[InternalRow](readerContext, avroSchema,
avroSchema,
Option.empty(), metaClient.getTableConfig, readerProperties))
val stats = new HoodieReadStats
- val recordBuffer = new
KeyBasedFileGroupRecordBuffer[InternalRow](readerContext, metaClient,
readerContext.getMergeMode,
+ keyBasedFileGroupRecordBuffer.ifPresent(k => k.close())
+ keyBasedFileGroupRecordBuffer = Option.of(new
KeyBasedFileGroupRecordBuffer[InternalRow](readerContext, metaClient,
readerContext.getMergeMode,
Review Comment:
What's the reason of reusing `keyBasedFileGroupRecordBuffer` variable here?
##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/cdc/CDCFileGroupIterator.scala:
##########
@@ -516,17 +525,19 @@ class CDCFileGroupIterator(split: HoodieCDCFileGroupSplit,
.withBufferSize(HoodieMetadataConfig.MAX_READER_BUFFER_SIZE_PROP.defaultValue)
.withPartition(partitionPath)
.withMetaClient(metaClient)
- .withRecordBuffer(recordBuffer)
+ .withRecordBuffer(keyBasedFileGroupRecordBuffer.get())
.build
-
CloseableIteratorListener.addListener(recordBuffer.getLogRecordIterator).asScala
+
CloseableIteratorListener.addListener(keyBasedFileGroupRecordBuffer.get().getLogRecordIterator).asScala
}
/**
* Convert InternalRow to json string.
*/
- private def convertRowToJsonString(record: InternalRow): UTF8String = {
- internalRowToJsonStringConverter.convert(record)
+ private def convertBufferedRecordToJsonString(record:
BufferedRecord[InternalRow]): UTF8String = {
+ internalRowToJsonStringConverterMap.getOrElseUpdate(record.getSchemaId,
+ new
InternalRowToJsonStringConverter(HoodieInternalRowUtils.getCachedSchema(readerContext.getRecordContext.decodeAvroSchema(record.getSchemaId))))
Review Comment:
@jonvex could you write a test or add breakpoints to validate that
`InternalRowToJsonStringConverter` is constructed once per schema ID?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]