|
109 | 109 | import static org.apache.hudi.common.util.DateTimeUtils.microsToInstant;
|
110 | 110 | import static org.apache.hudi.common.util.StringUtils.getUTF8Bytes;
|
111 | 111 | import static org.apache.hudi.common.util.ValidationUtils.checkState;
|
112 |
| -import static org.apache.hudi.metadata.HoodieMetadataPayload.SCHEMA_FIELD_ID_COLUMN_STATS; |
113 | 112 | import static org.apache.hudi.metadata.HoodieTableMetadataUtil.tryUpcastDecimal;
|
114 | 113 |
|
115 | 114 | /**
|
@@ -1474,16 +1473,14 @@ public static Comparable<?> unwrapAvroValueWrapper(Object avroValueWrapper) {
|
1474 | 1473 | * @param avroValueWrapper A wrapped value with Avro type wrapper.
|
1475 | 1474 | * @return Java value.
|
1476 | 1475 | */
|
1477 |
| - public static Comparable<?> unwrapAvroValueWrapper(Object avroValueWrapper, boolean handleObfuscatedFlow, Option<String> fieldName, Option<GenericRecord> record) { |
| 1476 | + public static Comparable<?> unwrapAvroValueWrapper(Object avroValueWrapper, boolean handleObfuscatedFlow, Option<String> fieldName, Option<GenericRecord> colStatsRecord) { |
1478 | 1477 | if (avroValueWrapper == null) {
|
1479 | 1478 | return null;
|
1480 | 1479 | }
|
1481 | 1480 |
|
1482 |
| - if (handleObfuscatedFlow) { |
1483 |
| - Pair<Boolean, String> isValueWrapperObfuscated = getIsValueWrapperObfuscated(record.get(), fieldName.get()); |
1484 |
| - if (isValueWrapperObfuscated.getKey()) { |
1485 |
| - return unwrapAvroValueWrapper(avroValueWrapper, isValueWrapperObfuscated.getValue()); |
1486 |
| - } |
| 1481 | + Pair<Boolean, String> isValueWrapperObfuscated = getIsValueWrapperObfuscated(avroValueWrapper); |
| 1482 | + if (isValueWrapperObfuscated.getKey()) { |
| 1483 | + return unwrapAvroValueWrapper(avroValueWrapper, isValueWrapperObfuscated.getValue()); |
1487 | 1484 | }
|
1488 | 1485 |
|
1489 | 1486 | if (avroValueWrapper instanceof DateWrapper) {
|
@@ -1524,27 +1521,44 @@ public static Comparable<?> unwrapAvroValueWrapper(Object avroValueWrapper, Stri
|
1524 | 1521 | if (avroValueWrapper == null) {
|
1525 | 1522 | return null;
|
1526 | 1523 | } else if (DateWrapper.class.getSimpleName().equals(wrapperClassName)) {
|
1527 |
| - return Date.valueOf(LocalDate.ofEpochDay((Integer)((Record) avroValueWrapper).get(0))); |
| 1524 | + if (avroValueWrapper instanceof GenericRecord) { |
| 1525 | + return Date.valueOf(LocalDate.ofEpochDay((Integer) ((GenericRecord) avroValueWrapper).get(0))); |
| 1526 | + } else { |
| 1527 | + return Date.valueOf(LocalDate.ofEpochDay((Integer) ((Record) avroValueWrapper).get(0))); |
| 1528 | + } |
1528 | 1529 | } else if (LocalDateWrapper.class.getSimpleName().equals(wrapperClassName)) {
|
1529 |
| - return LocalDate.ofEpochDay((Integer)((Record) avroValueWrapper).get(0)); |
| 1530 | + if (avroValueWrapper instanceof GenericRecord) { |
| 1531 | + return LocalDate.ofEpochDay((Integer) ((GenericRecord) avroValueWrapper).get(0)); |
| 1532 | + } else { |
| 1533 | + return LocalDate.ofEpochDay((Integer) ((Record) avroValueWrapper).get(0)); |
| 1534 | + } |
1530 | 1535 | } else if (TimestampMicrosWrapper.class.getSimpleName().equals(wrapperClassName)) {
|
1531 |
| - Instant instant = microsToInstant((Long)((Record) avroValueWrapper).get(0)); |
1532 |
| - return Timestamp.from(instant); |
| 1536 | + if (avroValueWrapper instanceof GenericRecord) { |
| 1537 | + Instant instant = microsToInstant((Long) ((GenericRecord) avroValueWrapper).get(0)); |
| 1538 | + return Timestamp.from(instant); |
| 1539 | + } else { |
| 1540 | + Instant instant = microsToInstant((Long) ((Record) avroValueWrapper).get(0)); |
| 1541 | + return Timestamp.from(instant); |
| 1542 | + } |
1533 | 1543 | } else if (DecimalWrapper.class.getSimpleName().equals(wrapperClassName)) {
|
1534 | 1544 | Schema valueSchema = DecimalWrapper.SCHEMA$.getField("value").schema();
|
1535 |
| - return AVRO_DECIMAL_CONVERSION.fromBytes((ByteBuffer) ((Record) avroValueWrapper).get(0), valueSchema, valueSchema.getLogicalType()); |
| 1545 | + if (avroValueWrapper instanceof GenericRecord) { |
| 1546 | + return AVRO_DECIMAL_CONVERSION.fromBytes((ByteBuffer)((GenericRecord) avroValueWrapper).get(0), valueSchema, valueSchema.getLogicalType()); |
| 1547 | + } else { |
| 1548 | + return AVRO_DECIMAL_CONVERSION.fromBytes((ByteBuffer) ((Record) avroValueWrapper).get(0), valueSchema, valueSchema.getLogicalType()); |
| 1549 | + } |
1536 | 1550 | } else {
|
1537 | 1551 | throw new UnsupportedOperationException(String.format("Unsupported type of the value (%s)", avroValueWrapper.getClass()));
|
1538 | 1552 | }
|
1539 | 1553 | }
|
1540 | 1554 |
|
1541 |
| - private static Pair<Boolean, String> getIsValueWrapperObfuscated(GenericRecord record, String subFieldName) { |
1542 |
| - Object statsValue = ((GenericRecord) record.get(SCHEMA_FIELD_ID_COLUMN_STATS)).get(subFieldName); |
| 1555 | + private static Pair<Boolean, String> getIsValueWrapperObfuscated(Object statsValue) { |
1543 | 1556 | if (statsValue != null) {
|
1544 | 1557 | String statsValueSchemaClassName = ((GenericRecord) statsValue).getSchema().getName();
|
1545 | 1558 | boolean toReturn = statsValueSchemaClassName.equals(DateWrapper.class.getSimpleName())
|
1546 | 1559 | || statsValueSchemaClassName.equals(LocalDateWrapper.class.getSimpleName())
|
1547 |
| - || statsValueSchemaClassName.equals(TimestampMicrosWrapper.class.getSimpleName()); |
| 1560 | + || statsValueSchemaClassName.equals(TimestampMicrosWrapper.class.getSimpleName()) |
| 1561 | + || statsValueSchemaClassName.equals(DecimalWrapper.class.getSimpleName()); |
1548 | 1562 | if (toReturn) {
|
1549 | 1563 | return Pair.of(true, ((GenericRecord) statsValue).getSchema().getName());
|
1550 | 1564 | }
|
|
0 commit comments