hudi-agent commented on code in PR #19845:
URL: https://github.com/apache/hudi/pull/19845#discussion_r3939316998
##########
hudi-spark-datasource/hudi-spark/src/test/java/org/apache/hudi/io/storage/row/TestHoodieRowCreateHandle.java:
##########
@@ -133,6 +136,44 @@ public void testRowCreateHandle(boolean
populateMetaFields) throws Exception {
}
}
+ @ParameterizedTest
+ @ValueSource(booleans = {true, false})
+ public void testAllExceptRecordKeyPreservesMetadata(boolean
preserveMetadata) throws Exception {
+ HoodieWriteConfig config =
SparkDatasetTestUtils.getConfigBuilder(basePath, timelineServicePort)
+ .withMetaFieldsMode(MetaFieldsMode.ALL_EXCEPT_RECORD_KEY).build();
+ Properties tableProps = new Properties();
+ tableProps.setProperty(HoodieTableConfig.META_FIELDS_MODE.key(),
MetaFieldsMode.ALL_EXCEPT_RECORD_KEY.name());
+ tableProps.setProperty(HoodieTableConfig.POPULATE_META_FIELDS.key(),
"false");
+ HoodieTableConfig.update(metaClient.getStorage(),
metaClient.getMetaPath(), tableProps);
+ metaClient = HoodieTableMetaClient.reload(metaClient);
+ HoodieTable table = HoodieSparkTable.create(config, context, metaClient);
+ String partitionPath = HoodieTestDataGenerator.DEFAULT_PARTITION_PATHS[0];
+ HoodieRowCreateHandle handle = new HoodieRowCreateHandle(table, config,
partitionPath,
+ UUID.randomUUID().toString(), "002", 0, 0, 0,
SparkDatasetTestUtils.STRUCT_TYPE.asNullable(), preserveMetadata);
+ Dataset<Row> input = SparkDatasetTestUtils.getRandomRows(sqlContext, 10,
partitionPath, false)
+ .withColumn(HoodieRecord.COMMIT_TIME_METADATA_FIELD,
functions.lit("001"))
+ .withColumn(HoodieRecord.COMMIT_SEQNO_METADATA_FIELD,
functions.concat(functions.lit("001_0_"),
functions.col(SparkDatasetTestUtils.RECORD_KEY_FIELD_NAME)));
+ WriteStatus status = writeAndGetWriteStatus(input, handle);
+ assertFalse(status.hasErrors());
+ List<Row> written = sqlContext.read().parquet(basePath + "/" +
status.getStat().getPath()).collectAsList();
+ Map<String, Row> original = input.collectAsList().stream()
+ .collect(Collectors.toMap(row -> row.getString(5), row -> row));
+ assertEquals(10, written.size());
Review Comment:
🤖 nit: could you use named field access
(`row.getAs(HoodieRecord.RECORD_KEY_METADATA_FIELD)`,
`row.getAs(HoodieRecord.PARTITION_PATH_METADATA_FIELD)`, etc.) instead of the
positional indices throughout this test? The numbers force a reader to mentally
cross-reference the schema to understand what's being asserted, and they'll
silently shift meaning if a column is ever added.
<sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag
quality.</i></sub>
--
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]