Skip to content
Closed
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 @@ -569,12 +569,19 @@ public Object[] getObjectArray(String colName) {

@Override
public boolean hasValue(int colIndex) {
if (colIndex < 1 || colIndex > currentRecord.length) {
return false;
}
return currentRecord[colIndex - 1] != null;
}

@Override
public boolean hasValue(String colName) {
return hasValue(schema.nameToColumnIndex(colName));
try {
return hasValue(schema.nameToColumnIndex(colName));
} catch (NoSuchColumnException e) {
return false;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,4 +846,35 @@ public void testEmptyArraysByIndex() throws Exception {
Assert.assertEquals(reader.getList(2).size(), 0);
Assert.assertEquals(reader.getList(3).size(), 0);
}

@Test
public void testHasValueWithMissingColumns() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();

String[] names = new String[]{"a", "b"};
String[] types = new String[]{"UInt32", "UInt32"};

BinaryStreamUtils.writeVarInt(out, names.length);
for (String name : names) {
BinaryStreamUtils.writeString(out, name);
}
for (String type : types) {
BinaryStreamUtils.writeString(out, type);
}

BinaryStreamUtils.writeUnsignedInt32(out, 1L);
BinaryStreamUtils.writeUnsignedInt32(out, 2L);

InputStream in = new ByteArrayInputStream(out.toByteArray());
QuerySettings querySettings = new QuerySettings().setUseTimeZone("UTC");
RowBinaryWithNamesAndTypesFormatReader reader =
new RowBinaryWithNamesAndTypesFormatReader(in, querySettings, new BinaryStreamReader.CachingByteBufferAllocator());
reader.next();

Assert.assertTrue(reader.hasValue("a"), "Expected hasValue(\"a\") to be true");
Assert.assertTrue(reader.hasValue(1), "Expected hasValue(1) to be true");
Assert.assertFalse(reader.hasValue("missing"), "Expected hasValue(\"missing\") to return false, not throw");
Assert.assertFalse(reader.hasValue(100), "Expected hasValue(100) to return false, not throw");
Assert.assertFalse(reader.hasValue(0), "Expected hasValue(0) to return false, not throw");
}
}
Loading