Skip to content

ESQL: evaluate ReferenceAttributes to potentially FieldAttributes for full-text functions restriction#143893

Merged
elasticsearchmachine merged 6 commits intoelastic:mainfrom
astefan:143859_fix
Mar 10, 2026
Merged

ESQL: evaluate ReferenceAttributes to potentially FieldAttributes for full-text functions restriction#143893
elasticsearchmachine merged 6 commits intoelastic:mainfrom
astefan:143859_fix

Conversation

@astefan
Copy link
Copy Markdown
Contributor

@astefan astefan commented Mar 9, 2026

Fixes #143859

@astefan astefan requested a review from carlosdelest March 9, 2026 17:56
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Mar 9, 2026
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Hi @astefan, I've created a changelog YAML for you.

Copy link
Copy Markdown
Member

@carlosdelest carlosdelest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @astefan ! Very thorough testing 💯

I have a question regarding field resolution on query translation

issues:
- 143859
pr: 143893
summary: Evaluate `ReferenceAttributes` to potentially `FieldAttributes` for full-text
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
summary: Evaluate `ReferenceAttributes` to potentially `FieldAttributes` for full-text
summary: Identify correctly a renamed attribute in full text functions as a field attribute

* Resolves the given field expression to a {@link FieldAttribute} by following rename alias chains
* through {@link Project} nodes in the plan.
*/
private FieldAttribute resolveToFieldAttribute(LogicalPlan plan, Expression field) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we replace fieldAsFieldAttribute for this method instead? We're still using fieldAsFieldAttribute for the query generation - I wonder why we don't need the same field resolution code there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The query generation path doesn't need this because PushDownAndCombineFilters.pushDownPastProject (via resolveRenamesFromProject) already resolves the ReferenceAttribute back to the original FieldAttribute when pushing the filter below the Project.

The same applies to postOptimizationPlanVerification: by that point renames are already resolved. The resolveToFieldAttribute traversal is only truly needed in postAnalysisPlanVerification, where the filter is still above the Project and the field is still a ReferenceAttribute.
But I chose to keep it like this (checked in both places - post analysis and post optimization) because the optimizer runs unnecessarily on queries that should be rejected immediately. For example, FROM idx | EVAL x = 1 | WHERE match(x, "foo") would go through all optimization rules before the user sees the error. Also, I hope that resolveToFieldAttribute is cost-effective enough (single traversal with early exit) to not impact the execution flow too much.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining!

From my PoV, I'd prefer a unified way of identifying this even though we run through the optimization before we fail - we would avoid having separate code paths for having essentially the same outcome. From what you say, we could use the same code we had on a PostOptimizationPlanVerificationAware.

I trust your judgement on this of course 👍

@astefan astefan added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Mar 10, 2026
@elasticsearchmachine elasticsearchmachine merged commit b5532b6 into elastic:main Mar 10, 2026
36 checks passed
@astefan astefan deleted the 143859_fix branch March 10, 2026 11:47
szybia added a commit to szybia/elasticsearch that referenced this pull request Mar 10, 2026
…locations

* upstream/main: (126 commits)
  Update KnnIndexTester to use more settings from datasets (elastic#143869)
  fix: dynamic template vector array is overridden by automatic dense_vector mapping (elastic#143733)
  ES|QL: Don't reuse the same alias for _fork column (elastic#143909)
  Close and initialize clients after each node upgrade in logsdb rolling upgrade tests. (elastic#143823)
  ESQL: Added GroupedTopNOperator for LIMIT BY, compute only (elastic#143476)
  Handle views in ResolveIndexAction (elastic#143561)
  Improve reindex rethrottle API in stateless (elastic#143771)
  Use a copy of the SearchExecutionContext for each Percolator execution (elastic#142765)
  Log the stacktrace when we encounter a deprecation warning for `default_metric` (elastic#143929)
  ESQL: evaluate ReferenceAttributes to potentially FieldAttributes for full-text functions restriction (elastic#143893)
  Add ClusterStateSerializationStats Serializatation Tests (elastic#142703)
  Adds Coordination Diagnostics Tests (elastic#142709)
  Upgrade Elasticsearch to Apache Lucene 10.4 (elastic#141882)
  ESQL: Add configurable bracket-based multi-value support for CSV reader (elastic#143890)
  time series es819 binary dv use up to a 1mb block size (elastic#143049)
  Dynamically enable / disable plugins in correspondence to stateless mode. (elastic#142147)
  ES|QL: Implement first/last_over_time for tdigest (elastic#143832)
  Document CHANGE_POINT limitation (elastic#143877)
  Fix OperationsOnSeqNoDisabledIndicesIT (elastic#143892)
  [Test] Test that sequence numbers are not pruned with retention lease (elastic#143825)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ESQL: full-text function not considering a RENAMEd valid searchable field

3 participants