Repository navigation
Conversation
JdbcIO infers the schema of a query (readRows, readWithPartitions with row output) or of the destination table (write with a table and no statement) through PreparedStatement.getMetaData(). Some drivers, such as the Hive JDBC driver, don't implement it and throw SQLFeatureNotSupportedException, and the JDBC spec allows it to return null, so these transforms could not be used with them. When the metadata isn't available from the prepared statement, execute it with a maximum of one row and read the metadata of its result set. Fixes apache#26536 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Assigning reviewers: R: @Abacn added as fallback since no labels match configuration Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
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.
Fixes #26536
Some JdbcIO transforms infer a schema through
PreparedStatement.getMetaData():readRows(), andreadWithPartitions()with row output, infer the schema of the query.write()withwithTable(...)and no statement infers the schema of the destination table.Some drivers don't implement
getMetaData(). The Hive JDBC driver throwsSQLFeatureNotSupportedException, so these transforms failed with:The JDBC spec also allows
getMetaData()to returnnullwhen the driver can't describe the statement without running it.Change
A new
SchemaUtil.toBeamSchema(PreparedStatement)is used byReadRows.inferBeamSchemaand by the table schema lookup inwrite():getMetaData()when the driver supports it, so behaviour is unchanged for those drivers.setMaxRows(1)and reads the metadata of the result set.One limitation: the fallback can't execute a query that still has unset
?parameters, so for such queries on these drivers schema inference still fails.Testing
JdbcIOTestcases runreadRows()and a schema-inferredwrite()against a DerbyDataSource. The wrapper makesPreparedStatement.getMetaData()throwSQLFeatureNotSupportedException, like the Hive driver does. Both fail without this change and pass with it../gradlew :sdks:java:io:jdbc:test --tests '*JdbcIOTest' --tests '*SchemaUtilTest': 60 passed.Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.🤖 Generated with Claude Code