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

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

commit dff9a24195c72fa0ad81e9bfa04c9963804b9e0a
Author: HTHou <[email protected]>
AuthorDate: Tue Dec 30 18:34:22 2025 +0800

    Fix object insert bugs
---
 .../it/query/object/IoTDBObjectQueryIT.java        | 32 ++++++++++++++++++++++
 .../relational/it/session/IoTDBObjectInsertIT.java | 10 +++++++
 .../node/write/RelationalInsertTabletNode.java     |  3 ++
 .../plan/statement/crud/InsertRowStatement.java    |  7 +++++
 .../org/apache/iotdb/db/utils/CommonUtils.java     |  3 ++
 5 files changed, 55 insertions(+)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/object/IoTDBObjectQueryIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/object/IoTDBObjectQueryIT.java
index db520e7d9a5..fadcf72d578 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/object/IoTDBObjectQueryIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/object/IoTDBObjectQueryIT.java
@@ -34,6 +34,7 @@ import org.apache.tsfile.enums.TSDataType;
 import org.apache.tsfile.read.common.Field;
 import org.apache.tsfile.read.common.RowRecord;
 import org.junit.AfterClass;
+import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -274,4 +275,35 @@ public class IoTDBObjectQueryIT {
       fail(e.getMessage());
     }
   }
+
+  @Test
+  public void testIllegalObjectValue() {
+    try (ITableSession session = 
EnvFactory.getEnv().getTableSessionConnection()) {
+      session.executeNonQueryStatement("USE " + DATABASE_NAME);
+      try {
+        session.executeNonQueryStatement(
+            "INSERT INTO t1(time, device_id, b1, o1, s1, l1, l2) VALUES(1, 
'd1', X'cafebabe01', 1, 'cafebabe01', 0, 100)");
+        fail();
+      } catch (StatementExecutionException e) {
+        Assert.assertTrue(e.getMessage().contains("data type is not 
consistent"));
+      }
+
+      try {
+        session.executeNonQueryStatement(
+            "INSERT INTO t1(time, device_id, b1, o1, s1, l1, l2) VALUES(1, 
'd1', X'cafebabe01', 'test', 'cafebabe01', 0, 100)");
+        fail();
+      } catch (StatementExecutionException e) {
+        Assert.assertTrue(e.getMessage().contains("data type is not 
consistent"));
+      }
+
+      try {
+        session.executeNonQueryStatement(
+            "INSERT INTO t1(time, device_id, b1, o1, s1, l1, l2) VALUES(1, 
'd1', X'cafebabe01', X'cafebabe01', 'cafebabe01', 0, 100)");
+      } catch (StatementExecutionException e) {
+        Assert.assertTrue(e.getMessage().contains("data type is not 
consistent"));
+      }
+    } catch (IoTDBConnectionException | StatementExecutionException e) {
+      fail(e.getMessage());
+    }
+  }
 }
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/session/IoTDBObjectInsertIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/session/IoTDBObjectInsertIT.java
index 08946bf4cce..6e0d869c86f 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/session/IoTDBObjectInsertIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/session/IoTDBObjectInsertIT.java
@@ -127,6 +127,16 @@ public class IoTDBObjectInsertIT {
       session.insert(tablet);
       tablet.reset();
 
+      // insert another row without object value
+      rowIndex = tablet.getRowSize();
+      tablet.addTimestamp(rowIndex, 2);
+      tablet.addValue(rowIndex, 0, "1");
+      tablet.addValue(rowIndex, 1, "5");
+      tablet.addValue(rowIndex, 2, "3");
+      tablet.addValue(rowIndex, 3, 37.6F);
+      session.insert(tablet);
+      tablet.reset();
+
       try (SessionDataSet dataSet =
           session.executeQueryStatement("select file from object_table where 
time = 1")) {
         SessionDataSet.DataIterator iterator = dataSet.iterator();
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java
index 3255c11f1e9..9a02eeab3b2 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java
@@ -469,6 +469,9 @@ public class RelationalInsertTabletNode extends 
InsertTabletNode {
         continue;
       }
       byte[] binary = ((Binary[]) columns[column])[j].getValues();
+      if (binary == null || binary.length == 0) {
+        continue;
+      }
       ByteBuffer buffer = ByteBuffer.wrap(binary);
       boolean isEoF = buffer.get() == 1;
       long offset = buffer.getLong();
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 a33af21b194..1cb5abed66e 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
@@ -234,6 +234,13 @@ public class InsertRowStatement extends 
InsertBaseStatement implements ISchemaVa
         // 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);
+        } else if (dataTypes[i] == TSDataType.OBJECT && values[i] instanceof 
Binary) {
+          if (((Binary) values[i]).getValues().length < 9
+              || ((Binary) values[i]).getValues()[0] != 0
+                  && ((Binary) values[i]).getValues()[0] != 1) {
+            throw new IllegalArgumentException(
+                "data type is not consistent, input " + values[i] + ", 
registered " + dataTypes[i]);
+          }
         }
       } catch (Exception e) {
         LOGGER.warn(
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java
index 1fa1ec44fc1..cc84bcc36ea 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java
@@ -160,6 +160,9 @@ public class CommonUtils {
             }
           }
           return new Binary(parseBlobStringToByteArray(value));
+        case OBJECT:
+          throw new NumberFormatException(
+              "data type is not consistent, input " + value + ", registered " 
+ dataType);
         default:
           throw new QueryProcessException("Unsupported data type:" + dataType);
       }

Reply via email to