Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,6 @@ object DataSourceWriteOptions {
@Deprecated
val HIVE_DATABASE: ConfigProperty[String] = HoodieSyncConfig.META_SYNC_DATABASE_NAME
@Deprecated
val hiveTableOptKeyInferFunc: JavaFunction[HoodieConfig, Option[String]] = HoodieSyncConfig.TABLE_NAME_INFERENCE_FUNCTION
@Deprecated
val HIVE_TABLE: ConfigProperty[String] = HoodieSyncConfig.META_SYNC_TABLE_NAME
@Deprecated
val HIVE_BASE_FILE_FORMAT: ConfigProperty[String] = HoodieSyncConfig.META_SYNC_BASE_FILE_FORMAT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.hudi.common.config.HoodieMetadataConfig;
import org.apache.hudi.common.config.TypedProperties;
import org.apache.hudi.common.fs.FSUtils;
import org.apache.hudi.common.table.HoodieTableConfig;
import org.apache.hudi.common.util.Option;
import org.apache.hudi.common.util.StringUtils;
import org.apache.hudi.keygen.constant.KeyGeneratorOptions;
Expand All @@ -37,6 +36,10 @@
import java.util.Properties;
import java.util.function.Function;

import static org.apache.hudi.common.table.HoodieTableConfig.DATABASE_NAME;
import static org.apache.hudi.common.table.HoodieTableConfig.HOODIE_TABLE_NAME_KEY;
import static org.apache.hudi.common.table.HoodieTableConfig.HOODIE_WRITE_TABLE_NAME_KEY;

/**
* Configs needed to sync data into external meta stores, catalogs, etc.
*/
Expand All @@ -56,22 +59,14 @@ public class HoodieSyncConfig extends HoodieConfig {
public static final ConfigProperty<String> META_SYNC_DATABASE_NAME = ConfigProperty
.key("hoodie.datasource.hive_sync.database")
.defaultValue("default")
.withInferFunction(cfg -> Option.ofNullable(cfg.getString(DATABASE_NAME)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should note that ConfigProperty#getInferFunc gets called only in ConfigProperty#setDefaultValue(ConfigProperty) so we should check how the default is being set at the call site for all such configs with infer function.

Copy link
Member Author

@xushiyan xushiyan Jul 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. actually these infer functions were never effective as ConfigProperty#setDefaultValue(ConfigProperty) wasn't invoked at all.

.withDocumentation("The name of the destination database that we should sync the hudi table to.");

// If the table name for the metastore destination is not provided, pick it up from write or table configs.
public static final Function<HoodieConfig, Option<String>> TABLE_NAME_INFERENCE_FUNCTION = cfg -> {
if (cfg.contains(HoodieTableConfig.HOODIE_WRITE_TABLE_NAME_KEY)) {
return Option.of(cfg.getString(HoodieTableConfig.HOODIE_WRITE_TABLE_NAME_KEY));
} else if (cfg.contains(HoodieTableConfig.HOODIE_TABLE_NAME_KEY)) {
return Option.of(cfg.getString(HoodieTableConfig.HOODIE_TABLE_NAME_KEY));
} else {
return Option.empty();
}
};
public static final ConfigProperty<String> META_SYNC_TABLE_NAME = ConfigProperty
.key("hoodie.datasource.hive_sync.table")
.defaultValue("unknown")
.withInferFunction(TABLE_NAME_INFERENCE_FUNCTION)
.withInferFunction(cfg -> Option.ofNullable(cfg.getString(HOODIE_WRITE_TABLE_NAME_KEY))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove setting defaultValue if the config is being inferred from a mandatory config so that the app can fail fast. What do you think?

Copy link
Member Author

@xushiyan xushiyan Jul 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codope 2nd thought: ConfigProperty#setDefaultValue(ConfigProperty) the current implementation mandates that to use infer function there should be a default to fallback, as infer function may return empty option.

.or(() -> Option.ofNullable(cfg.getString(HOODIE_TABLE_NAME_KEY))))
.withDocumentation("The name of the destination table that we should sync the hudi table to.");

public static final ConfigProperty<String> META_SYNC_BASE_FILE_FORMAT = ConfigProperty
Expand Down Expand Up @@ -148,6 +143,7 @@ public HoodieSyncConfig(Properties props) {

public HoodieSyncConfig(Properties props, Configuration hadoopConf) {
super(props);
setDefaults(getClass().getName());
this.hadoopConf = hadoopConf;
}

Expand All @@ -173,9 +169,9 @@ public String toString() {
}

public static class HoodieSyncConfigParams {
@Parameter(names = {"--database"}, description = "name of the target database in meta store", required = true)
@Parameter(names = {"--database"}, description = "name of the target database in meta store")
public String databaseName;
@Parameter(names = {"--table"}, description = "name of the target table in meta store", required = true)
@Parameter(names = {"--table"}, description = "name of the target table in meta store")
public String tableName;
@Parameter(names = {"--base-path"}, description = "Base path of the hoodie table to sync", required = true)
public String basePath;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.sync.common;

import org.apache.hudi.common.table.HoodieTableConfig;

import org.apache.hadoop.conf.Configuration;
import org.junit.jupiter.api.Test;

import java.util.Properties;

import static org.apache.hudi.sync.common.HoodieSyncConfig.META_SYNC_DATABASE_NAME;
import static org.apache.hudi.sync.common.HoodieSyncConfig.META_SYNC_TABLE_NAME;
import static org.junit.jupiter.api.Assertions.assertEquals;

class TestHoodieSyncConfig {

@Test
void testInferDatabaseAndTableNames() {
Properties props1 = new Properties();
props1.setProperty(HoodieTableConfig.DATABASE_NAME.key(), "db1");
props1.setProperty(HoodieTableConfig.HOODIE_TABLE_NAME_KEY, "tbl1");
HoodieSyncConfig config1 = new HoodieSyncConfig(props1, new Configuration());
assertEquals("db1", config1.getString(META_SYNC_DATABASE_NAME));
assertEquals("tbl1", config1.getString(META_SYNC_TABLE_NAME));

Properties props2 = new Properties();
props2.setProperty(HoodieTableConfig.DATABASE_NAME.key(), "db2");
props2.setProperty(HoodieTableConfig.HOODIE_WRITE_TABLE_NAME_KEY, "tbl2");
HoodieSyncConfig config2 = new HoodieSyncConfig(props2, new Configuration());
assertEquals("db2", config2.getString(META_SYNC_DATABASE_NAME));
assertEquals("tbl2", config2.getString(META_SYNC_TABLE_NAME));

HoodieSyncConfig config3 = new HoodieSyncConfig(new Properties(), new Configuration());
assertEquals("default", config3.getString(META_SYNC_DATABASE_NAME));
assertEquals("unknown", config3.getString(META_SYNC_TABLE_NAME));
}
}