Skip to content

[client-v2] hasValue on GenericRecord does not work as intended #2755

@rickysaltzer

Description

@rickysaltzer

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

  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions