CTTY commented on code in PR #11601:
URL: https://github.com/apache/hudi/pull/11601#discussion_r1674723507


##########
hudi-common/src/main/java/org/apache/hudi/common/util/TableConfigUtils.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hudi.common.util;
+
+import org.apache.hudi.common.config.HoodieConfig;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.common.table.HoodieTableVersion;
+import org.apache.hudi.keygen.BaseKeyGenerator;
+
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+public class TableConfigUtils {

Review Comment:
   nit: We can add this logic to `HoodieTableConfig` so we don't need to add a 
new util



##########
hudi-common/src/main/java/org/apache/hudi/common/util/TableConfigUtils.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hudi.common.util;
+
+import org.apache.hudi.common.config.HoodieConfig;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.common.table.HoodieTableVersion;
+import org.apache.hudi.keygen.BaseKeyGenerator;
+
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+public class TableConfigUtils {
+
+  /**
+   * This function returns the partition fields joined by 
BaseKeyGenerator.FIELD_SEPARATOR. It will
+   * strip the partition key generator related info from the fields.
+   */
+  public static Option<String> getPartitionFieldProp(HoodieConfig config) {
+    if (getTableVersion(config).greaterThan(HoodieTableVersion.SIX)) {

Review Comment:
   I assume simple partition config like `par1,par2` would still work. Then why 
do we need to check table version here



##########
hudi-common/src/main/java/org/apache/hudi/common/util/TableConfigUtils.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hudi.common.util;
+
+import org.apache.hudi.common.config.HoodieConfig;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.common.table.HoodieTableVersion;
+import org.apache.hudi.keygen.BaseKeyGenerator;
+
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+public class TableConfigUtils {
+
+  /**
+   * This function returns the partition fields joined by 
BaseKeyGenerator.FIELD_SEPARATOR. It will
+   * strip the partition key generator related info from the fields.
+   */
+  public static Option<String> getPartitionFieldProp(HoodieConfig config) {
+    if (getTableVersion(config).greaterThan(HoodieTableVersion.SIX)) {
+      // After table version six, the table config 
org.apache.hudi.common.table.HoodieTableConfig.PARTITION_FIELDS
+      // stores the corresponding partition type as well. This partition type 
is useful for CustomKeyGenerator
+      // and CustomAvroKeyGenerator.
+      return getPartitionFields(config).map(fields -> 
String.join(BaseKeyGenerator.FIELD_SEPARATOR, fields));
+    } else {
+      return 
Option.ofNullable(config.getString(HoodieTableConfig.PARTITION_FIELDS));
+    }
+  }
+
+  /**
+   * This function returns the partition fields only. This method strips the 
key generator related
+   * partition key types from the configured fields.
+   */
+  public static Option<String[]> getPartitionFields(HoodieConfig config) {
+    if (HoodieConfig.contains(HoodieTableConfig.PARTITION_FIELDS, config)) {
+      return 
Option.of(Arrays.stream(config.getString(HoodieTableConfig.PARTITION_FIELDS).split(","))
+          .filter(p -> !p.isEmpty())
+          .map(p -> getTableVersion(config).greaterThan(HoodieTableVersion.SIX)
+              ? p.split(BaseKeyGenerator.CUSTOM_KEY_GENERATOR_SPLIT_REGEX)[0]

Review Comment:
   Same here, I feel like 
   `p -> p.split(BaseKeyGenerator.CUSTOM_KEY_GENERATOR_SPLIT_REGEX)[0]` would 
just work for all versions of Hudi table
   
   Am I overlooking anything?



##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/keygen/CustomKeyGenerator.java:
##########
@@ -83,7 +83,7 @@ private static List<BuiltinKeyGenerator> 
getPartitionKeyGenerators(List<String>
       return Collections.emptyList();
     } else {
       return partitionPathFields.stream().map(field -> {
-        String[] fieldWithType = 
field.split(CustomAvroKeyGenerator.SPLIT_REGEX);
+        String[] fieldWithType = 
field.split(BaseKeyGenerator.CUSTOM_KEY_GENERATOR_SPLIT_REGEX);

Review Comment:
   nit: just `CUSTOM_KEY_GENERATOR_SPLIT_REGEX` should suffice



-- 
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: commits-unsubscr...@hudi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to