|
62 | 62 | import java.util.Properties; |
63 | 63 | import java.util.Set; |
64 | 64 | import java.util.concurrent.atomic.AtomicLong; |
| 65 | +import java.util.function.Function; |
65 | 66 | import java.util.stream.Collectors; |
66 | 67 |
|
67 | 68 | import static org.apache.hudi.TypeUtils.unsafeCast; |
@@ -90,7 +91,7 @@ public abstract class AbstractHoodieLogRecordReader { |
90 | 91 | // Latest valid instant time |
91 | 92 | // Log-Blocks belonging to inflight delta-instants are filtered-out using this high-watermark. |
92 | 93 | private final String latestInstantTime; |
93 | | - private final HoodieTableMetaClient hoodieTableMetaClient; |
| 94 | + protected final HoodieTableMetaClient hoodieTableMetaClient; |
94 | 95 | // Merge strategy to use when combining records from log |
95 | 96 | private final String payloadClassFQN; |
96 | 97 | // preCombine field |
@@ -382,20 +383,36 @@ private boolean isNewInstantBlock(HoodieLogBlock logBlock) { |
382 | 383 | * handle it. |
383 | 384 | */ |
384 | 385 | private void processDataBlock(HoodieDataBlock dataBlock, Option<KeySpec> keySpecOpt) throws Exception { |
385 | | - Map<String, Object> mapperConfig = MapperUtils.buildMapperConfig(this.payloadClassFQN, this.preCombineField, this.simpleKeyGenFields, this.withOperationField, this.partitionName); |
386 | | - try (ClosableIterator<HoodieRecord> recordIterator = getRecordsIterator(dataBlock, keySpecOpt, recordType, mapperConfig)) { |
387 | | - Option<Schema> schemaOption = getMergedSchema(dataBlock); |
388 | | - Schema finalReadSchema = ((MappingIterator) recordIterator).getSchema(); |
389 | | - while (recordIterator.hasNext()) { |
390 | | - HoodieRecord<?> currentRecord = recordIterator.next(); |
391 | | - HoodieRecord<?> record = schemaOption.isPresent() |
392 | | - ? currentRecord.rewriteRecordWithNewSchema(finalReadSchema, new Properties(), schemaOption.get(), new HashMap<>()) : currentRecord; |
393 | | - processNextRecord(record); |
394 | | - totalLogRecords.incrementAndGet(); |
| 386 | + Map<String, Object> mapperConfig = MapperUtils.buildMapperConfig(this.payloadClassFQN, this.preCombineField, this.simpleKeyGenFields, this.withOperationField, |
| 387 | + this.partitionName, getPopulateMetaFields()); |
| 388 | + |
| 389 | + Option<Schema> schemaOption = getMergedSchema(dataBlock); |
| 390 | + if (schemaOption.isPresent()) { |
| 391 | + try (ClosableIterator<HoodieRecord> recordIterator = getRecordsIterator(dataBlock, keySpecOpt, recordType)) { |
| 392 | + Schema finalReadSchema = ((MappingIterator) recordIterator).getSchema(); |
| 393 | + while (recordIterator.hasNext()) { |
| 394 | + HoodieRecord currentRecord = recordIterator.next(); |
| 395 | + HoodieRecord record = currentRecord.rewriteRecordWithNewSchema(finalReadSchema, new Properties(), schemaOption.get(), new HashMap<>()) |
| 396 | + .expansion(schemaOption.get(), new Properties(), mapperConfig); |
| 397 | + processNextRecord(record); |
| 398 | + totalLogRecords.incrementAndGet(); |
| 399 | + } |
| 400 | + } |
| 401 | + } else { |
| 402 | + try (ClosableIterator<HoodieRecord> recordIterator = getRecordsIterator(dataBlock, keySpecOpt, recordType, mapperConfig)) { |
| 403 | + while (recordIterator.hasNext()) { |
| 404 | + HoodieRecord currentRecord = recordIterator.next(); |
| 405 | + processNextRecord(currentRecord); |
| 406 | + totalLogRecords.incrementAndGet(); |
| 407 | + } |
395 | 408 | } |
396 | 409 | } |
397 | 410 | } |
398 | 411 |
|
| 412 | + protected boolean getPopulateMetaFields() { |
| 413 | + return this.populateMetaFields; |
| 414 | + } |
| 415 | + |
399 | 416 | /** |
400 | 417 | * Get final Read Schema for support evolution. |
401 | 418 | * step1: find the fileSchema for current dataBlock. |
@@ -486,14 +503,22 @@ private ClosableIterator<HoodieRecord> getRecordsIterator(HoodieDataBlock dataBl |
486 | 503 | finalReadSchema = dataBlock.getSchema(); |
487 | 504 | } |
488 | 505 |
|
489 | | - return new MappingIterator<>(iter, rec -> { |
490 | | - try { |
491 | | - return rec.expansion(readerSchema, new Properties(), mapperConfig); |
492 | | - } catch (IOException e) { |
493 | | - LOG.error("Error expanse " + rec, e); |
494 | | - throw new HoodieException(e); |
495 | | - } |
496 | | - }, finalReadSchema); |
| 506 | + if (mapperConfig == null) { |
| 507 | + return new MappingIterator<>(iter, Function.identity(), finalReadSchema); |
| 508 | + } else { |
| 509 | + return new MappingIterator<>(iter, rec -> { |
| 510 | + try { |
| 511 | + return rec.expansion(readerSchema, new Properties(), mapperConfig); |
| 512 | + } catch (IOException e) { |
| 513 | + LOG.error("Error expanse " + rec, e); |
| 514 | + throw new HoodieException(e); |
| 515 | + } |
| 516 | + }, finalReadSchema); |
| 517 | + } |
| 518 | + } |
| 519 | + |
| 520 | + private ClosableIterator<HoodieRecord> getRecordsIterator(HoodieDataBlock dataBlock, Option<KeySpec> keySpecOpt, HoodieRecordType type) throws IOException { |
| 521 | + return getRecordsIterator(dataBlock, keySpecOpt, type, null); |
497 | 522 | } |
498 | 523 |
|
499 | 524 | /** |
|
0 commit comments