Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading