The new SearchQueryAnalyzerRule in crates/search/src/analyzerrule.rs is broken. For…
- User
The new
SearchQueryAnalyzerRuleincrates/search/src/analyzer_rule.rsis broken.For
select id, _score from text_search(qs, 'what') order by _score limit 3;We get the following rewrite
| initial_logical_plan | Limit: skip=0, fetch=3 | | | Sort: text_search(qs, Utf8("what"))._score ASC NULLS LAST | | | Projection: text_search(qs, Utf8("what")).id, text_search(qs, Utf8("what"))._score | | | TableScan: text_search(qs, Utf8("what")) | | logical_plan after search_query_expand | Limit: skip=0, fetch=3 | | | Sort: text_search(qs, Utf8("what"))._score ASC NULLS LAST | | | Projection: text_search(qs, Utf8("what")).id, text_search(qs, Utf8("what"))._score | | | SearchTelemetry | | | Projection: search_index._score, base_table.answer, search_index.id, base_table.question, base_table.reference_answer, base_table.source, base_table.subject | | | Sort: search_index._score DESC NULLS FIRST | | | Projection: search_index.id, search_index._score, base_table.answer, base_table.question, base_table.reference_answer, base_table.source, base_table.subject | | | Left Join: search_index.id = base_table.id | | | SubqueryAlias: search_index | | | Limit: skip=0, fetch=None | | | SubqueryAlias: search_index | | | TableScan: full_text | | | Projection: base_table.answer, base_table.id, base_table.question, base_table.reference_answer, base_table.source, base_table.subject | | | TableScan: base_table projection=[answer, id, question, reference_answer, source, subject] |
Assistant
I'll examine the
SearchQueryAnalyzerRuleto understand the issue with column references after the table rewrite.Assistant
Looking at the error, the issue is clear: when the
SearchQueryAnalyzerRuleexpands theTableScaninto the full logical plan, parent operations (Sort, Projection) still reference the original table nametext_search(qs, Utf8("what")). But the expanded plan usessearch_indexandbase_tablealiases instead, causing a schema mismatch during optimization.The solution is to wrap the expanded plan with an alias matching the original table name. This way parent operations can still reference the original table name and resolve to the correct columns.
Let me check the current structure and fix it:
- User
[Request interrupted by user for tool use]
- User
We should alias it as
text_search(qs, Utf8("what"))so parent operations are none the wiser about the analyzer rewrite Assistant
Now let's verify the fix works with the test case. Let me check if there are existing tests or a way to reproduce the issue:
Assistant
There's a test failure in the existing test. Let me check what's happening:
Assistant
Perfect! All tests pass. Let me verify the changes:
Assistant
Excellent! The fix is complete. Let me summarize the changes:
Fix Summary
The
SearchQueryAnalyzerRulewas broken because when it expanded theTableScan(SearchQueryProvider)into a full logical plan withsearch_indexandbase_tablealiases, parent operations (Sort, Projection, etc.) still referenced the original table name liketext_search(qs, Utf8("what")), causing schema resolution failures during optimization.Solution
Wrapped the expanded plan with an alias matching the original table name (
scan.table_name), making the expansion transparent to parent operations. This allows:- Parent Sort/Projection operations to continue referencing the original table name
- DataFusion's optimizer to work with the full expanded plan without schema errors
- Seamless integration of the analyzer rule's expansion with the rest of the query pipeline
Changes Made
- analyzer_rule.rs:31 - Added
LogicalPlanBuilderimport - analyzer_rule.rs:74-79 - Added aliasing logic that wraps the expanded plan with the original table name
Assistant
Now let me commit the fix:
Assistant
Perfect! The fix has been committed. Here's what was done:
Problem
The
SearchQueryAnalyzerRulewas broken because it expandedTableScan(SearchQueryProvider)into a full logical plan withsearch_indexandbase_tablealiases, but parent operations (Sort, Projection, etc.) still referenced the original table nametext_search(qs, Utf8("what")), causing a schema resolution error during optimization.Solution
Wrapped the expanded plan with an alias matching the original table name so parent operations remain unaware of the internal expansion. This allows:
- Parent operations to continue referencing columns by the original table name
- Seamless integration with DataFusion's optimizer
- Transparent expansion from the perspective of the rest of the query
Changes
- crates/search/src/analyzer_rule.rs: Added table name aliasing logic and fixed test helper
- All 23 unit tests pass
The commit
57cdc0f17is now on yourjeadie/26-03-04/fts-partitionbranch.