github-actions[bot] commented on code in PR #68768:
URL: https://github.com/apache/doris/pull/68768#discussion_r4214747898


##########
fe/fe-core/src/main/java/org/apache/doris/service/arrowflight/FlightSqlQuerySchema.java:
##########
@@ -149,12 +164,26 @@ static Schema analyze(ConnectContext context, String 
query) throws Exception {
                 StatementContext statementContext = 
statement.getStatementContext();
                 context.setStatementContext(statementContext);
                 statementContext.setParsedStatement(statement);
-                if (!statementContext.getPlaceholders().isEmpty()) {
-                    throw CallStatus.UNIMPLEMENTED.withDescription(
-                            "Flight SQL parameter binding is not 
supported").toRuntimeException();
+                int parameterCount = statementContext.getPlaceholders().size();
+                if (parameterCount > FlightSqlParameters.MAX_PARAMETERS) {
+                    throw CallStatus.INVALID_ARGUMENT.withDescription("Too 
many query parameters (maximum 1024)")
+                            .toRuntimeException();
                 }
-                List<Field> fields = new ArrayList<>();
                 Plan plan = statement.getLogicalPlan();
+                if (parameterCount > 0) {
+                    if (statements.size() != 1 || plan instanceof Command) {
+                        throw CallStatus.INVALID_ARGUMENT.withDescription(
+                                "Parameters require a single query 
statement").toRuntimeException();
+                    }
+                    if (preparing) {
+                        // Output types may depend on the values (SELECT ?); 
advertise them only after binding.
+                        return Pair.of(null, parameterCount);

Review Comment:
   [P1] Preserve the result schema for parameterized SELECTs when it is known. 
For `SELECT CAST(? AS BIGINT)`, this unconditional return sends an empty 
`dataset_schema` at Prepare. Arrow JDBC 19 classifies an empty result schema as 
DML, so even a null-bound SELECT is sent through `executeUpdate` instead of 
returning its row; `GetSchema` before binding also fails despite the static 
BIGINT output. Plan and validate the query at Prepare where possible, and 
advertise the inferred schema for value-independent fields.



##########
fe/fe-core/src/main/java/org/apache/doris/service/arrowflight/DorisFlightSqlProducer.java:
##########
@@ -461,12 +486,19 @@ public void createPreparedStatement(final 
ActionCreatePreparedStatementRequest r
                     String query = request.getQuery();
                     // ADBC ExecuteSchema reads this dataset schema directly 
without calling GetSchema.
                     // Analyze before registering a handle so failed 
preparation does not retain a query.
-                    Schema schema = analyzeQuerySchema(connectContext, query);
+                    org.apache.doris.common.Pair<Schema, Integer> prepared = 
FlightSqlQuerySchema.prepare(
+                            connectContext, query);
+                    Schema schema = prepared.first;
+                    List<Field> parameters = new ArrayList<>();
+                    for (int i = 0; i < prepared.second; i++) {
+                        parameters.add(Field.nullable(

Review Comment:
   [P1] Advertise bindable parameter types for JDBC clients. Every placeholder 
is returned as Arrow `Null`, but the managed Arrow JDBC 19 binder creates 
vectors from this schema. For `SELECT CAST(? AS BIGINT)`, `setLong(1, 42)` 
reaches `NullAvaticaParameterConverter`, which throws `Can't set non-null value 
on NullVector` before Doris receives DoPut. Infer fixed placeholder types such 
as BIGINT and cover a JDBC `PreparedStatement` bind; the regression test's 
manually built BigIntVector bypasses this path.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to