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

[PR] [Feature][transform-v2] Chinese numerals convert to Arabic numerals Transform support [seatunnel]

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

   <!--
   
   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][transform-v2] Chinese numerals convert to Arabic numerals Transform support [seatunnel]

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


##########
docs/en/transform-v2/sql-functions.md:
##########
@@ -1126,3 +1126,13 @@ SELECT * FROM dual
 	LATERAL VIEW OUTER EXPLODE ( age ) AS age
 	LATERAL VIEW OUTER EXPLODE ( ARRAY(1,1) ) AS num
 ```
+### CHINESE_TO_NUM

Review Comment:
   The currently known databases or SQL tools do not support this functionality



-- 
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][transform-v2] Chinese numerals convert to Arabic numerals Transform support [seatunnel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #9540: [Feature][transform-v2] Chinese numerals convert to Arabic numerals Transform support
URL: https://github.com/apache/seatunnel/pull/9540


-- 
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][transform-v2] Chinese numerals convert to Arabic numerals Transform support [seatunnel]

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


##########
docs/en/transform-v2/sql-functions.md:
##########
@@ -1126,3 +1126,13 @@ SELECT * FROM dual
 	LATERAL VIEW OUTER EXPLODE ( age ) AS age
 	LATERAL VIEW OUTER EXPLODE ( ARRAY(1,1) ) AS num
 ```
+### CHINESE_TO_NUM

Review Comment:
   Thanks, but I doubt this is a common requirement. Are there other databases or SQL tools that implement this functionality?



-- 
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][transform-v2] Chinese numerals convert to Arabic numerals Transform support [seatunnel]

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


