This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new c5310442e83 Fix insert null object value by tablet error and fix
illegel value insert error message (#16971)
c5310442e83 is described below
commit c5310442e8306077744476712b99faf4e3497c84
Author: Haonan <[email protected]>
AuthorDate: Sun Jan 4 09:26:31 2026 +0800
Fix insert null object value by tablet error and fix illegel value insert
error message (#16971)
* Fix object insert bugs
* Fix IT
---
.../it/query/object/IoTDBObjectQueryIT.java | 32 ++++++++++++++++++++++
.../iotdb/relational/it/schema/IoTDBTableIT.java | 4 ++-
.../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 ++
6 files changed, 58 insertions(+), 1 deletion(-)
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/schema/IoTDBTableIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
index cc50ac4e02c..7ad5172fca4 100644
---
a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
@@ -884,7 +884,9 @@ public class IoTDBTableIT {
statement.execute(String.format("insert into test (a, b, c) values
('%s', 1, 1)", illegal));
try {
statement.execute(
- String.format("insert into test (a, b, c, d) values ('%s', 1, 1,
's')", illegal));
+ String.format(
+ "insert into test (a, b, c, d) values ('%s', 1, 1,
to_object(true, 0, X'aa'))",
+ illegal));
fail();
} catch (final SQLException e) {
Assert.assertEquals(
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);
}