You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "liuwei178 (via GitHub)" <gi...@apache.org> on 2025/07/21 08:24:10 UTC

[PR] [Feature][SQL Transform] Check SQL Cast will fail or not during the SQL parsing stage [seatunnel]

liuwei178 opened a new pull request, #9600:
URL: https://github.com/apache/seatunnel/pull/9600

   - Removed unnecessary type conversion logic in SystemFunction
   - Added check on data type cast in ZetaSQLType.
   
   <!--
   
   Thank you for contributing to SeaTunnel! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   ## Contribution Checklist
     - Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/seatunnel/issues).
     - Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
     - Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
   -->
   
   ### Purpose of this pull request
   
   <!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
   
   
   ### Does this PR introduce _any_ user-facing change?
   
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released SeaTunnel versions or within the unreleased branches such as dev.
   If no, write 'No'.
   If you are adding/modifying connector documents, please follow our new specifications: https://github.com/apache/seatunnel/issues/4544.
   -->
   
   
   ### How was this patch tested?
   
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If you are adding E2E test cases, maybe refer to https://github.com/apache/seatunnel/blob/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-cdc-mysql-e2e/src/test/resources/mysqlcdc_to_mysql.conf, here is a good example.
   -->
   
   
   ### Check list
   
   * [ ] If any new Jar binary package adding in your PR, please add License Notice according
     [New License Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/contribution/new-license.md)
   * [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/seatunnel/tree/dev/docs
   * [ ] If you are contributing the connector code, please check that the following files are updated:
     1. Update [plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties) and add new connector information in it
     2. Update the pom file of [seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
     3. Add ci label in [label-scope-conf](https://github.com/apache/seatunnel/blob/dev/.github/workflows/labeler/label-scope-conf.yml)
     4. Add e2e testcase in [seatunnel-e2e](https://github.com/apache/seatunnel/tree/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/)
     5. Update connector [plugin_config](https://github.com/apache/seatunnel/blob/dev/config/plugin_config)


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][SQL Transform] Check SQL Cast will fail or not during the SQL parsing stage [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X merged PR #9600:
URL: https://github.com/apache/seatunnel/pull/9600


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][SQL Transform] Check SQL Cast will fail or not during the SQL parsing stage [seatunnel]

Posted by "liuwei178 (via GitHub)" <gi...@apache.org>.
liuwei178 commented on PR #9600:
URL: https://github.com/apache/seatunnel/pull/9600#issuecomment-3102111944

   <img width="1802" height="457" alt="image" src="https://github.com/user-attachments/assets/2e5afc41-1d0f-4b0e-b8ed-f8d967a7db88" />
   <img width="1604" height="653" alt="image" src="https://github.com/user-attachments/assets/c8f97598-3090-496f-ae54-262d40a9b7ac" />
   What should I do if some unmodified modules report a timeout during the CI phase?


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][SQL Transform] Check SQL Cast will fail or not during the SQL parsing stage [seatunnel]

Posted by "Carl-Zhou-CN (via GitHub)" <gi...@apache.org>.
Carl-Zhou-CN commented on code in PR #9600:
URL: https://github.com/apache/seatunnel/pull/9600#discussion_r2234504165


##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/CastFunction.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.transform.sql.zeta.functions;
+
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.DecimalType;
+import org.apache.seatunnel.api.table.type.LocalTimeType;
+import org.apache.seatunnel.api.table.type.PrimitiveByteArrayType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SqlType;
+import org.apache.seatunnel.common.exception.CommonErrorCodeDeprecated;
+import org.apache.seatunnel.transform.exception.TransformException;
+
+import net.sf.jsqlparser.statement.create.table.ColDataType;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class CastFunction {
+
+    public static final String DECIMAL = "DECIMAL";
+    public static final String VARCHAR = "VARCHAR";
+    public static final String STRING = "STRING";
+    public static final String TINYINT = "TINYINT";
+    public static final String SMALLINT = "SMALLINT";
+    public static final String INT = "INT";
+    public static final String INTEGER = "INTEGER";
+    public static final String BIGINT = "BIGINT";
+    public static final String LONG = "LONG";
+    public static final String BYTE = "BYTE";
+    public static final String BYTES = "BYTES";
+    public static final String BINARY = "BINARY";
+    public static final String DOUBLE = "DOUBLE";
+    public static final String FLOAT = "FLOAT";
+    public static final String TIMESTAMP = "TIMESTAMP";
+    public static final String DATETIME = "DATETIME";
+    public static final String DATE = "DATE";
+    public static final String TIME = "TIME";
+    public static final String BOOLEAN = "BOOLEAN";
+
+    public static final List<SqlType> INT_CAST_TYPE =
+            Arrays.asList(
+                    SqlType.TINYINT, SqlType.SMALLINT, SqlType.INT, SqlType.BIGINT, SqlType.STRING);
+    public static final List<SqlType> LONG_CAST_TYPES =
+            Arrays.asList(
+                    SqlType.TINYINT, SqlType.SMALLINT, SqlType.INT, SqlType.BIGINT, SqlType.STRING);
+    public static final List<SqlType> FLOAT_CAST_TYPES =
+            Arrays.asList(
+                    SqlType.TINYINT,
+                    SqlType.SMALLINT,
+                    SqlType.INT,
+                    SqlType.BIGINT,
+                    SqlType.FLOAT,
+                    SqlType.DOUBLE,
+                    SqlType.STRING);
+    public static final List<SqlType> BOOLEAN_CAST_TYPES =
+            Arrays.asList(
+                    SqlType.BOOLEAN,
+                    SqlType.STRING,
+                    SqlType.BIGINT,
+                    SqlType.INT,
+                    SqlType.SMALLINT,
+                    SqlType.TINYINT,
+                    SqlType.FLOAT,
+                    SqlType.DOUBLE);
+    public static final List<SqlType> DATETIME_CAST_TYPES =
+            Arrays.asList(SqlType.TIMESTAMP, SqlType.TIMESTAMP_TZ, SqlType.BIGINT);
+    public static final List<SqlType> DATE_CAST_TYPES =
+            Arrays.asList(SqlType.TIMESTAMP, SqlType.TIMESTAMP_TZ, SqlType.DATE, SqlType.INT);
+    public static final List<SqlType> TIME_CAST_TYPES =
+            Arrays.asList(SqlType.TIMESTAMP, SqlType.TIMESTAMP_TZ, SqlType.TIME, SqlType.INT);
+
+    public static SeaTunnelDataType<?> getCastType(SqlType originType, ColDataType colDataType) {
+        String dataType = colDataType.getDataType();
+        switch (dataType.toUpperCase()) {
+            case DECIMAL:
+                List<String> ps = colDataType.getArgumentsStringList();
+                return new DecimalType(Integer.parseInt(ps.get(0)), Integer.parseInt(ps.get(1)));
+            case VARCHAR:
+            case STRING:
+                return BasicType.STRING_TYPE;
+            case BYTE:
+            case TINYINT:
+                if (SqlType.TINYINT.equals(originType) || SqlType.STRING.equals(originType)) {

Review Comment:
   Ok. Thank you for your answer



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][SQL Transform] Check SQL Cast will fail or not during the SQL parsing stage [seatunnel]

Posted by "liuwei178 (via GitHub)" <gi...@apache.org>.
liuwei178 commented on PR #9600:
URL: https://github.com/apache/seatunnel/pull/9600#issuecomment-3101258642

   i added the test and enabled the CI. Please take some time to review them when you're available @Hisoka-X 


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][SQL Transform] Check SQL Cast will fail or not during the SQL parsing stage [seatunnel]

Posted by "liuwei178 (via GitHub)" <gi...@apache.org>.
liuwei178 commented on code in PR #9600:
URL: https://github.com/apache/seatunnel/pull/9600#discussion_r2234335085


##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/CastFunction.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.transform.sql.zeta.functions;
+
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.DecimalType;
+import org.apache.seatunnel.api.table.type.LocalTimeType;
+import org.apache.seatunnel.api.table.type.PrimitiveByteArrayType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SqlType;
+import org.apache.seatunnel.common.exception.CommonErrorCodeDeprecated;
+import org.apache.seatunnel.transform.exception.TransformException;
+
+import net.sf.jsqlparser.statement.create.table.ColDataType;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class CastFunction {
+
+    public static final String DECIMAL = "DECIMAL";
+    public static final String VARCHAR = "VARCHAR";
+    public static final String STRING = "STRING";
+    public static final String TINYINT = "TINYINT";
+    public static final String SMALLINT = "SMALLINT";
+    public static final String INT = "INT";
+    public static final String INTEGER = "INTEGER";
+    public static final String BIGINT = "BIGINT";
+    public static final String LONG = "LONG";
+    public static final String BYTE = "BYTE";
+    public static final String BYTES = "BYTES";
+    public static final String BINARY = "BINARY";
+    public static final String DOUBLE = "DOUBLE";
+    public static final String FLOAT = "FLOAT";
+    public static final String TIMESTAMP = "TIMESTAMP";
+    public static final String DATETIME = "DATETIME";
+    public static final String DATE = "DATE";
+    public static final String TIME = "TIME";
+    public static final String BOOLEAN = "BOOLEAN";
+
+    public static final List<SqlType> INT_CAST_TYPE =
+            Arrays.asList(
+                    SqlType.TINYINT, SqlType.SMALLINT, SqlType.INT, SqlType.BIGINT, SqlType.STRING);
+    public static final List<SqlType> LONG_CAST_TYPES =
+            Arrays.asList(
+                    SqlType.TINYINT, SqlType.SMALLINT, SqlType.INT, SqlType.BIGINT, SqlType.STRING);
+    public static final List<SqlType> FLOAT_CAST_TYPES =
+            Arrays.asList(
+                    SqlType.TINYINT,
+                    SqlType.SMALLINT,
+                    SqlType.INT,
+                    SqlType.BIGINT,
+                    SqlType.FLOAT,
+                    SqlType.DOUBLE,
+                    SqlType.STRING);
+    public static final List<SqlType> BOOLEAN_CAST_TYPES =
+            Arrays.asList(
+                    SqlType.BOOLEAN,
+                    SqlType.STRING,
+                    SqlType.BIGINT,
+                    SqlType.INT,
+                    SqlType.SMALLINT,
+                    SqlType.TINYINT,
+                    SqlType.FLOAT,
+                    SqlType.DOUBLE);
+    public static final List<SqlType> DATETIME_CAST_TYPES =
+            Arrays.asList(SqlType.TIMESTAMP, SqlType.TIMESTAMP_TZ, SqlType.BIGINT);
+    public static final List<SqlType> DATE_CAST_TYPES =
+            Arrays.asList(SqlType.TIMESTAMP, SqlType.TIMESTAMP_TZ, SqlType.DATE, SqlType.INT);
+    public static final List<SqlType> TIME_CAST_TYPES =
+            Arrays.asList(SqlType.TIMESTAMP, SqlType.TIMESTAMP_TZ, SqlType.TIME, SqlType.INT);
+
+    public static SeaTunnelDataType<?> getCastType(SqlType originType, ColDataType colDataType) {
+        String dataType = colDataType.getDataType();
+        switch (dataType.toUpperCase()) {
+            case DECIMAL:
+                List<String> ps = colDataType.getArgumentsStringList();
+                return new DecimalType(Integer.parseInt(ps.get(0)), Integer.parseInt(ps.get(1)));
+            case VARCHAR:
+            case STRING:
+                return BasicType.STRING_TYPE;
+            case BYTE:
+            case TINYINT:
+                if (SqlType.TINYINT.equals(originType) || SqlType.STRING.equals(originType)) {

Review Comment:
   Yes, these are just some pre-validation steps added to our existing capabilities,for example, when converting Timestamp to SMALLINT is illegal  Link to refer to  https://github.com/apache/seatunnel/issues/9538



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][SQL Transform] Check SQL Cast will fail or not during the SQL parsing stage [seatunnel]

Posted by "liuwei178 (via GitHub)" <gi...@apache.org>.
liuwei178 commented on code in PR #9600:
URL: https://github.com/apache/seatunnel/pull/9600#discussion_r2234337747


##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/CastFunction.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.transform.sql.zeta.functions;
+
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.DecimalType;
+import org.apache.seatunnel.api.table.type.LocalTimeType;
+import org.apache.seatunnel.api.table.type.PrimitiveByteArrayType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SqlType;
+import org.apache.seatunnel.common.exception.CommonErrorCodeDeprecated;
+import org.apache.seatunnel.transform.exception.TransformException;
+
+import net.sf.jsqlparser.statement.create.table.ColDataType;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class CastFunction {
+
+    public static final String DECIMAL = "DECIMAL";
+    public static final String VARCHAR = "VARCHAR";
+    public static final String STRING = "STRING";
+    public static final String TINYINT = "TINYINT";
+    public static final String SMALLINT = "SMALLINT";
+    public static final String INT = "INT";
+    public static final String INTEGER = "INTEGER";
+    public static final String BIGINT = "BIGINT";
+    public static final String LONG = "LONG";
+    public static final String BYTE = "BYTE";
+    public static final String BYTES = "BYTES";
+    public static final String BINARY = "BINARY";
+    public static final String DOUBLE = "DOUBLE";
+    public static final String FLOAT = "FLOAT";
+    public static final String TIMESTAMP = "TIMESTAMP";
+    public static final String DATETIME = "DATETIME";
+    public static final String DATE = "DATE";
+    public static final String TIME = "TIME";
+    public static final String BOOLEAN = "BOOLEAN";
+
+    public static final List<SqlType> INT_CAST_TYPE =
+            Arrays.asList(
+                    SqlType.TINYINT, SqlType.SMALLINT, SqlType.INT, SqlType.BIGINT, SqlType.STRING);
+    public static final List<SqlType> LONG_CAST_TYPES =
+            Arrays.asList(
+                    SqlType.TINYINT, SqlType.SMALLINT, SqlType.INT, SqlType.BIGINT, SqlType.STRING);
+    public static final List<SqlType> FLOAT_CAST_TYPES =
+            Arrays.asList(
+                    SqlType.TINYINT,
+                    SqlType.SMALLINT,
+                    SqlType.INT,
+                    SqlType.BIGINT,
+                    SqlType.FLOAT,
+                    SqlType.DOUBLE,
+                    SqlType.STRING);
+    public static final List<SqlType> BOOLEAN_CAST_TYPES =
+            Arrays.asList(
+                    SqlType.BOOLEAN,
+                    SqlType.STRING,
+                    SqlType.BIGINT,
+                    SqlType.INT,
+                    SqlType.SMALLINT,
+                    SqlType.TINYINT,
+                    SqlType.FLOAT,
+                    SqlType.DOUBLE);
+    public static final List<SqlType> DATETIME_CAST_TYPES =
+            Arrays.asList(SqlType.TIMESTAMP, SqlType.TIMESTAMP_TZ, SqlType.BIGINT);
+    public static final List<SqlType> DATE_CAST_TYPES =
+            Arrays.asList(SqlType.TIMESTAMP, SqlType.TIMESTAMP_TZ, SqlType.DATE, SqlType.INT);
+    public static final List<SqlType> TIME_CAST_TYPES =
+            Arrays.asList(SqlType.TIMESTAMP, SqlType.TIMESTAMP_TZ, SqlType.TIME, SqlType.INT);
+
+    public static SeaTunnelDataType<?> getCastType(SqlType originType, ColDataType colDataType) {
+        String dataType = colDataType.getDataType();
+        switch (dataType.toUpperCase()) {
+            case DECIMAL:
+                List<String> ps = colDataType.getArgumentsStringList();
+                return new DecimalType(Integer.parseInt(ps.get(0)), Integer.parseInt(ps.get(1)));
+            case VARCHAR:
+            case STRING:
+                return BasicType.STRING_TYPE;
+            case BYTE:
+            case TINYINT:
+                if (SqlType.TINYINT.equals(originType) || SqlType.STRING.equals(originType)) {

Review Comment:
   Yes, these are just some pre-validation steps added to our existing capabilities, for example, when converting Timestamp to SMALLINT is illegal.    @Carl-Zhou-CN 
   Link to https://github.com/apache/seatunnel/issues/9538



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][SQL Transform] Check SQL Cast will fail or not during the SQL parsing stage [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #9600:
URL: https://github.com/apache/seatunnel/pull/9600#discussion_r2222300553


##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/ZetaSQLType.java:
##########
@@ -85,6 +86,24 @@ public class ZetaSQLType {
     public static final String TIME = "TIME";
     public static final String BOOLEAN = "BOOLEAN";
 
+    public static final List<SqlType> DATETIME_CAST_TYPES =

Review Comment:
   Thanks @liuwei178 . Can we refactor it and move the cast-related logic and validation rules into separate classes?



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][SQL Transform] Check SQL Cast will fail or not during the SQL parsing stage [seatunnel]

Posted by "liuwei178 (via GitHub)" <gi...@apache.org>.
liuwei178 commented on code in PR #9600:
URL: https://github.com/apache/seatunnel/pull/9600#discussion_r2234335085


##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/CastFunction.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.transform.sql.zeta.functions;
+
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.DecimalType;
+import org.apache.seatunnel.api.table.type.LocalTimeType;
+import org.apache.seatunnel.api.table.type.PrimitiveByteArrayType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SqlType;
+import org.apache.seatunnel.common.exception.CommonErrorCodeDeprecated;
+import org.apache.seatunnel.transform.exception.TransformException;
+
+import net.sf.jsqlparser.statement.create.table.ColDataType;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class CastFunction {
+
+    public static final String DECIMAL = "DECIMAL";
+    public static final String VARCHAR = "VARCHAR";
+    public static final String STRING = "STRING";
+    public static final String TINYINT = "TINYINT";
+    public static final String SMALLINT = "SMALLINT";
+    public static final String INT = "INT";
+    public static final String INTEGER = "INTEGER";
+    public static final String BIGINT = "BIGINT";
+    public static final String LONG = "LONG";
+    public static final String BYTE = "BYTE";
+    public static final String BYTES = "BYTES";
+    public static final String BINARY = "BINARY";
+    public static final String DOUBLE = "DOUBLE";
+    public static final String FLOAT = "FLOAT";
+    public static final String TIMESTAMP = "TIMESTAMP";
+    public static final String DATETIME = "DATETIME";
+    public static final String DATE = "DATE";
+    public static final String TIME = "TIME";
+    public static final String BOOLEAN = "BOOLEAN";
+
+    public static final List<SqlType> INT_CAST_TYPE =
+            Arrays.asList(
+                    SqlType.TINYINT, SqlType.SMALLINT, SqlType.INT, SqlType.BIGINT, SqlType.STRING);
+    public static final List<SqlType> LONG_CAST_TYPES =
+            Arrays.asList(
+                    SqlType.TINYINT, SqlType.SMALLINT, SqlType.INT, SqlType.BIGINT, SqlType.STRING);
+    public static final List<SqlType> FLOAT_CAST_TYPES =
+            Arrays.asList(
+                    SqlType.TINYINT,
+                    SqlType.SMALLINT,
+                    SqlType.INT,
+                    SqlType.BIGINT,
+                    SqlType.FLOAT,
+                    SqlType.DOUBLE,
+                    SqlType.STRING);
+    public static final List<SqlType> BOOLEAN_CAST_TYPES =
+            Arrays.asList(
+                    SqlType.BOOLEAN,
+                    SqlType.STRING,
+                    SqlType.BIGINT,
+                    SqlType.INT,
+                    SqlType.SMALLINT,
+                    SqlType.TINYINT,
+                    SqlType.FLOAT,
+                    SqlType.DOUBLE);
+    public static final List<SqlType> DATETIME_CAST_TYPES =
+            Arrays.asList(SqlType.TIMESTAMP, SqlType.TIMESTAMP_TZ, SqlType.BIGINT);
+    public static final List<SqlType> DATE_CAST_TYPES =
+            Arrays.asList(SqlType.TIMESTAMP, SqlType.TIMESTAMP_TZ, SqlType.DATE, SqlType.INT);
+    public static final List<SqlType> TIME_CAST_TYPES =
+            Arrays.asList(SqlType.TIMESTAMP, SqlType.TIMESTAMP_TZ, SqlType.TIME, SqlType.INT);
+
+    public static SeaTunnelDataType<?> getCastType(SqlType originType, ColDataType colDataType) {
+        String dataType = colDataType.getDataType();
+        switch (dataType.toUpperCase()) {
+            case DECIMAL:
+                List<String> ps = colDataType.getArgumentsStringList();
+                return new DecimalType(Integer.parseInt(ps.get(0)), Integer.parseInt(ps.get(1)));
+            case VARCHAR:
+            case STRING:
+                return BasicType.STRING_TYPE;
+            case BYTE:
+            case TINYINT:
+                if (SqlType.TINYINT.equals(originType) || SqlType.STRING.equals(originType)) {

Review Comment:
   Yes, these are just some pre-validation steps added to our existing capabilities,for example, when converting Timestamp to SMALLINT is illegal  Link to refer to  https://github.com/apache/seatunnel/issues/9538



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][SQL Transform] Check SQL Cast will fail or not during the SQL parsing stage [seatunnel]

Posted by "liuwei178 (via GitHub)" <gi...@apache.org>.
liuwei178 commented on code in PR #9600:
URL: https://github.com/apache/seatunnel/pull/9600#discussion_r2222801690


##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/ZetaSQLType.java:
##########
@@ -85,6 +86,24 @@ public class ZetaSQLType {
     public static final String TIME = "TIME";
     public static final String BOOLEAN = "BOOLEAN";
 
+    public static final List<SqlType> DATETIME_CAST_TYPES =

Review Comment:
   Okay, I'll refactor it as soon as possible



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][SQL Transform] Check SQL Cast will fail or not during the SQL parsing stage [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on PR #9600:
URL: https://github.com/apache/seatunnel/pull/9600#issuecomment-3097107833

   Thanks @liuwei178 . Please follow the guide to open CI on your fork repository. https://github.com/apache/seatunnel/pull/9600/checks?check_run_id=46369080578


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][SQL Transform] Check SQL Cast will fail or not during the SQL parsing stage [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on PR #9600:
URL: https://github.com/apache/seatunnel/pull/9600#issuecomment-3102394004

   > What should I do if some unmodified modules report a timeout during the CI phase?
   
   Please retrigger the failed ci. Thanks


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][SQL Transform] Check SQL Cast will fail or not during the SQL parsing stage [seatunnel]

Posted by "liuwei178 (via GitHub)" <gi...@apache.org>.
liuwei178 commented on code in PR #9600:
URL: https://github.com/apache/seatunnel/pull/9600#discussion_r2224668036


##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/ZetaSQLType.java:
##########
@@ -85,6 +86,24 @@ public class ZetaSQLType {
     public static final String TIME = "TIME";
     public static final String BOOLEAN = "BOOLEAN";
 
+    public static final List<SqlType> DATETIME_CAST_TYPES =

Review Comment:
   @Hisoka-X   hi,Please help check which parts still need to adjust 



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][SQL Transform] Check SQL Cast will fail or not during the SQL parsing stage [seatunnel]

Posted by "Carl-Zhou-CN (via GitHub)" <gi...@apache.org>.
Carl-Zhou-CN commented on code in PR #9600:
URL: https://github.com/apache/seatunnel/pull/9600#discussion_r2232835858


##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/CastFunction.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.transform.sql.zeta.functions;
+
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.DecimalType;
+import org.apache.seatunnel.api.table.type.LocalTimeType;
+import org.apache.seatunnel.api.table.type.PrimitiveByteArrayType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SqlType;
+import org.apache.seatunnel.common.exception.CommonErrorCodeDeprecated;
+import org.apache.seatunnel.transform.exception.TransformException;
+
+import net.sf.jsqlparser.statement.create.table.ColDataType;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class CastFunction {
+
+    public static final String DECIMAL = "DECIMAL";
+    public static final String VARCHAR = "VARCHAR";
+    public static final String STRING = "STRING";
+    public static final String TINYINT = "TINYINT";
+    public static final String SMALLINT = "SMALLINT";
+    public static final String INT = "INT";
+    public static final String INTEGER = "INTEGER";
+    public static final String BIGINT = "BIGINT";
+    public static final String LONG = "LONG";
+    public static final String BYTE = "BYTE";
+    public static final String BYTES = "BYTES";
+    public static final String BINARY = "BINARY";
+    public static final String DOUBLE = "DOUBLE";
+    public static final String FLOAT = "FLOAT";
+    public static final String TIMESTAMP = "TIMESTAMP";
+    public static final String DATETIME = "DATETIME";
+    public static final String DATE = "DATE";
+    public static final String TIME = "TIME";
+    public static final String BOOLEAN = "BOOLEAN";
+
+    public static final List<SqlType> INT_CAST_TYPE =
+            Arrays.asList(
+                    SqlType.TINYINT, SqlType.SMALLINT, SqlType.INT, SqlType.BIGINT, SqlType.STRING);
+    public static final List<SqlType> LONG_CAST_TYPES =
+            Arrays.asList(
+                    SqlType.TINYINT, SqlType.SMALLINT, SqlType.INT, SqlType.BIGINT, SqlType.STRING);
+    public static final List<SqlType> FLOAT_CAST_TYPES =
+            Arrays.asList(
+                    SqlType.TINYINT,
+                    SqlType.SMALLINT,
+                    SqlType.INT,
+                    SqlType.BIGINT,
+                    SqlType.FLOAT,
+                    SqlType.DOUBLE,
+                    SqlType.STRING);
+    public static final List<SqlType> BOOLEAN_CAST_TYPES =
+            Arrays.asList(
+                    SqlType.BOOLEAN,
+                    SqlType.STRING,
+                    SqlType.BIGINT,
+                    SqlType.INT,
+                    SqlType.SMALLINT,
+                    SqlType.TINYINT,
+                    SqlType.FLOAT,
+                    SqlType.DOUBLE);
+    public static final List<SqlType> DATETIME_CAST_TYPES =
+            Arrays.asList(SqlType.TIMESTAMP, SqlType.TIMESTAMP_TZ, SqlType.BIGINT);
+    public static final List<SqlType> DATE_CAST_TYPES =
+            Arrays.asList(SqlType.TIMESTAMP, SqlType.TIMESTAMP_TZ, SqlType.DATE, SqlType.INT);
+    public static final List<SqlType> TIME_CAST_TYPES =
+            Arrays.asList(SqlType.TIMESTAMP, SqlType.TIMESTAMP_TZ, SqlType.TIME, SqlType.INT);
+
+    public static SeaTunnelDataType<?> getCastType(SqlType originType, ColDataType colDataType) {
+        String dataType = colDataType.getDataType();
+        switch (dataType.toUpperCase()) {
+            case DECIMAL:
+                List<String> ps = colDataType.getArgumentsStringList();
+                return new DecimalType(Integer.parseInt(ps.get(0)), Integer.parseInt(ps.get(1)));
+            case VARCHAR:
+            case STRING:
+                return BasicType.STRING_TYPE;
+            case BYTE:
+            case TINYINT:
+                if (SqlType.TINYINT.equals(originType) || SqlType.STRING.equals(originType)) {

Review Comment:
   For validation types, are they referring to the types that we currently have the capability to convert?



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org