Skip to content

Fix hasValue to handle missing columns gracefully#2756

Closed
utafrali wants to merge 1 commit intoClickHouse:mainfrom
utafrali:fix/issue-2755-client-v2-hasvalue-on-genericrecord-does
Closed

Fix hasValue to handle missing columns gracefully#2756
utafrali wants to merge 1 commit intoClickHouse:mainfrom
utafrali:fix/issue-2755-client-v2-hasvalue-on-genericrecord-does

Conversation

@utafrali
Copy link

Issue

The hasValue() method on GenericRecord would throw exceptions when checking for non-existent columns:

  • hasValue(int colIndex) threw ArrayIndexOutOfBoundsException for out-of-range indices
  • hasValue(String colName) threw NoSuchColumnException for unknown column names

Solution

Add defensive checks to return false instead of throwing:

  • Add bounds validation in the int-based method to check column index is within valid range (1-based, between 1 and record length)
  • Wrap the name-to-index lookup in try-catch to handle NoSuchColumnException

This makes the API more intuitive and allows callers to safely check for column existence without exception handling.

Fixes #2755

…of throwing for missing columns

- Add bounds check to hasValue(int colIndex) to return false when colIndex is out of range instead of throwing ArrayIndexOutOfBoundsException
- Wrap hasValue(String colName) in try/catch for NoSuchColumnException to return false when column name does not exist instead of propagating the exception
- Add unit test testHasValueWithMissingColumns to verify both fixes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@chernser
Copy link
Contributor

@utafrali please accept CLA
Thanks!

@utafrali
Copy link
Author

Closing this PR — I'm unable to sign the CLA at this time. Thank you for the review!

@utafrali utafrali closed this Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants