XuQianJin-Stars commented on code in PR #3888:
URL: https://github.com/apache/hudi/pull/3888#discussion_r978207406


##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/keygen/EmptyKeyGenerator.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.keygen;
+
+import org.apache.avro.generic.GenericRecord;
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.keygen.constant.KeyGeneratorOptions;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.catalyst.InternalRow;
+import org.apache.spark.sql.types.StructType;
+import org.apache.spark.unsafe.types.UTF8String;
+
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+/**
+ * Key generator for Hudi tables without record key.
+ */
+public class EmptyKeyGenerator extends BuiltinKeyGenerator {
+
+  public static final String EMPTY_RECORD_KEY = 
EmptyAvroKeyGenerator.EMPTY_RECORD_KEY;
+
+  private final EmptyAvroKeyGenerator emptyAvroKeyGenerator;
+
+  public EmptyKeyGenerator(TypedProperties config) {
+    super(config);
+    this.emptyAvroKeyGenerator = new EmptyAvroKeyGenerator(config);
+    this.recordKeyFields = emptyAvroKeyGenerator.getRecordKeyFieldNames();
+    this.partitionPathFields = 
Arrays.stream(config.getString(KeyGeneratorOptions.PARTITIONPATH_FIELD_NAME.key())
+        .split(",")).map(String::trim).filter(s -> 
!s.isEmpty()).collect(Collectors.toList());
+  }
+
+  @Override
+  public String getRecordKey(GenericRecord record) {
+    return EMPTY_RECORD_KEY;
+  }
+
+  @Override
+  public String getRecordKey(Row row) {
+    return EMPTY_RECORD_KEY;
+  }
+
+  @Override
+  public UTF8String getRecordKey(InternalRow internalRow, StructType schema) {
+    return combineCompositeRecordKeyUnsafe(EMPTY_RECORD_KEY);
+  }
+
+  @Override
+  public String getPartitionPath(GenericRecord record) {
+    return emptyAvroKeyGenerator.getPartitionPath(record);
+  }
+
+  @Override
+  public String getPartitionPath(Row row) {
+    tryInitRowAccessor(row.schema());
+    return combinePartitionPath(rowAccessor.getRecordPartitionPathValues(row));
+  }
+
+  @Override
+  public UTF8String getPartitionPath(InternalRow row, StructType schema) {

Review Comment:
   Support for time field partitioning is also required here.



##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/keygen/EmptyAvroKeyGenerator.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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.keygen;
+
+import org.apache.avro.generic.GenericRecord;
+
+import org.apache.hudi.common.model.HoodieKey;
+
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.keygen.constant.KeyGeneratorOptions;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+/**
+ * Avro key generator for empty record key Hudi tables.
+ */
+public class EmptyAvroKeyGenerator extends BaseKeyGenerator {
+
+  private static final Logger LOG = 
LogManager.getLogger(EmptyAvroKeyGenerator.class);
+  public static final String EMPTY_RECORD_KEY = HoodieKey.EMPTY_RECORD_KEY;
+  private static final List<String> EMPTY_RECORD_KEY_FIELD_LIST = 
Collections.emptyList();
+
+  public EmptyAvroKeyGenerator(TypedProperties props) {
+    super(props);
+    if (config.containsKey(KeyGeneratorOptions.RECORDKEY_FIELD_NAME.key())) {
+      LOG.warn(KeyGeneratorOptions.RECORDKEY_FIELD_NAME.key() + " will be 
ignored while using "
+          + this.getClass().getSimpleName());
+    }
+    this.recordKeyFields = EMPTY_RECORD_KEY_FIELD_LIST;
+    this.partitionPathFields = 
Arrays.stream(props.getString(KeyGeneratorOptions.PARTITIONPATH_FIELD_NAME.key())
+        .split(",")).map(String::trim).filter(s -> 
!s.isEmpty()).collect(Collectors.toList());
+  }
+
+  @Override
+  public String getRecordKey(GenericRecord record) {
+    return EMPTY_RECORD_KEY;
+  }
+
+  @Override
+  public String getPartitionPath(GenericRecord record) {
+    return KeyGenUtils.getRecordPartitionPath(record, 
getPartitionPathFields(), hiveStylePartitioning, encodePartitionPath, 
isConsistentLogicalTimestampEnabled());

Review Comment:
   Support for time field partitioning is also required here.



##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/table/HoodieTableFactory.java:
##########
@@ -188,6 +191,15 @@ private static void setupConfOptions(
     setupWriteOptions(conf);
     // infer avro schema from physical DDL schema
     inferAvroSchema(conf, 
schema.toPhysicalRowDataType().notNull().getLogicalType());
+    setupDefaultOptionsForNonIndex(conf);
+  }
+
+  private static void setupDefaultOptionsForNonIndex(Configuration conf) {

Review Comment:
   This method logic is merged with `setupHoodieKeyOptions`?



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