Repository navigation
fix(jdbc-v2): throw SQLException when the writer schema lookup fails in prepareStatement - #3390
Open
rohan4naik wants to merge 1 commit into
Open
rohan4naik wants to merge 1 commit into
rohan4naik wants to merge 1 commit into
Conversation
…in prepareStatement With beta.row_binary_for_simple_insert=true, prepareStatement() calls Client#getTableSchema. Its unchecked ServerException / ClientException left prepareStatement() unchanged. Convert it with ExceptionUtils.toSqlState, as the other jdbc-v2 call sites do. Closes ClickHouse#3326
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
With
beta.row_binary_for_simple_insert=true,Connection#prepareStatement()for a simpleINSERT ... VALUES (?)asks the server for the table schema. When that lookup failed, the unchecked client-v2 exception (ServerExceptionorClientException) leftprepareStatement()as it was, although the method declaresthrows SQLException.Cause:
ConnectionImpl.prepareStatement(String, int, int, int)calledclient.getTableSchema(table, schema)without atry/catch.Fix: catch the failure of that call and re-throw it through
ExceptionUtils.toSqlState(e), the conversion the other jdbc-v2 call sites already use (for exampleWriterStatementImpl#executeLargeUpdate). An unknown table now gives SQL state42S02with error code 60, and other server errors give22000with the server code. The original exception stays as the cause.I kept the conversion in jdbc-v2 and did not touch
Client#getTableSchema, because client-v2 callers rely on its unchecked exceptions. Nothing changes when the lookup succeeds, and nothing changes with the writer off (no server call inprepareStatement).Compatibility: code that caught
ServerException/ClientExceptionfromprepareStatement()with the beta writer on now getsSQLExceptionwith that exception as the cause.Testing
JDBCErrorHandlingTests#testWriterSchemaLookupFailureThrowsSQLException(unknown table, unknown database). It fails without the fix ("Expected SQLException to be thrown, but ServerException was thrown") and passes with it.JDBCErrorHandlingTestsandWriterStatementImplTestagainst a local ClickHouse 26.11 server (TEST_CLICKHOUSE_CONTAINER=none): all pass. I could not run the Docker-based setup locally, so I did not run the whole integration suite; theConnectionTest/PreparedStatementTestfailures I saw locally (nodefaultcluster, no TLS endpoint, non-UTC machine time zone) occur with and without this change.This change was AI-assisted.
Closes #3326
Checklist
history/latest/3326.md)Note
Low Risk
Narrow error-handling change on a beta code path; behavior only shifts from unchecked exceptions to SQLException with preserved causes.
Overview
With
beta.row_binary_for_simple_insert=true,Connection#prepareStatement()on simple INSERT statements resolves table schema via the server; failures used to escape as uncheckedServerException/ClientExceptioninstead ofSQLException.ConnectionImplnow wrapsclient.getTableSchema()in try/catch and rethrows throughExceptionUtils.toSqlState(), aligning SQL state and error codes with the rest of jdbc-v2 (e.g. unknown table →42S02). Successful lookups and the non-writer path are unchanged.Integration coverage adds
testWriterSchemaLookupFailureThrowsSQLExceptionfor unknown table and unknown database; a changelog entry documents the fix for #3326.Reviewed by Cursor Bugbot for commit 14ba55b. Bugbot is set up for automated code reviews on this repo. Configure here.