linliu-code commented on code in PR #14315:
URL: https://github.com/apache/hudi/pull/14315#discussion_r2557123873
##########
hudi-utilities/src/test/java/org/apache/hudi/utilities/deltastreamer/TestHoodieDeltaStreamer.java:
##########
@@ -652,6 +657,206 @@ public void testSchemaEvolution(String tableType, boolean
useUserProvidedSchema,
defaultSchemaProviderClassName = FilebasedSchemaProvider.class.getName();
}
+ @Test
+ public void testTimestampMillis() throws Exception {
+ String tableBasePath = basePath + "/testTimestampMillis";
+ defaultSchemaProviderClassName = FilebasedSchemaProvider.class.getName();
+ // Insert data produced with Schema A, pass Schema A
+ HoodieDeltaStreamer.Config cfg = TestHelpers.makeConfig(tableBasePath,
WriteOperationType.INSERT,
Collections.singletonList(TestIdentityTransformer.class.getName()),
+ PROPS_FILENAME_TEST_SOURCE, false, true, false, null,
HoodieTableType.MERGE_ON_READ.name());
+ cfg.payloadClassName = DefaultHoodieRecordPayload.class.getName();
+ cfg.configs.add("hoodie.streamer.schemaprovider.source.schema.file=" +
basePath + "/source-timestamp-millis.avsc");
+ cfg.configs.add("hoodie.streamer.schemaprovider.target.schema.file=" +
basePath + "/source-timestamp-millis.avsc");
+ cfg.configs.add(String.format("%s=%s",
HoodieCompactionConfig.PARQUET_SMALL_FILE_LIMIT.key(), "0"));
+ cfg.configs.add("hoodie.datasource.write.row.writer.enable=false");
+
+
+ new HoodieDeltaStreamer(cfg, jsc).sync();
+ assertRecordCount(1000, tableBasePath, sqlContext);
+ TestHelpers.assertCommitMetadata("00000", tableBasePath, 1);
+ TableSchemaResolver tableSchemaResolver = new TableSchemaResolver(
+ HoodieTestUtils.createMetaClient(storage, tableBasePath));
+ Schema tableSchema = tableSchemaResolver.getTableAvroSchema(false);
+ assertEquals("timestamp-millis",
tableSchema.getField("current_ts").schema().getLogicalType().getName());
+ assertEquals(1000,
sqlContext.read().options(hudiOpts).format("org.apache.hudi").load(tableBasePath).filter("current_ts
> '1980-01-01'").count());
+
+ cfg = TestHelpers.makeConfig(tableBasePath, WriteOperationType.UPSERT,
Collections.singletonList(TestIdentityTransformer.class.getName()),
+ PROPS_FILENAME_TEST_SOURCE, false, true, false, null,
HoodieTableType.MERGE_ON_READ.name());
+ cfg.payloadClassName = DefaultHoodieRecordPayload.class.getName();
+ cfg.configs.add("hoodie.streamer.schemaprovider.source.schema.file=" +
basePath + "/source-timestamp-millis.avsc");
+ cfg.configs.add("hoodie.streamer.schemaprovider.target.schema.file=" +
basePath + "/source-timestamp-millis.avsc");
+ cfg.configs.add(String.format("%s=%s",
HoodieCompactionConfig.PARQUET_SMALL_FILE_LIMIT.key(), "0"));
+ cfg.configs.add("hoodie.datasource.write.row.writer.enable=false");
+
+ new HoodieDeltaStreamer(cfg, jsc).sync();
+ assertRecordCount(1450, tableBasePath, sqlContext);
+ TestHelpers.assertCommitMetadata("00001", tableBasePath, 2);
+ tableSchemaResolver = new TableSchemaResolver(
+ HoodieTestUtils.createMetaClient(storage, tableBasePath));
+ tableSchema = tableSchemaResolver.getTableAvroSchema(false);
+ assertEquals("timestamp-millis",
tableSchema.getField("current_ts").schema().getLogicalType().getName());
+ sqlContext.clearCache();
+ assertEquals(1450,
sqlContext.read().options(hudiOpts).format("org.apache.hudi").load(tableBasePath).filter("current_ts
> '1980-01-01'").count());
+ assertEquals(1450,
sqlContext.read().options(hudiOpts).format("org.apache.hudi").load(tableBasePath).filter("current_ts
< '2080-01-01'").count());
+ assertEquals(0,
sqlContext.read().options(hudiOpts).format("org.apache.hudi").load(tableBasePath).filter("current_ts
< '1980-01-01'").count());
+ }
+
+ @Test
+ public void testLogicalTypes() throws Exception {
+ try {
+ String tableBasePath = basePath + "/testTimestampMillis";
+ defaultSchemaProviderClassName =
TestHoodieDeltaStreamerSchemaEvolutionBase.TestSchemaProvider.class.getName();
+
+ if (HoodieSparkUtils.isSpark3_3()) {
+
TestHoodieDeltaStreamerSchemaEvolutionBase.TestSchemaProvider.sourceSchema =
HoodieTestDataGenerator.AVRO_TRIP_LOGICAL_TYPES_SCHEMA_NO_LTS;
+
TestHoodieDeltaStreamerSchemaEvolutionBase.TestSchemaProvider.targetSchema =
HoodieTestDataGenerator.AVRO_TRIP_LOGICAL_TYPES_SCHEMA_NO_LTS;
+ AbstractBaseTestSource.schemaStr =
HoodieTestDataGenerator.TRIP_LOGICAL_TYPES_SCHEMA_NO_LTS;
+ AbstractBaseTestSource.avroSchema =
HoodieTestDataGenerator.AVRO_TRIP_LOGICAL_TYPES_SCHEMA_NO_LTS;
+ } else {
+
TestHoodieDeltaStreamerSchemaEvolutionBase.TestSchemaProvider.sourceSchema =
HoodieTestDataGenerator.AVRO_TRIP_LOGICAL_TYPES_SCHEMA;
+
TestHoodieDeltaStreamerSchemaEvolutionBase.TestSchemaProvider.targetSchema =
HoodieTestDataGenerator.AVRO_TRIP_LOGICAL_TYPES_SCHEMA;
+ AbstractBaseTestSource.schemaStr =
HoodieTestDataGenerator.TRIP_LOGICAL_TYPES_SCHEMA;
+ AbstractBaseTestSource.avroSchema =
HoodieTestDataGenerator.AVRO_TRIP_LOGICAL_TYPES_SCHEMA;
+ }
+
+ // Insert data produced with Schema A, pass Schema A
+ HoodieDeltaStreamer.Config cfg = TestHelpers.makeConfig(tableBasePath,
WriteOperationType.INSERT,
Collections.singletonList(TestIdentityTransformer.class.getName()),
+ PROPS_FILENAME_TEST_SOURCE, false, true, false, null,
HoodieTableType.MERGE_ON_READ.name());
+ cfg.payloadClassName = DefaultHoodieRecordPayload.class.getName();
+ cfg.configs.add(String.format("%s=%s",
HoodieCompactionConfig.PARQUET_SMALL_FILE_LIMIT.key(), "0"));
+ cfg.configs.add("hoodie.datasource.write.row.writer.enable=false");
+
+ new HoodieDeltaStreamer(cfg, jsc).sync();
+ assertRecordCount(1000, tableBasePath, sqlContext);
+ TestHelpers.assertCommitMetadata("00000", tableBasePath, 1);
+ TableSchemaResolver tableSchemaResolver = new TableSchemaResolver(
+ HoodieTestUtils.createMetaClient(storage, tableBasePath));
+ Schema tableSchema = tableSchemaResolver.getTableAvroSchema(false);
+ Map<String, String> hudiOpts = new HashMap<>();
+ hudiOpts.put("hoodie.datasource.write.recordkey.field", "id");
+ logicalAssertions(tableSchema, tableBasePath, hudiOpts,
HoodieTableVersion.current().versionCode());
+
+
+ cfg = TestHelpers.makeConfig(tableBasePath, WriteOperationType.UPSERT,
Collections.singletonList(TestIdentityTransformer.class.getName()),
+ PROPS_FILENAME_TEST_SOURCE, false, true, false, null,
HoodieTableType.MERGE_ON_READ.name());
+ cfg.payloadClassName = DefaultHoodieRecordPayload.class.getName();
+ cfg.configs.add(String.format("%s=%s",
HoodieCompactionConfig.PARQUET_SMALL_FILE_LIMIT.key(), "0"));
+ cfg.configs.add("hoodie.datasource.write.row.writer.enable=false");
+
+ new HoodieDeltaStreamer(cfg, jsc).sync();
+ assertRecordCount(1450, tableBasePath, sqlContext);
+ TestHelpers.assertCommitMetadata("00001", tableBasePath, 2);
+ tableSchemaResolver = new TableSchemaResolver(
+ HoodieTestUtils.createMetaClient(storage, tableBasePath));
+ tableSchema = tableSchemaResolver.getTableAvroSchema(false);
+ logicalAssertions(tableSchema, tableBasePath, hudiOpts,
HoodieTableVersion.current().versionCode());
+ } finally {
+ defaultSchemaProviderClassName = FilebasedSchemaProvider.class.getName();
+ AbstractBaseTestSource.schemaStr =
HoodieTestDataGenerator.TRIP_EXAMPLE_SCHEMA;
+ AbstractBaseTestSource.avroSchema = HoodieTestDataGenerator.AVRO_SCHEMA;
+ }
+ }
+
+ private void logicalAssertions(Schema tableSchema, String tableBasePath,
Map<String, String> hudiOpts, int tableVersion) {
+ if (tableVersion > 8) {
Review Comment:
We could remove these >8 statements since they will not be executed at all.
--
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]