Skip to content

Conversation

@nik9000
Copy link
Member

@nik9000 nik9000 commented Aug 5, 2025

This modifies the ESQL grammar to allow FIRST and LAST as identifiers. We're going to make functions called that.

Relates to #108385

This modifies the ESQL grammar to allow FIRST and LAST as identifiers.
We're going to make functions called that.

Relates to elastic#108385
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Aug 5, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@nik9000
Copy link
Member Author

nik9000 commented Aug 5, 2025

Another option is to make FIRST and LAST valid functions so we can do the FIRST(x BY @timestamp) syntax.

@nik9000
Copy link
Member Author

nik9000 commented Aug 5, 2025

The alternative is #132474

: UNQUOTED_IDENTIFIER
| QUOTED_IDENTIFIER
| FIRST
| LAST
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth restricting FIRST/LAST to only a function name opposed to any identifier? Although somebody might want to use | EVAL first=first(column, @timestamp). Not sure.

Copy link
Contributor

@alex-spies alex-spies left a comment

Choose a reason for hiding this comment

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

Hey, I think we're adding this bit of grammar in the wrong place, see my comment below.

Additionally, the PR description mentions the syntax FIRST(v BY @timestamp). Having BY inside the function is also new grammar. Do we need this, or could we start with just FIRST(v, @timestamp) and decide later if/how functions should be extended to use the BY keyword in their arguments?

@nik9000
Copy link
Member Author

nik9000 commented Aug 6, 2025

This one's ready for another look, @alex-spies and @idegtiarenko .

Copy link
Contributor

@alex-spies alex-spies left a comment

Choose a reason for hiding this comment

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

LGTM!

@nik9000 nik9000 enabled auto-merge (squash) August 6, 2025 12:18
@nik9000
Copy link
Member Author

nik9000 commented Aug 6, 2025

Thanks @alex-spies and @idegtiarenko .

}

private String functionName(EsqlBaseParser.FunctionNameContext ctx) {
TerminalNode first = ctx.LAST();
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this should be

Suggested change
TerminalNode first = ctx.LAST();
TerminalNode first = ctx.FIRST();

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah. #132503

@nik9000 nik9000 merged commit 7ec5b41 into elastic:main Aug 6, 2025
33 checks passed
nik9000 added a commit to nik9000/elasticsearch that referenced this pull request Aug 6, 2025
szybia added a commit to szybia/elasticsearch that referenced this pull request Aug 6, 2025
…cking

* upstream/main: (24 commits)
  Revert "[Fleet] add privileges to `kibana_system` to read integrations data (elastic#132400)" (elastic#132499)
  ESQL: Rename evaluators for FIRST and LAST (elastic#132466)
  Add inference fields to semantic text docs (elastic#132471)
  ESQL: Allow FIRST and LAST as method name (elastic#132469)
  ESQL: Add javadoc for PushDownAndCombineFilters (elastic#132484)
  Misc cleanups in Coordinator (elastic#132452)
  [DiskBBQ] Write the maximum posting list size to avoid resizing the docId array (elastic#132447)
  Improve exception handling for JsonXContentParser (elastic#123439)
  Clarify quantization on semantic_text BBQ dense vector default (elastic#132470)
  Fix test infra NPE in doEnsureClusterStateConsistency (elastic#131859)
  Stabilize CancellableTasksIT#testRemoveBanParentsOnDisconnect (elastic#131858)
  Move ClusterApplierService assertion after logging exception (elastic#132446)
  ESQL: Support for multi-argument aggs (elastic#132424)
  Update wolfi (versioned) (elastic#132457)
  ESQL: Fix Function javadoc (elastic#132399)
  [ML] Inference API disable partial search results (elastic#132362)
  Unmute testTermsQuery tests (elastic#132409)
  Fix index lookup when field-caps returns empty mapping (elastic#132138)
  CompressorFactory.compressor (elastic#132448)
  ESQL add formatting to plans in javadoc (elastic#132421)
  ...
nik9000 added a commit that referenced this pull request Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL >refactoring Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants