codope commented on code in PR #11638:
URL: https://github.com/apache/hudi/pull/11638#discussion_r1689132587


##########
hudi-common/src/main/java/org/apache/hudi/common/util/TableConfigUtils.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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: rename to HoodieTableConfigUtils



##########
hudi-common/src/main/java/org/apache/hudi/common/util/TableConfigUtils.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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 also
+   * include the partition type with the field.
+   */
+  public static Option<String> getPartitionFieldPropWithType(HoodieConfig 
config) {
+    return 
Option.ofNullable(config.getString(HoodieTableConfig.PARTITION_FIELDS));
+  }
+
+  /**
+   * 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]
+              : p)
+          .collect(Collectors.toList()).toArray(new String[] {}));

Review Comment:
   let's extract this parsing logic to a separate util method that can be 
reused.



##########
hudi-common/src/main/java/org/apache/hudi/common/util/TableConfigUtils.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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 also
+   * include the partition type with the field.
+   */
+  public static Option<String> getPartitionFieldPropWithType(HoodieConfig 
config) {
+    return 
Option.ofNullable(config.getString(HoodieTableConfig.PARTITION_FIELDS));
+  }
+
+  /**
+   * 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]
+              : p)
+          .collect(Collectors.toList()).toArray(new String[] {}));
+    }
+    return Option.empty();
+  }
+
+  /**
+   * This function returns the hoodie.table.version from hoodie.properties 
file.
+   */
+  public static HoodieTableVersion getTableVersion(HoodieConfig config) {
+    return HoodieConfig.contains(HoodieTableConfig.VERSION, config)
+        ? 
HoodieTableVersion.versionFromCode(config.getInt(HoodieTableConfig.VERSION))
+        : HoodieTableConfig.VERSION.defaultValue();

Review Comment:
   something to consider: should we change the default VERSION from ZERO to 
current version?



##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/SixToSevenUpgradeHandler.java:
##########
@@ -37,6 +40,12 @@ public class SixToSevenUpgradeHandler implements 
UpgradeHandler {
   public Map<ConfigProperty, String> upgrade(HoodieWriteConfig config, 
HoodieEngineContext context,
                                              String instantTime,
                                              SupportsUpgradeDowngrade 
upgradeDowngradeHelper) {
+    HoodieTableConfig tableConfig = upgradeDowngradeHelper.getTable(config, 
context).getMetaClient().getTableConfig();

Review Comment:
   Don't we need this for 7->8 upgrade/downgrade handlers too?



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