Repository navigation
fix(jdbc-v2): throw SQLException for an invalid type name in createArrayOf and createStruct - #3363
Open
smthwentroong wants to merge 2 commits into
Open
smthwentroong wants to merge 2 commits into
smthwentroong wants to merge 2 commits into
Conversation
…rayOf and createStruct
3 tasks done
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
Connection.createArrayOf(typeName, ...)andConnection.createStruct(typeName, ...)threw an uncheckedIllegalArgumentExceptionorNumberFormatExceptionwhen the type-name parser rejectedtypeName. Both methods declarethrows SQLException. Thus acatch (SQLException e)block and frameworks that translateSQLExceptiondid not get the error.Changes:
ConnectionImplparses the type name in a new private helperparseColumnType. The helper wraps a parser exception inSQLExceptionwith SQLStateHY000. The message contains the type name. The parser exception is the cause.createArrayOfandcreateStructuse this helper.typeName == null(SQLFeatureNotSupportedException), a closed connection (08000), a non-Tuple type increateStruct, and valid type names.User-visible behavior: for a type name that the driver cannot parse, the two methods throw
SQLExceptioninstead ofIllegalArgumentException/NumberFormatException.Compatibility: a caller that catches
IllegalArgumentExceptionfrom these two methods now getsSQLException.SQLExceptionis already in both method signatures, so existing code compiles.Tests:
ConnectionTest.testCreateArrayOfAndStructRejectInvalidTypeName: one@DataProviderwith 9 rejected type names (unknown type, misspelled type, unknown nested type, unbalanced parentheses, invalidDecimalparameter, empty string). For both methods, the test checks the exact classSQLException, SQLStateHY000, the type name in the message, and anIllegalArgumentExceptioncause.server_time_zone, so it does not need a ClickHouse server.ConnectionTestunit tests pass (mvn -pl jdbc-v2 -am verify -DskipITs -Dtest=ConnectionTest). I did not run the integration tests locally.Closes #3347
Checklist
history/latest/3347.md)Note
Low Risk
Client-side JDBC error-mapping only; no server or security logic changes, with a minor compatibility shift for code that caught unchecked parser exceptions from these two methods.
Overview
jdbc-v2 now reports unparseable
typeNamevalues fromcreateArrayOfandcreateStructas checkedSQLException(SQLStateHY000) instead of bubblingIllegalArgumentException/NumberFormatExceptionfromClickHouseColumn.of. A newparseColumnTypehelper performs the parse and wraps failures with a message that includes the type name and the original parser exception as the cause.Unit tests cover nine invalid type-name cases for both methods (WireMock, no real server). Changelog documents the behavior change for issue #3347.
Callers that specifically caught
IllegalArgumentExceptionfrom these paths must handleSQLExceptioninstead.Reviewed by Cursor Bugbot for commit 5f65acb. Bugbot is set up for automated code reviews on this repo. Configure here.