Hisoka-X commented on code in PR #6679:
URL: https://github.com/apache/seatunnel/pull/6679#discussion_r1562503893


##########
seatunnel-connectors-v2/connector-doris/src/test/java/org/apache/seatunnel/connectors/doris/catalog/DorisCreateTableTest.java:
##########
@@ -111,25 +116,37 @@ public void test() {
                                 Collections.emptyMap(),
                                 Collections.emptyList(),
                                 ""));
+
+        String createTemplate = 
DorisOptions.SAVE_MODE_CREATE_TEMPLATE.defaultValue();
+        CatalogTable catalogTable =
+                CatalogTable.of(
+                        TableIdentifier.of("test", "test1", "test2"),
+                        TableSchema.builder()
+                                .primaryKey(
+                                        PrimaryKey.of(StringUtils.EMPTY, 
Collections.emptyList()))
+                                .constraintKey(Collections.emptyList())
+                                .columns(columns)
+                                .build(),
+                        Collections.emptyMap(),
+                        Collections.emptyList(),
+                        "");
+        TablePath tablePath = TablePath.of("test1.test2");
+        RuntimeException runtimeException =
+                Assertions.assertThrows(
+                        RuntimeException.class,
+                        () ->
+                                DorisCatalogUtil.getCreateTableStatement(
+                                        createTemplate, tablePath, 
catalogTable));
+        String primaryKeyHolder = 
SaveModePlaceHolderEnum.ROWTYPE_PRIMARY_KEY.getPlaceHolder();
         Assertions.assertEquals(
-                result,
-                "CREATE TABLE IF NOT EXISTS `test1`.`test2` (                  
                                                                                
                                                 \n"
-                        + "`id` BIGINT(1) NULL ,`age` INT(1) NULL   ,       \n"
-                        + "`name` STRING NULL ,`score` INT(1) NULL  , \n"
-                        + "`create_time` DATETIME NOT NULL ,  \n"
-                        + "`gender` TINYINT NULL   \n"
-                        + ") ENGINE=OLAP  \n"
-                        + "PRIMARY KEY(`id`,`age`,`create_time`)  \n"
-                        + "PARTITION BY RANGE (`create_time`)(  \n"
-                        + "   PARTITION p20230329 VALUES LESS THAN 
(\"2023-03-29\")                                                                
                                                                                
           \n"
-                        + ")                                      \n"
-                        + "DISTRIBUTED BY HASH (`id`,`age`)  \n"
-                        + "PROPERTIES (\n"
-                        + "\"replication_allocation\" = 
\"tag.location.default: 1\",\n"
-                        + "\"in_memory\" = \"false\",\n"
-                        + "\"storage_format\" = \"V2\",\n"
-                        + "\"disable_auto_compaction\" = \"false\"\n"
-                        + ")");

Review Comment:
   Where is this part?



##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/SaveModePlaceHolderEnum.java:
##########
@@ -0,0 +1,66 @@
+/*

Review Comment:
   Please this file and `SqlTemplate` into `connector-common` module. I think 
that is a better place.



##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/SaveModePlaceHolderEnum.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.seatunnel.api.sink;
+
+import java.util.Arrays;
+import java.util.Optional;
+
+public enum SaveModePlaceHolderEnum {
+    ROWTYPE_PRIMARY_KEY("rowtype_primary_key", "primaryKeys"),
+    ROWTYPE_UNIQUE_KEY("rowtype_unique_key", "uniqueKeys"),
+    ROWTYPE_FIELDS("rowtype_fields", "fields"),
+    TABLE_NAME("table_name", "tableName"),
+    DATABASE("database", "database");
+
+    private String keyValue;
+    private String actualValue;

Review Comment:
   ```suggestion
       private String display;
   ```



##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/table/sql/template/SqlTemplate.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.seatunnel.api.table.sql.template;
+
+import org.apache.seatunnel.api.sink.SaveModePlaceHolderEnum;
+
+import org.apache.commons.lang3.StringUtils;
+
+public class SqlTemplate {
+
+    public static final String EXCEPTION_TEMPLATE =
+            "The table of %s has no %s, but the template \n %s \n which has 
the place holder named %s. Please use the option named %s to specify sql 
template";
+
+    public static void canHandledByTemplateWithPlaceholder(
+            String createTemplate,
+            String placeholder,
+            String actualPlaceHolderValue,
+            String tableName,
+            String optionsKey) {
+        if (createTemplate.contains(placeholder) && 
StringUtils.isBlank(actualPlaceHolderValue)) {
+            throw new RuntimeException(

Review Comment:
   Please add common error in 
https://github.com/apache/seatunnel/blob/790150a54b559148657a599fa16bf00539a5ab74/seatunnel-common/src/main/java/org/apache/seatunnel/common/exception/CommonError.java.
 Not throw RuntimeException.



##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/SaveModePlaceHolderEnum.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.seatunnel.api.sink;
+
+import java.util.Arrays;
+import java.util.Optional;
+
+public enum SaveModePlaceHolderEnum {
+    ROWTYPE_PRIMARY_KEY("rowtype_primary_key", "primaryKeys"),
+    ROWTYPE_UNIQUE_KEY("rowtype_unique_key", "uniqueKeys"),
+    ROWTYPE_FIELDS("rowtype_fields", "fields"),
+    TABLE_NAME("table_name", "tableName"),
+    DATABASE("database", "database");
+
+    private String keyValue;
+    private String actualValue;
+
+    private static final String REPLACE_PLACE_HOLDER = "\\$\\{%s\\}";
+    private static final String PLACE_HOLDER = "${%s}";
+
+    SaveModePlaceHolderEnum(String keyValue, String actualValue) {
+        this.keyValue = keyValue;
+        this.actualValue = actualValue;
+    }
+
+    public static String getActualValueByPlaceHolder(String placeholder) {

Review Comment:
   ```suggestion
       public static String getDisplay(String placeholder) {
   ```



##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/SaveModePlaceHolderEnum.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.seatunnel.api.sink;
+
+import java.util.Arrays;
+import java.util.Optional;
+
+public enum SaveModePlaceHolderEnum {

Review Comment:
   ```suggestion
   public enum SaveModePlaceholder {
   ```



##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/SaveModePlaceHolderEnum.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.seatunnel.api.sink;
+
+import java.util.Arrays;
+import java.util.Optional;
+
+public enum SaveModePlaceHolderEnum {
+    ROWTYPE_PRIMARY_KEY("rowtype_primary_key", "primaryKeys"),
+    ROWTYPE_UNIQUE_KEY("rowtype_unique_key", "uniqueKeys"),
+    ROWTYPE_FIELDS("rowtype_fields", "fields"),
+    TABLE_NAME("table_name", "tableName"),

Review Comment:
   ```suggestion
       ROWTYPE_PRIMARY_KEY("rowtype_primary_key", "primary keys"),
       ROWTYPE_UNIQUE_KEY("rowtype_unique_key", "unique keys"),
       ROWTYPE_FIELDS("rowtype_fields", "fields"),
       TABLE_NAME("table_name", "table name"),
   ```



##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/SaveModePlaceHolderEnum.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.seatunnel.api.sink;
+
+import java.util.Arrays;
+import java.util.Optional;
+
+public enum SaveModePlaceHolderEnum {
+    ROWTYPE_PRIMARY_KEY("rowtype_primary_key", "primaryKeys"),
+    ROWTYPE_UNIQUE_KEY("rowtype_unique_key", "uniqueKeys"),
+    ROWTYPE_FIELDS("rowtype_fields", "fields"),
+    TABLE_NAME("table_name", "tableName"),
+    DATABASE("database", "database");
+
+    private String keyValue;
+    private String actualValue;
+
+    private static final String REPLACE_PLACE_HOLDER = "\\$\\{%s\\}";
+    private static final String PLACE_HOLDER = "${%s}";
+
+    SaveModePlaceHolderEnum(String keyValue, String actualValue) {
+        this.keyValue = keyValue;
+        this.actualValue = actualValue;
+    }
+
+    public static String getActualValueByPlaceHolder(String placeholder) {
+        Optional<SaveModePlaceHolderEnum> saveModePlaceHolderEnumOptional =
+                Arrays.stream(SaveModePlaceHolderEnum.values())
+                        .filter(
+                                saveModePlaceHolderEnum ->
+                                        placeholder.equals(
+                                                
saveModePlaceHolderEnum.getPlaceHolder()))
+                        .findFirst();
+        if (saveModePlaceHolderEnumOptional.isPresent()) {
+            return saveModePlaceHolderEnumOptional.get().actualValue;
+        }
+        throw new RuntimeException(String.format("Not support the placeholder: 
%s", placeholder));
+    }
+
+    public String getPlaceHolderKeyValue() {
+        return this.keyValue;
+    }
+
+    public String getPlaceHolder() {
+        return String.format(PLACE_HOLDER, getPlaceHolderKeyValue());
+    }
+
+    public String getReplacePlaceHolder() {
+        return String.format(REPLACE_PLACE_HOLDER, getPlaceHolderKeyValue());
+    }

Review Comment:
   ```suggestion
       public String getPlaceholderKey() {
           return this.keyValue;
       }
   
       public String getPlaceholder() {
           return String.format(PLACE_HOLDER, getPlaceholderKey());
       }
   
       public String getReplacePlaceholder() {
           return String.format(REPLACE_PLACE_HOLDER, getPlaceholderKey());
       }
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to