##########
docs/en/transform-v2/sql-functions.md:
##########
@@ -1126,3 +1126,13 @@ SELECT * FROM dual
 	LATERAL VIEW OUTER EXPLODE ( age ) AS age
 	LATERAL VIEW OUTER EXPLODE ( ARRAY(1,1) ) AS num
 ```
+### CHINESE_TO_NUM

Review Comment:
   So I think we should not add this function for now. There is no clear evidence that this is a universal requirement.



-- 
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][transform-v2] Chinese numerals convert to Arabic numerals Transform support [seatunnel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9540:
URL: https://github.com/apache/seatunnel/pull/9540#issuecomment-3494264904

   This pull request has been automatically marked as stale because it has not had recent activity for 120 days. It will be closed in 7 days if no further activity occurs.


-- 
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][transform-v2] Chinese numerals convert to Arabic numerals Transform support [seatunnel]

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


##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/udf/chineseToNum/ChineseNumToArabicNum.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.udf.chineseToNum;
+
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.transform.sql.zeta.ZetaUDF;
+
+import org.apache.commons.lang3.StringUtils;
+
+import com.google.auto.service.AutoService;
+
+import java.util.List;
+
+// 中文数字转阿拉伯数字
+@AutoService(ZetaUDF.class)
+public class ChineseNumToArabicNum implements ZetaUDF {
+
+    @Override
+    public String functionName() {
+        return "CHINESE_TO_NUM";
+    }
+
+    @Override
+    public SeaTunnelDataType<?> resultType(List<SeaTunnelDataType<?>> argsType) {
+        return BasicType.LONG_TYPE;
+    }
+
+    @Override
+    public Object evaluate(List<Object> args) {
+        String data = (String) args.get(0);
+        if (StringUtils.isBlank(data)) {
+            return data;

Review Comment:
   The method is declared to return a Long (`resultType` is LONG_TYPE), but here it returns the original String on blank input, leading to a type mismatch. Consider returning null or 0L instead of the raw String.
   ```suggestion
               return null;
   ```



##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/udf/chineseToNum/CNToNumber.java:
##########
@@ -0,0 +1,247 @@
+/*
+ * 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.udf.chineseToNum;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+/** */
+@Slf4j
+public class CNToNumber {
+
+    /** 中文数字 */
+    private static final String allChineseNum = "零一二三四五六七八九壹贰叁肆伍陆柒捌玖十拾百佰千仟万萬亿兆京";
+
+    private static final String SIMPLE_ONE = "一";
+    private static final String SIMPLE_TWO = "二";
+    private static final String SIMPLE_THREE = "三";
+    private static final String SIMPLE_FOUR = "四";
+    private static final String SIMPLE_FIVE = "五";
+    private static final String SIMPLE_SIX = "六";
+    private static final String SIMPLE_SEVEN = "七";
+    private static final String SIMPLE_EIGHT = "八";
+    private static final String SIMPLE_NINE = "九";
+    private static final String SIMPLE_TEN = "十";
+    private static final String SIMPLE_HUNDRED = "百";
+    private static final String SIMPLE_THOUSAND = "千";
+    private static final String SIMPLE_TEN_THOUSAND = "万";
+    private static final String TRADITION_ONE = "壹";
+    private static final String TRADITION_TWO = "贰";
+    private static final String TRADITION_THREE = "叁";
+    private static final String TRADITION_FOUR = "肆";
+    private static final String TRADITION_FIVE = "伍";
+    private static final String TRADITION_SIX = "陆";
+    private static final String TRADITION_SEVEN = "柒";
+    private static final String TRADITION_EIGHT = "捌";
+    private static final String TRADITION_NINE = "玖";
+    private static final String TRADITION_TEN = "拾";
+    private static final String TRADITION_HUNDRED = "佰";
+    private static final String TRADITION_THOUSAND = "仟";
+    private static final String TRADITION_TEN_THOUSAND = "萬";
+    private static final String HUNDRED_MILLION = "亿";
+    private static final String HUNDRED_BILLION = "兆";
+    private static final String HUNDRED_TRILLION = "京";
+    private static final String ZERO = "零";
+
+    private static HashMap<String, Long> chMap = new HashMap<>();
+
+    static {
+        chMap.put(ZERO, 0l);
+        chMap.put(SIMPLE_ONE, 1l);
+        chMap.put(SIMPLE_TWO, 2l);
+        chMap.put(SIMPLE_THREE, 3l);
+        chMap.put(SIMPLE_FOUR, 4l);
+        chMap.put(SIMPLE_FIVE, 5l);
+        chMap.put(SIMPLE_SIX, 6l);
+        chMap.put(SIMPLE_SEVEN, 7l);
+        chMap.put(SIMPLE_EIGHT, 8l);
+        chMap.put(SIMPLE_NINE, 9l);
+        chMap.put(TRADITION_ONE, 1l);
+        chMap.put(TRADITION_TWO, 2l);
+        chMap.put(TRADITION_THREE, 3l);
+        chMap.put(TRADITION_FOUR, 4l);
+        chMap.put(TRADITION_FIVE, 5l);
+        chMap.put(TRADITION_SIX, 6l);
+        chMap.put(TRADITION_SEVEN, 7l);
+        chMap.put(TRADITION_EIGHT, 8l);
+        chMap.put(TRADITION_NINE, 9l);
+        chMap.put(SIMPLE_TEN, 10l);
+        chMap.put(TRADITION_TEN, 10l);
+        chMap.put(SIMPLE_HUNDRED, 100l);
+        chMap.put(TRADITION_HUNDRED, 100l);
+        chMap.put(SIMPLE_THOUSAND, 1000l);
+        chMap.put(TRADITION_THOUSAND, 1000l);
+        chMap.put(SIMPLE_TEN_THOUSAND, 10000l);
+        chMap.put(TRADITION_TEN_THOUSAND, 10000l);
+        chMap.put(HUNDRED_MILLION, 100000000l);
+        chMap.put(HUNDRED_BILLION, 1000000000000l);
+        chMap.put(HUNDRED_TRILLION, 10000000000000000l);

Review Comment:
   [nitpick] Lowercase `l` for long literals can be confused with the digit `1`. Consider using uppercase `L` (e.g., `0L`) for clarity.
   ```suggestion
           chMap.put(ZERO, 0L);
           chMap.put(SIMPLE_ONE, 1L);
           chMap.put(SIMPLE_TWO, 2L);
           chMap.put(SIMPLE_THREE, 3L);
           chMap.put(SIMPLE_FOUR, 4L);
           chMap.put(SIMPLE_FIVE, 5L);
           chMap.put(SIMPLE_SIX, 6L);
           chMap.put(SIMPLE_SEVEN, 7L);
           chMap.put(SIMPLE_EIGHT, 8L);
           chMap.put(SIMPLE_NINE, 9L);
           chMap.put(TRADITION_ONE, 1L);
           chMap.put(TRADITION_TWO, 2L);
           chMap.put(TRADITION_THREE, 3L);
           chMap.put(TRADITION_FOUR, 4L);
           chMap.put(TRADITION_FIVE, 5L);
           chMap.put(TRADITION_SIX, 6L);
           chMap.put(TRADITION_SEVEN, 7L);
           chMap.put(TRADITION_EIGHT, 8L);
           chMap.put(TRADITION_NINE, 9L);
           chMap.put(SIMPLE_TEN, 10L);
           chMap.put(TRADITION_TEN, 10L);
           chMap.put(SIMPLE_HUNDRED, 100L);
           chMap.put(TRADITION_HUNDRED, 100L);
           chMap.put(SIMPLE_THOUSAND, 1000L);
           chMap.put(TRADITION_THOUSAND, 1000L);
           chMap.put(SIMPLE_TEN_THOUSAND, 10000L);
           chMap.put(TRADITION_TEN_THOUSAND, 10000L);
           chMap.put(HUNDRED_MILLION, 100000000L);
           chMap.put(HUNDRED_BILLION, 1000000000000L);
           chMap.put(HUNDRED_TRILLION, 10000000000000000L);
   ```



-- 
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][transform-v2] Chinese numerals convert to Arabic numerals Transform support [seatunnel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9540:
URL: https://github.com/apache/seatunnel/pull/9540#issuecomment-3524531495

   This pull request has been closed because it has not had recent activity. You could reopen it if you try to continue your work, and anyone who are interested in it are encouraged to continue work on this pull request.


-- 
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