This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 07c0040ee8d Add DataTypeConverterTest (#37339)
07c0040ee8d is described below

commit 07c0040ee8d64ff1c2e7c9b212e00a268609aa49
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Dec 11 10:05:52 2025 +0800

    Add DataTypeConverterTest (#37339)
    
    * Rename DataTypeExpressionConverter
    
    * Add DataTypeConverterTest
---
 .../sql/ast/converter/type/DataTypeConverter.java  |  5 +--
 .../ast/converter/type/DataTypeConverterTest.java  | 42 ++++++++++++++++++++++
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git 
a/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/type/DataTypeConverter.java
 
b/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/type/DataTypeConverter.java
index fddb9ba722e..5c3a9c4c02a 100644
--- 
a/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/type/DataTypeConverter.java
+++ 
b/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/type/DataTypeConverter.java
@@ -51,9 +51,6 @@ public final class DataTypeConverter {
      * @return converted SQL operator
      */
     public static SqlTypeName convert(final String dataType) {
-        if (!REGISTRY.containsKey(dataType)) {
-            return SqlTypeName.valueOf(dataType);
-        }
-        return REGISTRY.get(dataType);
+        return REGISTRY.containsKey(dataType) ? REGISTRY.get(dataType) : 
SqlTypeName.valueOf(dataType.toUpperCase());
     }
 }
diff --git 
a/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/type/DataTypeConverterTest.java
 
b/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/type/DataTypeConverterTest.java
new file mode 100644
index 00000000000..157b667bbb6
--- /dev/null
+++ 
b/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/type/DataTypeConverterTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.shardingsphere.sqlfederation.compiler.sql.ast.converter.type;
+
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class DataTypeConverterTest {
+    
+    @Test
+    void assertConvertRegisteredDataType() {
+        assertThat(DataTypeConverter.convert("int"), is(SqlTypeName.INTEGER));
+        assertThat(DataTypeConverter.convert("int2"), 
is(SqlTypeName.SMALLINT));
+        assertThat(DataTypeConverter.convert("int4"), is(SqlTypeName.INTEGER));
+        assertThat(DataTypeConverter.convert("int8"), is(SqlTypeName.BIGINT));
+        assertThat(DataTypeConverter.convert("money"), 
is(SqlTypeName.DECIMAL));
+    }
+    
+    @Test
+    void assertConvertUnregisteredDataType() {
+        assertThat(DataTypeConverter.convert("varchar"), 
is(SqlTypeName.VARCHAR));
+        assertThat(DataTypeConverter.convert("VARCHAR"), 
is(SqlTypeName.VARCHAR));
+    }
+}

Reply via email to