Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fillMeasurements NPE #313

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -369,27 +369,31 @@ void fillInto(TsBlock block, int blockRowNum) {
final TsPrimitiveType value = vector[i];
final List<Integer> columnPositions = posInResult.get(i);
for (Integer pos : columnPositions) {
switch (value.getDataType()) {
case TEXT:
block.getColumn(pos).getBinaries()[blockRowNum] = value.getBinary();
break;
case INT32:
block.getColumn(pos).getInts()[blockRowNum] = value.getInt();
break;
case INT64:
block.getColumn(pos).getLongs()[blockRowNum] = value.getLong();
break;
case BOOLEAN:
block.getColumn(pos).getBooleans()[blockRowNum] = value.getBoolean();
break;
case FLOAT:
block.getColumn(pos).getFloats()[blockRowNum] = value.getFloat();
break;
case DOUBLE:
block.getColumn(pos).getDoubles()[blockRowNum] = value.getDouble();
break;
default:
throw new IllegalArgumentException("Unsupported data type: " + value.getDataType());
if (value != null) {
switch (value.getDataType()) {
case TEXT:
block.getColumn(pos).getBinaries()[blockRowNum] = value.getBinary();
break;
case INT32:
block.getColumn(pos).getInts()[blockRowNum] = value.getInt();
break;
case INT64:
block.getColumn(pos).getLongs()[blockRowNum] = value.getLong();
break;
case BOOLEAN:
block.getColumn(pos).getBooleans()[blockRowNum] = value.getBoolean();
break;
case FLOAT:
block.getColumn(pos).getFloats()[blockRowNum] = value.getFloat();
break;
case DOUBLE:
block.getColumn(pos).getDoubles()[blockRowNum] = value.getDouble();
break;
default:
throw new IllegalArgumentException("Unsupported data type: " + value.getDataType());
}
} else {
block.getColumn(pos).setNull(blockRowNum, blockRowNum + 1);
}
block.getColumn(pos).setPositionCount(blockRowNum + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,74 @@ public void testQueryTable() throws Exception {
Assert.assertTrue(resultSet.isNull(5));
}
}

@Test
public void testQueryTableWithPartialNullValueInChunk() throws Exception {
TableSchema tableSchema =
new TableSchema(
"t1",
Arrays.asList(
new MeasurementSchema("id1", TSDataType.STRING),
new MeasurementSchema("id2", TSDataType.STRING),
new MeasurementSchema("s1", TSDataType.BOOLEAN),
new MeasurementSchema("s2", TSDataType.BOOLEAN)),
Arrays.asList(
Tablet.ColumnCategory.ID,
Tablet.ColumnCategory.ID,
Tablet.ColumnCategory.MEASUREMENT,
Tablet.ColumnCategory.MEASUREMENT));
Tablet tablet =
new Tablet(
Arrays.asList("id1", "id2", "s1", "s2"),
Arrays.asList(
TSDataType.STRING, TSDataType.STRING, TSDataType.BOOLEAN, TSDataType.BOOLEAN),
1024);
tablet.addTimestamp(0, 0);
tablet.addValue("id1", 0, "id_field1");
tablet.addValue("id2", 0, "id_field2");
tablet.addValue("s1", 0, true);
tablet.addValue("s2", 0, false);

tablet.addTimestamp(1, 1);
tablet.addValue("id1", 1, "id_field1");
tablet.addValue("id2", 1, "id_field2");
tablet.addValue("s2", 1, false);

try (ITsFileWriter writer =
new TsFileWriterBuilder().file(tsfile).tableSchema(tableSchema).build()) {
writer.write(tablet);
}

try (DeviceTableModelReader tsFileReader = new DeviceTableModelReader(tsfile);
ResultSet resultSet =
tsFileReader.query("t1", Arrays.asList("id1", "id2", "s2", "s1"), 0, 2); ) {
// id1 id2 s2 s1
ResultSetMetadata resultSetMetadata = resultSet.getMetadata();
// Time id1 id2 s2 s1
Assert.assertEquals("Time", resultSetMetadata.getColumnName(1));
Assert.assertEquals(TSDataType.INT64, resultSetMetadata.getColumnType(1));
Assert.assertEquals("id1", resultSetMetadata.getColumnName(2));
Assert.assertEquals(TSDataType.STRING, resultSetMetadata.getColumnType(2));
Assert.assertEquals("id2", resultSetMetadata.getColumnName(3));
Assert.assertEquals(TSDataType.STRING, resultSetMetadata.getColumnType(3));
Assert.assertEquals("s2", resultSetMetadata.getColumnName(4));
Assert.assertEquals(TSDataType.BOOLEAN, resultSetMetadata.getColumnType(4));
Assert.assertEquals("s1", resultSetMetadata.getColumnName(5));
Assert.assertEquals(TSDataType.BOOLEAN, resultSetMetadata.getColumnType(5));

Assert.assertTrue(resultSet.next());
Assert.assertEquals(0, resultSet.getLong(1));
Assert.assertEquals("id_field1", resultSet.getString(2));
Assert.assertEquals("id_field2", resultSet.getString(3));
Assert.assertFalse(resultSet.getBoolean(4));
Assert.assertTrue(resultSet.getBoolean(5));

Assert.assertTrue(resultSet.next());
Assert.assertEquals(1, resultSet.getLong(1));
Assert.assertEquals("id_field1", resultSet.getString(2));
Assert.assertEquals("id_field2", resultSet.getString(3));
Assert.assertTrue(resultSet.isNull("s1"));
Assert.assertFalse(resultSet.getBoolean("s2"));
}
}
}