Skip to content

Conversation

@ennuite
Copy link
Contributor

@ennuite ennuite commented Aug 6, 2025

What's Changed

Instead of always obtaining a result set for queries issued via
PreparedStatement.execute(), we now inspect the dataset_schema
returned in ActionCreatePreparedStatementResult. If the schema has no
fields, we retrieve the update count instead. This aligns the return
value with the expectations of the JDBC API.

For such cases, the Arrow Flight SQL path now uses
CommandPreparedStatementUpdate instead of
CommandPreparedStatementQuery. This change mirrors the existing
approach in Statement.execute() and Statement.executeUpdate().

Are these changes tested?

Yes

Closes #797.

ennuite added 2 commits August 7, 2025 00:25
What's Changed

Instead of always obtaining a result set for queries issued via
PreparedStatement.execute(), we now inspect the dataset_schema
returned in ActionCreatePreparedStatementResult. If the schema has no
fields, we retrieve the update count instead. This aligns the return
value with the expectations of the JDBC API.

For such cases, the Arrow Flight SQL path now uses
CommandPreparedStatementUpdate instead of
CommandPreparedStatementQuery. This change mirrors the existing
approach in Statement.execute() and Statement.executeUpdate().
@ennuite ennuite marked this pull request as ready for review August 7, 2025 09:01
@lidavidm lidavidm changed the title GH-797: [JDBC] Fix pstmt.execute() for DML/DDL GH-797: [JDBC] Fix PreparedStatement#execute for DML/DDL Aug 7, 2025
Copy link
Member

@lidavidm lidavidm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks reasonable to me.

@lidavidm
Copy link
Member

lidavidm commented Aug 7, 2025

@alamb @jbonofre do InfluxDB and Dremio satisfy the assumptions here (dataset_schema will be populated if and only if the query of a prepared statement returns a result set)? I'm wondering if there might be systems that don't analyze the query at first and always omit the schema until actual execution

(We should really try to set up integration testing with Dremio and InfluxDB...)

@alamb
Copy link
Contributor

alamb commented Aug 7, 2025

@alamb @jbonofre do InfluxDB and Dremio satisfy the assumptions here (dataset_schema will be populated if and only if the query of a prepared statement returns a result set)? I'm wondering if there might be systems that don't analyze the query at first and always omit the schema until actual execution

Yes.

However, I think all our queries return results (InfluxDB doesn't do DDL / DML using SQL -- there is an alternate write path) so this particular issue is unlikely to affect us

Our system will actually analyze / plan the query twice -- once on the prepare and once when executing. While this is somewhat wasteful it allows us to remain stateless between requests

@ennuite
Copy link
Contributor Author

ennuite commented Aug 20, 2025

@lidavidm Hello David. I currently work at Dremio. From our side we are ok with these changes.

@lidavidm lidavidm merged commit 156b465 into apache:main Aug 20, 2025
19 of 24 checks passed
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.

PreparedStatement.execute() returns True for DML/DDL queries

3 participants