-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-4323] Make database table names optional in sync tool #6073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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. | ||
| */ | ||
|
|
@@ -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))) | ||
| .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)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @codope 2nd thought: |
||
| .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 | ||
|
|
@@ -148,6 +143,7 @@ public HoodieSyncConfig(Properties props) { | |
|
|
||
| public HoodieSyncConfig(Properties props, Configuration hadoopConf) { | ||
| super(props); | ||
| setDefaults(getClass().getName()); | ||
| this.hadoopConf = hadoopConf; | ||
| } | ||
|
|
||
|
|
@@ -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; | ||
|
|
||
| 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)); | ||
| } | ||
| } |
There was a problem hiding this comment.
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#getInferFuncgets called only inConfigProperty#setDefaultValue(ConfigProperty)so we should check how the default is being set at the call site for all such configs with infer function.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.