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 db520e7d9a5d..fadcf72d5783 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.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 void sessionTest() { 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 cc50ac4e02c2..7ad5172fca41 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 @@ private void testObject4SingleIllegalPath(final String illegal) throws Exception 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 08946bf4cceb..6e0d869c86fb 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 void insertObjectTest() 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 3255c11f1e96..9a02eeab3b20 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 @@ private void handleObjectValue( 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 a33af21b1943..1cb5abed66ef 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 void transferType(ZoneId zoneId) throws QueryProcessException { // 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 1fa1ec44fc18..cc84bcc36ead 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 static Object parseValue(TSDataType dataType, String value, ZoneId zoneId } } 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); }