generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 181
Support eventstats command with Calcite
#3585
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c017a1c
Support eventstats command with Calcite
LantaoJin 6a59baf
add doc
LantaoJin 23c7dfa
fix IT
LantaoJin 85127d8
address comments
LantaoJin 5a4c3cc
Merge remote-tracking branch 'upstream/main' into pr/issues/3563
LantaoJin 13d5b0c
Fix conflicts
LantaoJin 65acffc
address comments
LantaoJin f54cf56
Support variance functions
LantaoJin 843835b
fix UT
LantaoJin 44f2455
update doc
LantaoJin 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
60 changes: 60 additions & 0 deletions
60
core/src/main/java/org/opensearch/sql/ast/expression/WindowBound.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,60 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.ast.expression; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| public abstract class WindowBound { | ||
| private WindowBound() {} | ||
|
|
||
| @Getter | ||
| public static class OffSetWindowBound extends WindowBound { | ||
| private final long offset; | ||
| private final boolean isPreceding; | ||
|
|
||
| OffSetWindowBound(long offset, boolean isPreceding) { | ||
| this.offset = offset; | ||
| this.isPreceding = isPreceding; | ||
| } | ||
|
|
||
| public boolean isPreceding() { | ||
| return isPreceding; | ||
| } | ||
| } | ||
|
|
||
| public static class CurrentRowWindowBound extends WindowBound { | ||
| CurrentRowWindowBound() {} | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "CURRENT ROW"; | ||
| } | ||
| } | ||
|
|
||
| public static class UnboundedWindowBound extends WindowBound { | ||
| private final boolean isPreceding; | ||
|
|
||
| UnboundedWindowBound(boolean isPreceding) { | ||
| this.isPreceding = isPreceding; | ||
| } | ||
|
|
||
| public boolean isPreceding() { | ||
| return isPreceding; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| return this == o | ||
| || o instanceof UnboundedWindowBound | ||
| && isPreceding == ((UnboundedWindowBound) o).isPreceding; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return isPreceding ? "UNBOUNDED PRECEDING" : "UNBOUNDED FOLLOWING"; | ||
| } | ||
| } | ||
| } |
73 changes: 73 additions & 0 deletions
73
core/src/main/java/org/opensearch/sql/ast/expression/WindowFrame.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,73 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.ast.expression; | ||
|
|
||
| import java.util.Locale; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.ToString; | ||
|
|
||
| @EqualsAndHashCode(callSuper = false) | ||
| @Getter | ||
| @RequiredArgsConstructor | ||
| @ToString | ||
| public class WindowFrame extends UnresolvedExpression { | ||
| private final FrameType type; | ||
| private final WindowBound lower; | ||
| private final WindowBound upper; | ||
|
|
||
| public enum FrameType { | ||
| RANGE, | ||
| ROWS | ||
| } | ||
|
|
||
| public static WindowFrame defaultFrame() { | ||
| return new WindowFrame( | ||
| FrameType.ROWS, createBound("UNBOUNDED PRECEDING"), createBound("UNBOUNDED FOLLOWING")); | ||
| } | ||
|
|
||
| public static WindowFrame create(FrameType type, Literal lower, Literal upper) { | ||
| WindowBound lowerBound = null; | ||
| WindowBound upperBound = null; | ||
| if (lower != null) { | ||
| if (lower.getType() == DataType.STRING) { | ||
| lowerBound = createBound(lower.getValue().toString()); | ||
| } else { | ||
| throw new IllegalArgumentException( | ||
| String.format("Unsupported bound type: %s", lower.getType())); | ||
| } | ||
| } | ||
| if (upper != null) { | ||
| if (upper.getType() == DataType.STRING) { | ||
| upperBound = createBound(upper.getValue().toString()); | ||
| } else { | ||
| throw new IllegalArgumentException( | ||
| String.format("Unsupported bound type: %s", upper.getType())); | ||
| } | ||
| } | ||
| return new WindowFrame(type, lowerBound, upperBound); | ||
| } | ||
|
|
||
| private static WindowBound createBound(String boundType) { | ||
| boundType = boundType.trim().toUpperCase(Locale.ROOT); | ||
| if ("CURRENT ROW".equals(boundType)) { | ||
| return new WindowBound.CurrentRowWindowBound(); | ||
| } else if ("UNBOUNDED PRECEDING".equals(boundType)) { | ||
| return new WindowBound.UnboundedWindowBound(true); | ||
| } else if ("UNBOUNDED FOLLOWING".equals(boundType)) { | ||
| return new WindowBound.UnboundedWindowBound(false); | ||
| } else if (boundType.endsWith(" PRECEDING")) { | ||
| long number = Long.parseLong(boundType.split(" PRECEDING")[0]); | ||
| return new WindowBound.OffSetWindowBound(number, true); | ||
| } else if (boundType.endsWith(" FOLLOWING")) { | ||
| long number = Long.parseLong(boundType.split(" FOLLOWING")[0]); | ||
| return new WindowBound.OffSetWindowBound(number, false); | ||
| } else { | ||
| throw new IllegalArgumentException(String.format("Unsupported bound type: %s", boundType)); | ||
| } | ||
| } | ||
| } |
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
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
41 changes: 41 additions & 0 deletions
41
core/src/main/java/org/opensearch/sql/ast/tree/Window.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,41 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.ast.tree; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import java.util.List; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.ToString; | ||
| import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
| import org.opensearch.sql.ast.expression.UnresolvedExpression; | ||
|
|
||
| @Getter | ||
| @ToString | ||
| @EqualsAndHashCode(callSuper = false) | ||
| @RequiredArgsConstructor | ||
| public class Window extends UnresolvedPlan { | ||
|
|
||
| private final List<UnresolvedExpression> windowFunctionList; | ||
| private UnresolvedPlan child; | ||
|
|
||
| @Override | ||
| public Window attach(UnresolvedPlan child) { | ||
| this.child = child; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public List<UnresolvedPlan> getChild() { | ||
| return ImmutableList.of(this.child); | ||
| } | ||
|
|
||
| @Override | ||
| public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) { | ||
| return nodeVisitor.visitWindow(this, context); | ||
| } | ||
| } | ||
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to add window boundary? For example, I want to execute a ppl equal to a sql like
select AVG(SUM(total_amount)) OVER (ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS moving_avg_3day(this is one of themoving avg, which we plan to support for t2visbuilder).Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's easy to support it. but not this PR of
eventstatscommand. We can extend this syntax after PPL lang unified. e.g support boundary when we implementstreamstatscommand.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a
WindowFramefor further using.