Hisoka-X commented on code in PR #6679:
URL: https://github.com/apache/seatunnel/pull/6679#discussion_r1565421487
##########
seatunnel-common/src/main/java/org/apache/seatunnel/common/exception/CommonErrorCode.java:
##########
@@ -48,7 +48,8 @@ public enum CommonErrorCode implements SeaTunnelErrorCode {
"<identifier> <operation> file '<fileName>' failed, because it not
existed."),
WRITE_SEATUNNEL_ROW_ERROR(
"COMMON-23",
- "<connector> write SeaTunnelRow failed, the SeaTunnelRow value is
'<seaTunnelRow>'.");
+ "<connector> write SeaTunnelRow failed, the SeaTunnelRow value is
'<seaTunnelRow>'."),
+ SQL_TEMPLATE_HANDLED_ERROR("COMMON-24", "Handle the template with
placeholder failed.");
Review Comment:
```suggestion
SQL_TEMPLATE_HANDLED_ERROR("COMMON-24", "The table of <tableName> has no
<keyName>, but the template \n <template> \n which has the place holder named
<placeholder>. Please use the option named <optionName> to specify sql
template");
```
##########
seatunnel-common/src/main/java/org/apache/seatunnel/common/exception/CommonError.java:
##########
@@ -183,4 +184,12 @@ public static SeaTunnelRuntimeException jsonOperationError(
return new SeaTunnelRuntimeException(code, params);
}
}
+
+ public static SeaTunnelRuntimeException sqlTemplateHandledError(
+ String identifier, String operation, Throwable cause) {
+ Map<String, String> params = new HashMap<>();
+ params.put("identifier", identifier);
+ params.put("operation", operation);
Review Comment:
```suggestion
params.put("tableName", tableName);
params.put("keyName", keyName);
params.put("template", template);
params.put("placeholder", placeholder);
params.put("optionName", optionName);
```
##########
seatunnel-connectors-v2/connector-common/src/main/java/org/apache/seatunnel/connectors/seatunnel/common/sql/template/SqlTemplate.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.connectors.seatunnel.common.sql.template;
+
+import org.apache.seatunnel.api.sink.SaveModePlaceHolder;
+import org.apache.seatunnel.common.exception.CommonError;
+
+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 CommonError.sqlTemplateHandledError(
+ "SqlTemplate",
+ "canHandledByTemplateWithPlaceholder",
+ new RuntimeException(
+ String.format(
+ EXCEPTION_TEMPLATE,
+ tableName,
+
SaveModePlaceHolder.getDisplay(placeholder),
+ createTemplate,
+ placeholder,
+ optionsKey)));
+ }
Review Comment:
```suggestion
throw CommonError.sqlTemplateHandledError(
tableName,
SaveModePlaceHolder.getDisplay(placeholder),
createTemplate,
placeholder,
optionsKey));
}
```
--
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]