Description
The boolean hasValue(int) and boolean hasValue(string) methods do not work as intended. If the value does not exist, an exception is thrown rather than false.
Steps to reproduce
- Submit a basic query like (
SELECT 1 + 1 as result)
2a. Run hasValue("missing")
2b. Run hasValue(100)
Error Log or Exception StackTrace
For 2a
Method threw 'com.clickhouse.client.api.metadata.NoSuchColumnException' exception.
For 2b
Method threw 'java.lang.ArrayIndexOutOfBoundsException' exception.
Expected Behaviour
For both 2a and 2b, the expected behavior is for the method to return false if the value does not exist.
Notes
For 2a, see TableSchema - Either we should catch in the caller and return False, or return -1 as an indicator that the value is missing.
public int nameToIndex(String name) {
Integer index = colIndex.get(name);
if (index == null) {
throw new NoSuchColumnException("Result has no column with name '" + name + "'");
}
return index;
}
For 2b, see AbstractBinaryFormatReader - We should just check the size of the array and see if the parameter is within bounds rather than checking for a null.
public boolean hasValue(int colIndex) {
return currentRecord[colIndex - 1] != null;
}
@mzitnik
Description
The
boolean hasValue(int)andboolean hasValue(string)methods do not work as intended. If the value does not exist, an exception is thrown rather thanfalse.Steps to reproduce
SELECT 1 + 1 as result)2a. Run
hasValue("missing")2b. Run
hasValue(100)Error Log or Exception StackTrace
For 2a
For 2b
Expected Behaviour
For both 2a and 2b, the expected behavior is for the method to return
falseif the value does not exist.Notes
For 2a, see
TableSchema- Either we should catch in the caller and return False, or return -1 as an indicator that the value is missing.For 2b, see
AbstractBinaryFormatReader- We should just check the size of the array and see if the parameter is within bounds rather than checking for a null.@mzitnik