Skip to content

branch-4.1: [fix](be) Fix ANN query vector extraction to handle all constant expression types #62637#62957

Merged
yiguolei merged 2 commits intoapache:branch-4.1from
zhiqiang-hhhh:pick_62637_to_upstream_branch-4.1
May 1, 2026
Merged

branch-4.1: [fix](be) Fix ANN query vector extraction to handle all constant expression types #62637#62957
yiguolei merged 2 commits intoapache:branch-4.1from
zhiqiang-hhhh:pick_62637_to_upstream_branch-4.1

Conversation

@zhiqiang-hhhh
Copy link
Copy Markdown
Contributor

cherry pick from #62637

…ession types (apache#62637)

## Proposed changes

Fix `extract_query_vector` in `ann_topn_runtime.cpp` to handle all
constant expression types instead of only `VArrayLiteral` and
`VCastExpr`.

### What problem does this PR solve?

Issue Number: close #xxx

Problem Summary:

The `extract_query_vector` function previously checked whether the query
vector argument was specifically a `VArrayLiteral` or `VCastExpr` via
`dynamic_pointer_cast`. When FE produced other constant expression forms
(e.g., after expression rewrites), ANN index queries would fail with
`InvalidArgument: Constant must be ArrayLiteral or CAST to array`.

The fix removes the rigid type check and instead:
1. Calls `get_const_col()` to materialize the constant expression
2. Unwraps `ColumnConst` via `check_and_get_column<ColumnConst>` to get
the underlying data column
3. Validates the resulting column shape (Nullable → Array → Float32)

This approach works for any constant expression that materializes to an
array column, regardless of the expression node type.

### Release note

Fix ANN vector index query failure when the query vector expression is
not a direct array literal or CAST expression.

### Check List (For Author)

- Test: Regression test
- Behavior changed: No
- Does this need documentation: No
@zhiqiang-hhhh zhiqiang-hhhh requested a review from yiguolei as a code owner April 30, 2026 02:18
@zhiqiang-hhhh
Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen
Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@zhiqiang-hhhh
Copy link
Copy Markdown
Contributor Author

run buildall

1 similar comment
@yiguolei
Copy link
Copy Markdown
Contributor

run buildall

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label May 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

PR approved by anyone and no changes requested.

@yiguolei yiguolei merged commit 97007c2 into apache:branch-4.1 May 1, 2026
27 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants