Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.hudi.util.DataTypeUtils;
import org.apache.hudi.util.RowDataProjection;
import org.apache.hudi.util.RowDataToAvroConverters;
import org.apache.hudi.util.StreamerUtil;
import org.apache.hudi.util.StringToRowDataConverter;

import org.apache.avro.Schema;
Expand All @@ -63,6 +64,7 @@
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -634,6 +636,8 @@ static class MergeIterator implements RecordIterator {

private final Set<String> keyToSkip = new HashSet<>();

private Properties payloadProps;

private RowData currentRecord;

MergeIterator(
Expand All @@ -651,6 +655,7 @@ static class MergeIterator implements RecordIterator {
this.tableSchema = tableSchema;
this.reader = reader;
this.scanner = FormatUtils.logScanner(split, tableSchema, finkConf, hadoopConf);
this.payloadProps = StreamerUtil.getHoodieClientConfig(finkConf).getPayloadConfig().getProps();
this.logKeysIterator = scanner.getRecords().keySet().iterator();
this.requiredSchema = requiredSchema;
this.requiredPos = requiredPos;
Expand Down Expand Up @@ -751,7 +756,7 @@ private Option<IndexedRecord> mergeRowWithLog(
String curKey) throws IOException {
final HoodieAvroRecord<?> record = (HoodieAvroRecord) scanner.getRecords().get(curKey);
GenericRecord historyAvroRecord = (GenericRecord) rowDataToAvroConverter.convert(tableSchema, curRow);
return record.getData().combineAndGetUpdateValue(historyAvroRecord, tableSchema);
return record.getData().combineAndGetUpdateValue(historyAvroRecord, tableSchema, payloadProps);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,56 @@ void testWriteAndReadWithDataSkipping() {
+ "+I[id7, Bob, 44, 1970-01-01T00:00:07, par4], "
+ "+I[id8, Han, 56, 1970-01-01T00:00:08, par4]]");
}

@ParameterizedTest
@EnumSource(value = HoodieTableType.class)
void testWriteAndCompactAndRead(HoodieTableType tableType) {
TableEnvironment tableEnv = streamTableEnv;
String hoodieTableDDL = sql("t1")
.field("uuid int")
.field("ts int")
.noPartition()
.option(FlinkOptions.PATH, tempFile.getAbsolutePath())
.option(FlinkOptions.READ_DATA_SKIPPING_ENABLED, true)
.option(FlinkOptions.COMPACTION_DELTA_COMMITS, 3)
.option("hoodie.compact.inline", true)
.option(FlinkOptions.PRE_COMBINE, true)
.option(FlinkOptions.RECORD_KEY_FIELD, "uuid")
.option(FlinkOptions.TABLE_TYPE, tableType.name())
.end();
tableEnv.executeSql(hoodieTableDDL);

System.out.println(hoodieTableDDL);

execInsertSql(tableEnv, "INSERT INTO t1 values (1, 1)");
List<Row> result1 = CollectionUtil.iterableToList(
() -> tableEnv.sqlQuery("select * from t1").execute().collect());
assertRowsEquals(result1, "[+I[1, 1]]");

execInsertSql(tableEnv, "INSERT INTO t1 values (1, 100)");
List<Row> result2 = CollectionUtil.iterableToList(
() -> tableEnv.sqlQuery("select * from t1").execute().collect());
assertRowsEquals(result2, "[+I[1, 100]]");

execInsertSql(tableEnv, "INSERT INTO t1 values (1, 50)");
List<Row> result3 = CollectionUtil.iterableToList(
() -> tableEnv.sqlQuery("select * from t1").execute().collect());
assertRowsEquals(result3, "[+I[1, 100]]");

execInsertSql(tableEnv, "INSERT INTO t1 values (1, 2)");
List<Row> result4 = CollectionUtil.iterableToList(
() -> tableEnv.sqlQuery("select * from t1").execute().collect());
assertRowsEquals(result4, "[+I[1, 100]]");

execInsertSql(tableEnv, "INSERT INTO t1 values (1, 80)");
List<Row> result5 = CollectionUtil.iterableToList(
() -> tableEnv.sqlQuery("select * from t1").execute().collect());
assertRowsEquals(result5, "[+I[1, 100]]");

execInsertSql(tableEnv, "INSERT INTO t1 values (1, 180)");
List<Row> result6 = CollectionUtil.iterableToList(
() -> tableEnv.sqlQuery("select * from t1").execute().collect());
assertRowsEquals(result6, "[+I[1, 180]]");

@Test
void testBuiltinFunctionWithHMSCatalog() {
Expand Down Expand Up @@ -1393,6 +1443,7 @@ void testWriteReadWithComputedColumns() {
List<Row> result2 = CollectionUtil.iterableToList(
() -> tableEnv.sqlQuery("select f3 from t1").execute().collect());
assertRowsEquals(result2, "[+I[3]]");

}

// -------------------------------------------------------------------------
Expand Down