Skip to content

Commit cc7116d

Browse files
committed
bug-fix: Fix pstmt.execute() return for DML/DDL
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().
1 parent e4f6426 commit cc7116d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightMetaImpl.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,17 @@ static Signature newSignature(final String sql, Schema resultSetSchema, Schema p
6262
parameterSchema == null
6363
? new ArrayList<>()
6464
: ConvertUtils.convertArrowFieldsToAvaticaParameters(parameterSchema.getFields());
65-
65+
StatementType statementType =
66+
resultSetSchema == null || resultSetSchema.getFields().isEmpty()
67+
? StatementType.IS_DML
68+
: StatementType.SELECT;
6669
return new Signature(
6770
columnMetaData,
6871
sql,
6972
parameters,
7073
Collections.emptyMap(),
7174
null, // unnecessary, as SQL requests use ArrowFlightJdbcCursor
72-
StatementType.SELECT);
75+
statementType);
7376
}
7477

7578
@Override
@@ -105,7 +108,8 @@ public ExecuteResult execute(
105108
preparedStatement, ((ArrowFlightConnection) connection).getBufferAllocator())
106109
.bind(typedValues);
107110

108-
if (statementHandle.signature == null) {
111+
if (statementHandle.signature == null
112+
|| statementHandle.signature.statementType == StatementType.IS_DML) {
109113
// Update query
110114
long updatedCount = preparedStatement.executeUpdate();
111115
return new ExecuteResult(

0 commit comments

Comments
 (0)