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

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


The following commit(s) were added to 
refs/heads/fix_status_code_of_type_column_mismatch by this push:
     new 9ecba998e3d Fix returned status code & data type conversion
9ecba998e3d is described below

commit 9ecba998e3d424ecc3671ade715d17107ae6aa53
Author: Tian Jiang <[email protected]>
AuthorDate: Thu Aug 22 12:24:33 2024 +0800

    Fix returned status code & data type conversion
---
 .../relational/it/db/it/IoTDBInsertTableIT.java    | 63 +---------------------
 .../db/queryengine/plan/analyze/AnalyzeUtils.java  |  9 +++-
 .../relational/sql/ast/WrappedInsertStatement.java | 12 +++--
 3 files changed, 16 insertions(+), 68 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertTableIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertTableIT.java
index 44924251a36..53dfe7700fe 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertTableIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertTableIT.java
@@ -173,66 +173,6 @@ public class IoTDBInsertTableIT {
     }
   }
 
-  @Test
-  public void testPartialInsertionRestart() throws SQLException {
-    try (Connection connection = 
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
-        Statement statement = connection.createStatement()) {
-      statement.execute("USE \"test\"");
-      statement.execute("SET CONFIGURATION enable_auto_create_schema='false'");
-      statement.execute(
-          "create table sg5 (id1 string id, s1 text measurement, s2 double 
measurement)");
-
-      try {
-        statement.execute("INSERT INTO sg5(id1,time,s1,s2) VALUES('d1', 
100,'test','test')");
-      } catch (SQLException e) {
-        // ignore
-      }
-    } finally {
-      try (Connection connection = 
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
-          Statement statement = connection.createStatement()) {
-        statement.execute("SET CONFIGURATION 
enable_auto_create_schema='true'");
-      }
-    }
-
-    // TODO: replace restartDaemon() with new methods in Env.
-    /*
-    long time = 0;
-    try {
-      EnvironmentUtils.restartDaemon();
-      StorageEngine.getInstance().recover();
-      // wait for recover
-      while (!StorageEngine.getInstance().isAllSgReady()) {
-        Thread.sleep(500);
-        time += 500;
-        if (time > 10000) {
-          logger.warn("wait too long in restart, wait for: " + time / 1000 + 
"s");
-        }
-      }
-    } catch (Exception e) {
-      fail(e.getMessage());
-    }
-     */
-
-    try (Connection connection = 
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
-        Statement statement = connection.createStatement()) {
-      statement.execute("use \"test\"");
-
-      try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM sg5")) 
{
-        assertNotNull(resultSet);
-        int cnt = 0;
-        while (resultSet.next()) {
-          cnt++;
-          assertEquals("test", resultSet.getString("s1"));
-        }
-        assertEquals(1, cnt);
-      }
-      try (ResultSet resultSet = statement.executeQuery("SELECT s2 FROM sg5")) 
{
-        assertNotNull(resultSet);
-        assertFalse(resultSet.next());
-      }
-    }
-  }
-
   @Test
   public void testPartialInsertTablet() {
     try (ISession session = 
EnvFactory.getEnv().getSessionConnection(BaseEnv.TABLE_SQL_DIALECT)) {
@@ -522,8 +462,7 @@ public class IoTDBInsertTableIT {
       st1.execute("insert into wt14(time, s1, s2) values(100, null, 1), (101, 
null, 2)");
       fail();
     } catch (SQLException e) {
-      assertTrue(
-          
e.getMessage().contains(Integer.toString(TSStatusCode.METADATA_ERROR.getStatusCode())));
+      assertEquals("507: Table wt14 does not exist", e.getMessage());
     }
     try (Connection connection = 
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT)) {
       try (Statement st2 = connection.createStatement()) {
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeUtils.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeUtils.java
index 3745ab09054..9d6556b501f 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeUtils.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeUtils.java
@@ -210,7 +210,14 @@ public class AnalyzeUtils {
         analysis.setFailStatus(
             RpcUtils.getStatus(exception.getErrorCode(), 
exception.getMessage()));
       } else {
-        analysis.setFailStatus(RpcUtils.getStatus(e.getErrorCode(), 
e.getMessage()));
+        if (e.getErrorCode() != TSStatusCode.SEMANTIC_ERROR.getStatusCode()) {
+          // a specific code has been set, use it
+          analysis.setFailStatus(RpcUtils.getStatus(e.getErrorCode(), 
e.getMessage()));
+        } else {
+          // use METADATA_ERROR by default
+          analysis.setFailStatus(
+              RpcUtils.getStatus(TSStatusCode.METADATA_ERROR.getStatusCode(), 
e.getMessage()));
+        }
       }
     } finally {
       
PERFORMANCE_OVERVIEW_METRICS.recordScheduleSchemaValidateCost(System.nanoTime() 
- startTime);
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/WrappedInsertStatement.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/WrappedInsertStatement.java
index 40efbcc669c..1e86418eab3 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/WrappedInsertStatement.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/WrappedInsertStatement.java
@@ -78,14 +78,16 @@ public abstract class WrappedInsertStatement extends 
WrappedStatement
         new ArrayList<>(insertBaseStatement.getMeasurements().length);
     for (int i = 0; i < insertBaseStatement.getMeasurements().length; i++) {
       if (insertBaseStatement.getMeasurements()[i] != null) {
+        TSDataType dataType = insertBaseStatement.getDataType(i);
+        if (dataType == null) {
+          dataType =
+              TypeInferenceUtils.getPredictedDataType(
+                  insertBaseStatement.getFirstValueOfIndex(i), true);
+        }
         columnSchemas.add(
             new ColumnSchema(
                 insertBaseStatement.getMeasurements()[i],
-                insertBaseStatement.getDataType(i) != null
-                    ? TypeFactory.getType(insertBaseStatement.getDataType(i))
-                    : TypeFactory.getType(
-                        TypeInferenceUtils.getPredictedDataType(
-                            insertBaseStatement.getFirstValueOfIndex(i), 
true)),
+                dataType != null ? TypeFactory.getType(dataType) : null,
                 false,
                 insertBaseStatement.getColumnCategory(i)));
       } else {

Reply via email to