-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[ES|QL] Substitute date_trunc with round_to when the pre-calculated rounding points are available #128639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fang-xing-esql
merged 25 commits into
elastic:main
from
fang-xing-esql:date-trunc-search-stats
Jul 15, 2025
Merged
[ES|QL] Substitute date_trunc with round_to when the pre-calculated rounding points are available #128639
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b677c8f
consolidate min/max in SearchStats and substitue date_trunc with roun…
fang-xing-esql 08c3d18
Update docs/changelog/128639.yaml
fang-xing-esql 3f96c15
Merge branch 'main' into date-trunc-search-stats
fang-xing-esql c3ffa8f
skip multi-typed fields with mixed date and date_nanos
fang-xing-esql f78fa18
Merge branch 'main' into date-trunc-search-stats
fang-xing-esql 88dbdf8
support bucket SubstituteSurrogateExpressionsWithSearchStats
fang-xing-esql 511faeb
Merge branch 'main' into date-trunc-search-stats
fang-xing-esql 3d28f88
Merge branch 'main' into date-trunc-search-stats
fang-xing-esql 3f1cd81
Merge branch 'main' into date-trunc-search-stats
fang-xing-esql e59ea5a
add tests for min/max in SearchContextStats, disallow substitution fo…
fang-xing-esql 2f1aef9
add tests for min/max in SearchContextStats, disallow substitution fo…
fang-xing-esql debd20e
Merge branch 'main' into date-trunc-search-stats
fang-xing-esql 5d6d9c9
Merge branch 'main' into date-trunc-search-stats
fang-xing-esql 5a152ab
Merge branch 'main' into date-trunc-search-stats
fang-xing-esql 7b669b8
fix test failures
fang-xing-esql 54567d4
safe guard prepare with min max
fang-xing-esql 3208b5f
Merge branch 'main' into date-trunc-search-stats
fang-xing-esql ee24a7e
Merge branch 'main' into date-trunc-search-stats
fang-xing-esql a76362f
Merge branch 'main' into date-trunc-search-stats
fang-xing-esql 57dfe15
add trace and clean up
fang-xing-esql d42ea8e
Merge branch 'main' into date-trunc-search-stats
fang-xing-esql 89039cd
Merge branch 'main' into date-trunc-search-stats
fang-xing-esql 1d453f3
Merge branch 'main' into date-trunc-search-stats
fang-xing-esql 4e82da7
refactor according to review comments
fang-xing-esql a2b80be
Merge branch 'main' into date-trunc-search-stats
fang-xing-esql File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| pr: 128639 | ||
| summary: Substitue `date_trunc` with `round_to` when the pre-calculated rounding points | ||
| are available | ||
| area: ES|QL | ||
| type: enhancement | ||
| issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
.../esql/src/main/java/org/elasticsearch/xpack/esql/expression/LocalSurrogateExpression.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.esql.expression; | ||
|
|
||
| import org.elasticsearch.xpack.esql.core.expression.Expression; | ||
| import org.elasticsearch.xpack.esql.stats.SearchStats; | ||
|
|
||
| /** | ||
| * Interface signaling to the local logical plan optimizer that the declaring expression | ||
| * has to be replaced by a different form. | ||
| * Implement this on {@code Function}s when: | ||
| * <ul> | ||
| * <li>The expression can be rewritten to another expression on data node, with the statistics available in SearchStats. | ||
| * Like {@code DateTrunc} and {@code Bucket} could be rewritten to {@code RoundTo} with the min/max values on the date field. | ||
| * </li> | ||
| * </ul> | ||
| */ | ||
| public interface LocalSurrogateExpression { | ||
| /** | ||
| * Returns the expression to be replaced by or {@code null} if this cannot be replaced. | ||
| */ | ||
| Expression surrogate(SearchStats searchStats); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
.../org/elasticsearch/xpack/esql/expression/function/scalar/date/BinaryDateTimeFunction.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,7 @@ | |
| public class DateDiff extends EsqlScalarFunction { | ||
| public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "DateDiff", DateDiff::new); | ||
|
|
||
| public static final ZoneId UTC = ZoneId.of("Z"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| public static final ZoneId UTC = org.elasticsearch.xpack.esql.core.util.DateUtils.UTC; | ||
|
|
||
| private final Expression unit; | ||
| private final Expression startTimestamp; | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.