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

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

Reply via email to