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

jt2594838 pushed a commit to branch remove_swtich_type
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 93a97ed6e95f4836f151551683d3fc1667b578b4
Author: Tian Jiang <[email protected]>
AuthorDate: Tue Aug 25 20:50:15 2026 +0800

    multiple refactors
---
 .../plan/relational/type/InternalTypeManager.java  | 67 ++++------------------
 .../relational/type/InternalTypeManagerTest.java   | 61 ++++++++++++++++++++
 2 files changed, 72 insertions(+), 56 deletions(-)

diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/queryengine/plan/relational/type/InternalTypeManager.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/queryengine/plan/relational/type/InternalTypeManager.java
index c3d2fcd880f..8d236c888fa 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/queryengine/plan/relational/type/InternalTypeManager.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/queryengine/plan/relational/type/InternalTypeManager.java
@@ -82,66 +82,21 @@ public class InternalTypeManager implements TypeManager {
     if (type == null) {
       return null;
     }
-    TypeEnum typeEnum = type.getTypeEnum();
-    switch (typeEnum) {
-      case TEXT:
-        return TSDataType.TEXT;
-      case FLOAT:
-        return TSDataType.FLOAT;
-      case DOUBLE:
-        return TSDataType.DOUBLE;
-      case INT32:
-        return TSDataType.INT32;
-      case INT64:
-        return TSDataType.INT64;
-      case BOOLEAN:
-        return TSDataType.BOOLEAN;
-      case UNKNOWN:
-        return TSDataType.UNKNOWN;
-      case DATE:
-        return TSDataType.DATE;
-      case TIMESTAMP:
-        return TSDataType.TIMESTAMP;
-      case BLOB:
-      case ROW:
-        return TSDataType.BLOB;
-      case STRING:
-        return TSDataType.STRING;
-      case OBJECT:
-        return TSDataType.OBJECT;
-      default:
-        throw new IllegalArgumentException();
+    final TypeEnum typeEnum = type.getTypeEnum();
+    // TSDataType has no ROW counterpart, so preserve its existing binary 
representation.
+    if (typeEnum == TypeEnum.ROW) {
+      return TSDataType.BLOB;
     }
+    if (typeEnum == TypeEnum.VECTOR) {
+      throw new IllegalArgumentException();
+    }
+    return TSDataType.valueOf(typeEnum.name());
   }
 
   public static Type fromTSDataType(TSDataType dataType) {
-    switch (dataType) {
-      case TEXT:
-        return TEXT;
-      case FLOAT:
-        return FLOAT;
-      case DOUBLE:
-        return DOUBLE;
-      case INT32:
-        return INT32;
-      case INT64:
-        return INT64;
-      case BOOLEAN:
-        return BOOLEAN;
-      case UNKNOWN:
-        return UNKNOWN;
-      case DATE:
-        return DATE;
-      case TIMESTAMP:
-        return TIMESTAMP;
-      case BLOB:
-        return BLOB;
-      case OBJECT:
-        return OBJECT;
-      case STRING:
-        return STRING;
-      default:
-        throw new IllegalArgumentException();
+    if (dataType == TSDataType.VECTOR) {
+      throw new IllegalArgumentException();
     }
+    return Type.fromTsDataType(dataType);
   }
 }
diff --git 
a/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/queryengine/plan/relational/type/InternalTypeManagerTest.java
 
b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/queryengine/plan/relational/type/InternalTypeManagerTest.java
new file mode 100644
index 00000000000..f579d0d0f01
--- /dev/null
+++ 
b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/queryengine/plan/relational/type/InternalTypeManagerTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.iotdb.commons.queryengine.plan.relational.type;
+
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.type.RowType;
+import org.apache.tsfile.read.common.type.Type;
+import org.apache.tsfile.read.common.type.VectorType;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+public class InternalTypeManagerTest {
+
+  @Test
+  public void testScalarTypeConversion() {
+    for (final TSDataType dataType : TSDataType.values()) {
+      if (dataType == TSDataType.VECTOR) {
+        continue;
+      }
+
+      final Type type = InternalTypeManager.fromTSDataType(dataType);
+      assertSame(Type.fromTsDataType(dataType), type);
+      assertEquals(dataType, InternalTypeManager.getTSDataType(type));
+    }
+  }
+
+  @Test
+  public void testSpecialTypes() {
+    assertNull(InternalTypeManager.getTSDataType(null));
+    assertEquals(
+        TSDataType.BLOB,
+        InternalTypeManager.getTSDataType(
+            RowType.anonymousRow(Type.fromTsDataType(TSDataType.INT32))));
+
+    Assert.assertThrows(
+        IllegalArgumentException.class,
+        () -> InternalTypeManager.fromTSDataType(TSDataType.VECTOR));
+    Assert.assertThrows(
+        IllegalArgumentException.class, () -> 
InternalTypeManager.getTSDataType(VectorType.VECTOR));
+  }
+}

Reply via email to