Skip to content
Merged
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 @@ -590,6 +590,10 @@ public boolean isBinary() {
return this == TEXT || this == STRING || this == BLOB || this == OBJECT;
}

public boolean isTextStringOrBlob() {
return this == TEXT || this == STRING || this == BLOB;
}

// Indicating the statistics don't contain values, such as first, last, min, max...
public boolean hasNoValueInStatistics() {
return this == BLOB || this == OBJECT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ public void addValue(int rowIndex, String measurement, String val) {

@TsFileApi
public void addValue(int rowIndex, int columnIndex, String val) {
if (!(values[columnIndex] instanceof Binary[])) {
if (!(values[columnIndex] instanceof Binary[])
|| !schemas.get(columnIndex).getType().isTextStringOrBlob()) {
throw new IllegalArgumentException(
"The data type of column index " + columnIndex + " is not TEXT/STRING/BLOB");
}
Expand All @@ -529,7 +530,8 @@ public void addValue(int rowIndex, String measurement, byte[] val) {

@TsFileApi
public void addValue(int rowIndex, int columnIndex, byte[] val) {
if (!(values[columnIndex] instanceof Binary[])) {
if (!(values[columnIndex] instanceof Binary[])
|| !schemas.get(columnIndex).getType().isTextStringOrBlob()) {
throw new IllegalArgumentException(
"The data type of column index " + columnIndex + " is not TEXT/STRING/BLOB");
}
Expand Down Expand Up @@ -562,7 +564,8 @@ public void addValue(int rowIndex, int columnIndex, LocalDate val) {
}

public void addValue(int rowIndex, int columnIndex, boolean isEOF, long offset, byte[] content) {
if (!(values[columnIndex] instanceof Binary[])) {
if (!(values[columnIndex] instanceof Binary[])
|| schemas.get(columnIndex).getType() != TSDataType.OBJECT) {
throw new IllegalArgumentException(
"The data type of column index " + columnIndex + " is not OBJECT");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,57 @@ private void addValueWithException(Tablet tablet, String column, int rowIndex, O
Assert.fail();
}

@Test
public void testWriteWrongType2() {
final String deviceId = "root.sg";
final List<IMeasurementSchema> measurementSchemas = new ArrayList<>();
measurementSchemas.add(new MeasurementSchema("s0", TSDataType.INT32));
measurementSchemas.add(new MeasurementSchema("s1", TSDataType.INT64));
measurementSchemas.add(new MeasurementSchema("s2", TSDataType.FLOAT));
measurementSchemas.add(new MeasurementSchema("s3", TSDataType.DOUBLE));
measurementSchemas.add(new MeasurementSchema("s4", TSDataType.BOOLEAN));
measurementSchemas.add(new MeasurementSchema("s5", TSDataType.TEXT));
measurementSchemas.add(new MeasurementSchema("s6", TSDataType.STRING));
measurementSchemas.add(new MeasurementSchema("s7", TSDataType.BLOB));
measurementSchemas.add(new MeasurementSchema("s8", TSDataType.TIMESTAMP));
measurementSchemas.add(new MeasurementSchema("s9", TSDataType.DATE));
measurementSchemas.add(new MeasurementSchema("s10", TSDataType.OBJECT));

Tablet tablet = new Tablet(deviceId, measurementSchemas);
addValueWithException2(tablet, 0, 0, 1L);
addValueWithException2(tablet, 1, 0, "1");
addValueWithException2(tablet, 2, 0, 0.1d);
addValueWithException2(tablet, 3, 0, 0.1f);
addValueWithException2(tablet, 4, 0, "1");
addValueWithException2(tablet, 5, 0, 1L);
addValueWithException2(tablet, 6, 0, 1L);
addValueWithException2(tablet, 7, 0, 1L);
addValueWithException2(tablet, 8, 0, "str");
addValueWithException2(tablet, 9, 0, 1L);
addValueWithException2(tablet, 10, 0, "str");
}

private void addValueWithException2(Tablet tablet, int columnIndex, int rowIndex, Object value) {
try {
if (value instanceof Integer) {
tablet.addValue(rowIndex, columnIndex, (int) value);
} else if (value instanceof Double) {
tablet.addValue(rowIndex, columnIndex, (double) value);
} else if (value instanceof Long) {
tablet.addValue(rowIndex, columnIndex, (long) value);
} else if (value instanceof Float) {
tablet.addValue(rowIndex, columnIndex, (float) value);
} else if (value instanceof String) {
tablet.addValue(rowIndex, columnIndex, (String) value);
} else {
throw new IllegalArgumentException("Unsupported type: " + value.getClass());
}
} catch (IllegalArgumentException e) {
return;
}
Assert.fail();
}

@Test
public void testSerializeDateColumnWithNullValue() throws IOException {
final List<IMeasurementSchema> measurementSchemas = new ArrayList<>();
Expand Down
Loading