Skip to content

Conversation

@limotova
Copy link
Contributor

@limotova limotova commented Nov 7, 2025

This commit adds a check after translating STATS run with the TS command that the @timestamp field still exists for commands that require it (TimestampAware functions and functions that bucket on it) and errors if it is missing.

Resolves #137655

@limotova limotova changed the title [ES|QL] TS Disallow renaming timestamp prior to implicit use [ES|QL] TS Disallow renaming into timestamp prior to implicit use Nov 7, 2025
@limotova limotova force-pushed the disallow-renaming-timestamp branch from 703e816 to 446cffd Compare November 11, 2025 04:23
@limotova limotova marked this pull request as ready for review November 11, 2025 21:11
@elasticsearchmachine elasticsearchmachine added the needs:triage Requires assignment of a team area label label Nov 11, 2025
@limotova limotova added >bug :StorageEngine/ES|QL Timeseries / metrics / logsdb capabilities in ES|QL and removed needs:triage Requires assignment of a team area label labels Nov 11, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

@elasticsearchmachine
Copy link
Collaborator

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

@limotova limotova requested a review from bpintea November 11, 2025 21:33
@Override
public String toString() {
return "rate(" + field() + ")";
return "rate(" + field() + ", " + timestamp() + ")";
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this added? Is it necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It wasn't necessary but @bpintea recommended it in our conversation and I agreed it made sense to add

Copy link
Contributor

Choose a reason for hiding this comment

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

@dnhatn wdyt?

If we want this, we'll have to update all time-series aggregate functions.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about the benefits of adding this, but I'm not against it either

Copy link
Contributor

Choose a reason for hiding this comment

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

not sure about the benefits of adding this

When seeing the failed query (in the issue this addresses), I wanted to quickly see what's happening in a running instance with debug on I hand running, but failed, because @timestamp isn't "visible". Since it's a parameter of the function, even if implicit, I think it can help. It's a nice to have though, not a strict necessity. And can be done here or some other PR.

Copy link
Member

@dnhatn dnhatn left a comment

Choose a reason for hiding this comment

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

I've left a question, thanks Larisa!

}
}
}
if (aggregate.child().output().contains(timestamp.get()) == false) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should run this check in TimeSeriesAggregate#postAnalysisVerification instead. What about TBucket? It seems we aren't checking it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh you're right; TBucket is a TimestampAware function so I thought it would be getting caught there but it doesn't end up in the list of timeSeriesAggs so it's getting skipped over. I'll see what I can do about both of those

Copy link
Contributor Author

@limotova limotova Nov 13, 2025

Choose a reason for hiding this comment

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

I rewrote it (edit: or so i thought; it didnt actually work) to be checked in TimeSeriesAggregate#postAnalysisVerification but it looks like something else actually catches the TBucket case already

      stack_trace: "org.elasticsearch.xpack.esql.VerificationException: Found 1 problem\n\
        line 3:68: [tbucket(5minute)] requires the [@timestamp] field, which was either\
        \ not present in the source index, or has been dropped or renamed

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, all the TimestampAware functions that are created by the Analyzer will have the UnresolvedTimestamp injected and if during reference resolution this isn't swapped out, it'll get caught into the Verifier.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I guess we're doing this to prevent @timestamp be altered at all, right? Like maybe shifted with a TZ delta.
If so, maybe we'll want to add a test for it to testTranslateMetricsAfterRenamingTimestamp(), like ... | EVAL @timestamp = @timestamp + 1 day

@Override
public String toString() {
return "rate(" + field() + ")";
return "rate(" + field() + ", " + timestamp() + ")";
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about the benefits of adding this, but I'm not against it either

Copy link
Contributor

@bpintea bpintea left a comment

Choose a reason for hiding this comment

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

Lgtm

}
}
}
if (aggregate.child().output().contains(timestamp.get()) == false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, all the TimestampAware functions that are created by the Analyzer will have the UnresolvedTimestamp injected and if during reference resolution this isn't swapped out, it'll get caught into the Verifier.

+ "["
+ String.join(", ", timestampAwareFunctions.subList(0, Math.min(size, 3)))
+ (size > 3 ? ", ..." : "")
+ "] requires a @timestamp field of type date to be present when run with the TS command, but it was not present."
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll probably want to do the plural dance with the require/s too.
Also, can @timestamp be of nanos resolution, or just date?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah @timestamp can be nanos. I'll change the phrase a bit and look into adding tests for that in a bit (we don't have an index with a date_nanos timestamp that's set up as a time series index in the CSV tests)

}
}
}
if (aggregate.child().output().contains(timestamp.get()) == false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I guess we're doing this to prevent @timestamp be altered at all, right? Like maybe shifted with a TZ delta.
If so, maybe we'll want to add a test for it to testTranslateMetricsAfterRenamingTimestamp(), like ... | EVAL @timestamp = @timestamp + 1 day

@Override
public String toString() {
return "rate(" + field() + ")";
return "rate(" + field() + ", " + timestamp() + ")";
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure about the benefits of adding this

When seeing the failed query (in the issue this addresses), I wanted to quickly see what's happening in a running instance with debug on I hand running, but failed, because @timestamp isn't "visible". Since it's a parameter of the function, even if implicit, I think it can help. It's a nice to have though, not a strict necessity. And can be done here or some other PR.

@limotova limotova merged commit 3cc97b9 into elastic:main Nov 14, 2025
34 checks passed
@limotova limotova deleted the disallow-renaming-timestamp branch November 14, 2025 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :StorageEngine/ES|QL Timeseries / metrics / logsdb capabilities in ES|QL Team:StorageEngine v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CI] GenerativeMetricsIT test failing

5 participants