lokeshj1703 commented on code in PR #11816:
URL: https://github.com/apache/hudi/pull/11816#discussion_r1749809476


##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/catalyst/catalog/HoodieCatalogTable.scala:
##########
@@ -212,7 +211,9 @@ class HoodieCatalogTable(val spark: SparkSession, var 
table: CatalogTable) exten
     } else {
       val (recordName, namespace) = 
AvroConversionUtils.getAvroRecordNameAndNamespace(table.identifier.table)
       val schema = SchemaConverters.toAvroType(dataSchema, nullable = false, 
recordName, namespace)
-      val partitionColumns = if (table.partitionColumnNames.isEmpty) {
+      val partitionColumns = if 
(tableConfigs.contains(KeyGeneratorOptions.PARTITIONPATH_FIELD_NAME.key())) {

Review Comment:
   This is while creation of hudi table. So I have used the config used for 
setting partition fields. 
   I dont think we suggest using HoodieTableConfig.PARTITION_FIELDS while 
creation of new table?



##########
hudi-client/hudi-client-common/src/test/java/org/apache/hudi/keygen/TestKeyGenUtils.java:
##########
@@ -45,12 +46,68 @@ public void testInferKeyGeneratorType() {
     assertEquals(
         KeyGeneratorType.COMPLEX,
         KeyGenUtils.inferKeyGeneratorType(Option.of("col1,col2"), 
"partition1,partition2"));
+
+    assertEquals(
+        KeyGeneratorType.CUSTOM,
+        KeyGenUtils.inferKeyGeneratorType(Option.of("col1"), 
"partition1:simple,partition2:timestamp"));
+    assertEquals(
+        KeyGeneratorType.CUSTOM,
+        KeyGenUtils.inferKeyGeneratorType(Option.of("col1,col2"), 
"partition1:simple"));
+    assertEquals(
+        KeyGeneratorType.CUSTOM,
+        KeyGenUtils.inferKeyGeneratorType(Option.of("col1,col2"), 
"partition1:simple,partition2:timestamp"));
+
     assertEquals(
         KeyGeneratorType.NON_PARTITION,
         KeyGenUtils.inferKeyGeneratorType(Option.of("col1,col2"), ""));
     assertEquals(
         KeyGeneratorType.NON_PARTITION,
         KeyGenUtils.inferKeyGeneratorType(Option.of("col1,col2"), null));
+
+    // Test key generator type with auto generation of record keys
+    assertEquals(
+        KeyGeneratorType.SIMPLE,
+        KeyGenUtils.inferKeyGeneratorType(Option.empty(), "partition1"));
+    assertEquals(
+        KeyGeneratorType.COMPLEX,
+        KeyGenUtils.inferKeyGeneratorType(Option.empty(), 
"partition1,partition2"));
+    assertEquals(
+        KeyGeneratorType.CUSTOM,
+        KeyGenUtils.inferKeyGeneratorType(Option.empty(), 
"partition1:simple"));
+    assertEquals(
+        KeyGeneratorType.CUSTOM,
+        KeyGenUtils.inferKeyGeneratorType(Option.empty(), 
"partition1:simple,partition2:timestamp"));
+    assertEquals(
+        KeyGeneratorType.NON_PARTITION,
+        KeyGenUtils.inferKeyGeneratorType(Option.empty(), ""));
+    assertEquals(
+        KeyGeneratorType.NON_PARTITION,
+        KeyGenUtils.inferKeyGeneratorType(Option.empty(), null));
+  }
+
+  @Test
+  public void testInferKeyGeneratorTypeFromPartitionFields() {
+    assertEquals(
+        KeyGeneratorType.SIMPLE,
+        KeyGenUtils.inferKeyGeneratorTypeFromPartitionFields("partition1"));
+    assertEquals(
+        KeyGeneratorType.COMPLEX,
+        
KeyGenUtils.inferKeyGeneratorTypeFromPartitionFields("partition1,partition1"));
+    assertEquals(
+        KeyGeneratorType.CUSTOM,
+        
KeyGenUtils.inferKeyGeneratorTypeFromPartitionFields("partition1:simple"));
+    assertEquals(
+        KeyGeneratorType.CUSTOM,
+        
KeyGenUtils.inferKeyGeneratorTypeFromPartitionFields("partition1:timestamp"));
+    assertEquals(
+        KeyGeneratorType.CUSTOM,
+        
KeyGenUtils.inferKeyGeneratorTypeFromPartitionFields("partition1:simple,partition1:timestamp"));

Review Comment:
   Addressed



-- 
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]

Reply via email to