Gabriel39 opened a new pull request, #68162:
URL: https://github.com/apache/doris/pull/68162

   ### What problem does this PR solve?
   
   `vector_search("query_vector"=?, "top_k"=?)` currently converts the 
placeholders into the literal string `?`, so server-side prepared Lance vector 
queries fail during analysis.
   
   Preserve placeholders for `query_vector`, `top_k`, `offset`, and `filter`, 
and bind fresh property values on every EXECUTE. PREPARE resolves the output 
schema without requiring a query vector. Table, column, and search 
configuration remain constant. Each execution performs normal analysis and 
planning and resolves Lance metadata again; the retained statement never caches 
a bound vector or snapshot.
   
   This supports both indexed and flat searches and reuses the parsed 
statement. It does not introduce an execution-plan cache or bypass the 
optimizer.
   
   Example with MySQL Connector/J and `useServerPrepStmts=true`:
   
   ```java
   try (PreparedStatement statement = connection.prepareStatement(
           "SELECT id, _distance FROM vector_search("
           + "'table'='catalog.db.items', 'column'='embedding', "
           + "'query_vector'=?, 'top_k'=?, 'offset'=?, 'filter'=?)")) {
       for (String vector : vectors) {
           statement.setString(1, vector); // JSON array matching the vector 
column dimension.
           statement.setInt(2, 10);
           statement.setInt(3, 0);
           statement.setString(4, "id > 0");
           try (ResultSet rows = statement.executeQuery()) {
               // Consume the result before executing the next vector.
           }
       }
   }
   ```
   
   ### Release note
   
   Support server-side prepared parameters for Lance `vector_search` query 
vectors, top-k, offsets, and filters.
   
   ### Validation
   
   - Parser and analyzer tests cover parameter retention, quoted question 
marks, case-insensitive properties, constant-only property rejection, repeated 
execution with different vectors and snapshots, mixed constants/parameters, and 
invalid or missing parameters.
   - A JDBC regression reuses one `ServerPreparedStatement` with A/B/A 
parameter changes and compares results with literal SQL for both indexed and 
flat searches.
   - Local verification: all 102 tests passed via `run-fe-ut.sh` (the two new 
suites, `NereidsParserTest`, `PrepareTest`, `LanceVectorQueryTest`, and both 
existing search TVF suites); FE Checkstyle passed; the JDBC regression script 
compiled with Groovy 4.0.19. The external JDBC regression requires the 
MinIO/Lance fixtures and has not been executed locally.
   
   ### Check List (For Author)
   
   - Test
       - [x] Regression test
       - [x] Unit Test
   - Behavior changed:
       - [x] Yes. Supported `vector_search` property values can be prepared 
parameters.
   - Does this need documentation?
       - [x] Yes. Usage and the supported parameter scope are documented above.
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label
   


-- 
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