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

jackietien pushed a commit to branch ty/TableModelGrammar
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/ty/TableModelGrammar by this 
push:
     new f6464aef0ad Fix BLOB conversion in Table sql insertion (#13043)
f6464aef0ad is described below

commit f6464aef0adafcc13a54c78ce530f4a24f5f6861
Author: Jiang Tian <[email protected]>
AuthorDate: Sat Jul 27 16:40:26 2024 +0800

    Fix BLOB conversion in Table sql insertion (#13043)
---
 .../it/query/old/IoTDBSimpleQueryTableIT.java      |  2 +-
 .../scalar/IoTDBSubStringFunctionTableIT.java      | 23 +++++++---------------
 .../plan/statement/crud/InsertRowStatement.java    |  4 +++-
 3 files changed, 11 insertions(+), 18 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/IoTDBSimpleQueryTableIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/IoTDBSimpleQueryTableIT.java
index 90650fca177..d253bdbeabc 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/IoTDBSimpleQueryTableIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/IoTDBSimpleQueryTableIT.java
@@ -664,7 +664,7 @@ public class IoTDBSimpleQueryTableIT {
         statement.execute(
             String.format(
                 "insert into table1(time, device, s4, s5, s6, s7) values(%d, 
'd1', '%s', %d, %s, '%s')",
-                i, LocalDate.of(2024, 5, i % 31 + 1), i, "'X''cafebabe'''", 
i));
+                i, LocalDate.of(2024, 5, i % 31 + 1), i, "X'cafebabe'", i));
       }
 
       try (ResultSet resultSet = statement.executeQuery("select * from 
table1")) {
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBSubStringFunctionTableIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBSubStringFunctionTableIT.java
index d31c12525b8..d2f5a081f0c 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBSubStringFunctionTableIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBSubStringFunctionTableIT.java
@@ -48,15 +48,8 @@ public class IoTDBSubStringFunctionTableIT {
       new String[] {
         "CREATE DATABASE " + DATABASE_NAME,
         "use " + DATABASE_NAME,
-        //          "create table table1(device_id STRING ID, s1 TEXT 
MEASUREMENT, s2 INT32
-        // MEASUREMENT, s3 INT64 MEASUREMENT, s4 FLOAT MEASUREMENT, s5 DOUBLE 
MEASUREMENT, s6
-        // BOOLEAN MEASUREMENT, s7 DATE MEASUREMENT, s8 TIMESTAMP MEASUREMENT, 
s9 STRING
-        // MEASUREMENT, s10 BLOB MEASUREMENT)",
-        //          "INSERT INTO 
table1(Time,device_id,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10) values(1,
-        // 'd1', 'abcd', 1, 1, 1, 1, true, '2021-10-01', 1633046400000, 
'abcd', X'abcd')",
-
-        "create table table1(device_id STRING ID, s1 TEXT MEASUREMENT, s2 
INT32 MEASUREMENT, s3 INT64 MEASUREMENT, s4 FLOAT MEASUREMENT, s5 DOUBLE 
MEASUREMENT, s6 BOOLEAN MEASUREMENT, s7 DATE MEASUREMENT, s8 TIMESTAMP 
MEASUREMENT, s9 STRING MEASUREMENT)",
-        "INSERT INTO table1(Time,device_id,s1,s2,s3,s4,s5,s6,s7,s8,s9) 
values(1, 'd1', 'abcd', 1, 1, 1, 1, true, '2021-10-01', 1633046400000, 'abcd')",
+        "create table table1(device_id STRING ID, s1 TEXT MEASUREMENT, s2 
INT32 MEASUREMENT, s3 INT64 MEASUREMENT, s4 FLOAT MEASUREMENT, s5 DOUBLE 
MEASUREMENT, s6 BOOLEAN MEASUREMENT, s7 DATE MEASUREMENT, s8 TIMESTAMP 
MEASUREMENT, s9 STRING MEASUREMENT, s10 BLOB MEASUREMENT)",
+        "INSERT INTO table1(Time,device_id,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10) 
values(1, 'd1', 'abcd', 1, 1, 1, 1, true, '2021-10-01', 1633046400000, 'abcd', 
X'abcd')",
         "INSERT INTO table1(Time,device_id,s1) values(2, 'd1', 'test')",
         "INSERT INTO table1(Time,device_id,s1) values(3, 'd1', 'abcdefg')",
         "INSERT INTO table1(Time,device_id,s9) values(2, 'd1', 'test')",
@@ -188,14 +181,12 @@ public class IoTDBSubStringFunctionTableIT {
             + ": Scalar function substring only accepts two or three arguments 
and first must be text or string data type, second and third must be numeric 
data types [INT32, INT64]",
         DATABASE_NAME);
 
-    // TODO add back after blob support
     // Wrong input type
-    //    tableAssertTestFail(
-    //        "select SUBSTRING(s10 FROM 1 FOR 1) from table1",
-    //        TSStatusCode.SEMANTIC_ERROR.getStatusCode()
-    //            + ": Scalar function substring only accepts two or three 
arguments and first must
-    // be text or string data type, second and third must be numeric data 
types [INT32, INT64]",
-    //        DATABASE_NAME);
+    tableAssertTestFail(
+        "select SUBSTRING(s10 FROM 1 FOR 1) from table1",
+        TSStatusCode.SEMANTIC_ERROR.getStatusCode()
+            + ": Scalar function substring only accepts two or three arguments 
and first must be text or string data type, second and third must be numeric 
data types [INT32, INT64]",
+        DATABASE_NAME);
 
     // Using substring with float start position
     tableAssertTestFail(
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/InsertRowStatement.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/InsertRowStatement.java
index d2987144508..500827d1a7c 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/InsertRowStatement.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/InsertRowStatement.java
@@ -45,6 +45,7 @@ import org.apache.tsfile.file.metadata.IDeviceID;
 import org.apache.tsfile.file.metadata.IDeviceID.Factory;
 import org.apache.tsfile.file.metadata.enums.CompressionType;
 import org.apache.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.tsfile.utils.Binary;
 import org.apache.tsfile.utils.Pair;
 import org.apache.tsfile.utils.ReadWriteIOUtils;
 import org.apache.tsfile.write.schema.MeasurementSchema;
@@ -228,7 +229,8 @@ public class InsertRowStatement extends InsertBaseStatement 
implements ISchemaVa
       // parse string value to specific type
       dataTypes[i] = measurementSchemas[i].getType();
       try {
-        if (values[i] != null) {
+        // if the type is binary and the value is already binary, do not 
convert
+        if (values[i] != null && !(dataTypes[i].isBinary() && values[i] 
instanceof Binary)) {
           values[i] = CommonUtils.parseValue(dataTypes[i], 
values[i].toString(), zoneId);
         }
       } catch (Exception e) {

Reply via email to