[HUDI-1814] Non partitioned table for Flink writer (#2859)
This commit is contained in:
@@ -239,9 +239,9 @@ public class FlinkOptions {
|
||||
public static final ConfigOption<String> PARTITION_PATH_FIELD = ConfigOptions
|
||||
.key(KeyGeneratorOptions.PARTITIONPATH_FIELD_OPT_KEY)
|
||||
.stringType()
|
||||
.defaultValue("partition-path")
|
||||
.defaultValue("")
|
||||
.withDescription("Partition path field. Value to be used at the `partitionPath` component of `HoodieKey`.\n"
|
||||
+ "Actual value obtained by invoking .toString()");
|
||||
+ "Actual value obtained by invoking .toString(), default ''");
|
||||
|
||||
public static final ConfigOption<Boolean> PARTITION_PATH_URL_ENCODE = ConfigOptions
|
||||
.key("write.partition.url_encode")
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.apache.hudi.table;
|
||||
|
||||
import org.apache.hudi.configuration.FlinkOptions;
|
||||
import org.apache.hudi.keygen.ComplexAvroKeyGenerator;
|
||||
import org.apache.hudi.keygen.NonpartitionedAvroKeyGenerator;
|
||||
import org.apache.hudi.util.AvroSchemaConverter;
|
||||
|
||||
import org.apache.flink.configuration.ConfigOption;
|
||||
@@ -129,13 +130,21 @@ public class HoodieTableFactory implements DynamicTableSourceFactory, DynamicTab
|
||||
String recordKey = String.join(",", pkColumns);
|
||||
conf.setString(FlinkOptions.RECORD_KEY_FIELD, recordKey);
|
||||
}
|
||||
List<String> partitions = table.getPartitionKeys();
|
||||
if (partitions.size() > 0) {
|
||||
List<String> partitionKeys = table.getPartitionKeys();
|
||||
if (partitionKeys.size() > 0) {
|
||||
// the PARTITIONED BY syntax always has higher priority than option FlinkOptions#PARTITION_PATH_FIELD
|
||||
conf.setString(FlinkOptions.PARTITION_PATH_FIELD, String.join(",", partitions));
|
||||
conf.setString(FlinkOptions.PARTITION_PATH_FIELD, String.join(",", partitionKeys));
|
||||
}
|
||||
// tweak the key gen class if possible
|
||||
boolean complexHoodieKey = pkColumns.size() > 1 || partitions.size() > 1;
|
||||
final String[] partitions = conf.getString(FlinkOptions.PARTITION_PATH_FIELD).split(",");
|
||||
if (partitions.length == 1 && partitions[0].equals("")) {
|
||||
conf.setString(FlinkOptions.KEYGEN_CLASS, NonpartitionedAvroKeyGenerator.class.getName());
|
||||
LOG.info("Table option [{}] is reset to {} because this is a non-partitioned table",
|
||||
FlinkOptions.KEYGEN_CLASS.key(), NonpartitionedAvroKeyGenerator.class.getName());
|
||||
return;
|
||||
}
|
||||
final String[] pks = conf.getString(FlinkOptions.RECORD_KEY_FIELD).split(",");
|
||||
boolean complexHoodieKey = pks.length > 1 || partitions.length > 1;
|
||||
if (complexHoodieKey && FlinkOptions.isDefaultValueDefined(conf, FlinkOptions.KEYGEN_CLASS)) {
|
||||
conf.setString(FlinkOptions.KEYGEN_CLASS, ComplexAvroKeyGenerator.class.getName());
|
||||
LOG.info("Table option [{}] is reset to {} because record key or partition path has two or more fields",
|
||||
|
||||
Reference in New Issue
Block a user