This is an automated email from the ASF dual-hosted git repository. gaojun2048 pushed a commit to branch apache_240124_default_tablename in repository https://gitbox.apache.org/repos/asf/seatunnel.git
commit 80d1803aa1aaf35a44928e1e659d18c24965f130 Author: Eric <gaojun2...@gmail.com> AuthorDate: Wed Jan 24 10:32:25 2024 +0800 Use default tablepath when can not get the tablepath from source config --- .../api/table/catalog/CatalogTableUtil.java | 2 +- .../seatunnel/api/table/catalog/TablePath.java | 2 +- .../api/table/catalog/CatalogTableUtilTest.java | 12 ++++++ .../src/test/resources/conf/default_tablepath.conf | 45 ++++++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/CatalogTableUtil.java b/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/CatalogTableUtil.java index 6b8d19ea71..6f2b6adeb2 100644 --- a/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/CatalogTableUtil.java +++ b/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/CatalogTableUtil.java @@ -215,7 +215,7 @@ public class CatalogTableUtil implements Serializable { } else { Optional<String> resultTableNameOptional = readonlyConfig.getOptional(CommonOptions.RESULT_TABLE_NAME); - tablePath = resultTableNameOptional.map(TablePath::of).orElse(TablePath.EMPTY); + tablePath = resultTableNameOptional.map(TablePath::of).orElse(TablePath.DEFAULT); } return CatalogTable.of( diff --git a/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/TablePath.java b/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/TablePath.java index 60f4b691bd..1257262187 100644 --- a/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/TablePath.java +++ b/seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/TablePath.java @@ -34,7 +34,7 @@ public final class TablePath implements Serializable { private final String schemaName; private final String tableName; - public static final TablePath EMPTY = TablePath.of(null, null, null); + public static final TablePath DEFAULT = TablePath.of("default", "default", "default"); public static TablePath of(String fullName) { return of(fullName, false); diff --git a/seatunnel-api/src/test/java/org/apache/seatunnel/api/table/catalog/CatalogTableUtilTest.java b/seatunnel-api/src/test/java/org/apache/seatunnel/api/table/catalog/CatalogTableUtilTest.java index 9b579fbd90..a1ddbc8325 100644 --- a/seatunnel-api/src/test/java/org/apache/seatunnel/api/table/catalog/CatalogTableUtilTest.java +++ b/seatunnel-api/src/test/java/org/apache/seatunnel/api/table/catalog/CatalogTableUtilTest.java @@ -138,6 +138,18 @@ public class CatalogTableUtilTest { Thread.currentThread().getContextClassLoader())); } + @Test + public void testDefaultTablePath() throws FileNotFoundException, URISyntaxException { + String path = getTestConfigFile("/conf/default_tablepath.conf"); + Config config = ConfigFactory.parseFile(new File(path)); + Config source = config.getConfigList("source").get(0); + ReadonlyConfig sourceReadonlyConfig = ReadonlyConfig.fromConfig(source); + CatalogTable catalogTable = CatalogTableUtil.buildWithConfig(sourceReadonlyConfig); + Assertions.assertEquals("default", catalogTable.getTablePath().getDatabaseName()); + Assertions.assertEquals("default", catalogTable.getTablePath().getSchemaName()); + Assertions.assertEquals("default", catalogTable.getTablePath().getTableName()); + } + @Test public void testGenericRowSchemaTest() throws FileNotFoundException, URISyntaxException { String path = getTestConfigFile("/conf/generic_row.schema.conf"); diff --git a/seatunnel-api/src/test/resources/conf/default_tablepath.conf b/seatunnel-api/src/test/resources/conf/default_tablepath.conf new file mode 100644 index 0000000000..21cd9d5fd8 --- /dev/null +++ b/seatunnel-api/src/test/resources/conf/default_tablepath.conf @@ -0,0 +1,45 @@ +# +# 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. +# + +env { + job.mode = "BATCH" +} + +source { + MongoDB-CDC { + hosts = "mongo0:27017" + database = ["inventory"] + collection = ["inventory.products"] + username = superuser + password = superpw + schema = { + fields { + "_id": string, + "name": string, + "description": string, + "weight": string + } + } + } +} + +transform { +} + +sink { + Console{} +} \ No newline at end of file