-
Notifications
You must be signed in to change notification settings - Fork 141
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
Add trendline PPL command #3071
Merged
acarbonetto
merged 43 commits into
opensearch-project:main
from
Bit-Quill:ppl-trendline
Dec 12, 2024
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
494b0a2
WIP: Add trendline PPL command
jduo c6ec31f
fix missing newline
jduo 9a7b6a4
Optimize running average calculation and use DSL
jduo f39bef1
spotless
jduo 92657a1
Make implementation preserve child data
jduo 5732ac4
Implement logging and explain for trendline
jduo ec89a61
Use List#get(0) instead of getFirst() to support older compilers
jduo a25303d
Tell the project operator about new fields from trendline computations
jduo e8b0fe2
Add Trendline parser test
jduo f96a657
Spotless
jduo ed1670a
LogicalPlan testing
jduo cb4ea19
Physical plan tests
jduo fc3027e
Spotless
jduo a7354c5
Fix explain test failure
jduo 332f5e6
Add integration tests
jduo 289a74f
Add trendline documentation
jduo 1ec45f0
Make null handling consistent with normal aggregation
jduo bf03883
Make alias mandatory
jduo 94a2164
Remove weighted moving average stub
jduo 0c9dfb0
Add DefaultImplementor and PhysicalPlanNodeVisitor tests
jduo a5c455c
Propagate type information
jduo 4abbae7
Tweak math to evaluate lazily and reduce division
jduo db6a08a
Add support for moving averages on datetime types
jduo ce2d089
Add missing doc link
jduo 0e11421
Fix code coverage gaps
jduo 68ac7ad
Fix docs typo
jduo 048930c
Add missing OpenSearchExecutionProtectorTest
jduo 1dd720a
Include trendline in docs test
jduo 48a93e4
Fix typo drawing example table
jduo 4e2e2c0
Add explain integration test
jduo 54a8569
Fix trendline explain IT test
jduo aca31bd
Make the alias optional
jduo 50d590a
Add validation on number of data points
jduo 07c7efb
Add sort functionality to trendline
jduo b60093e
Make docs more consistent with Spark
jduo 25ccada
Fix docs typo in example
jduo c7b7cb1
Add missed update to AstBuilderTest for sort option
jduo 23917a5
Add test for checking an invalid number of samples
jduo b01dded
Add Trendline to KeywordsCanBeId
jduo 8da8255
Fix wrong column name in docs
jduo 9f1684f
Fix rebase error in parse
jduo 09bd6aa
Merge branch 'main' into ppl-trendline
acarbonetto 0ff1653
PPL-Trendline: remove unused grammar; clean doc
acarbonetto 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 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 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 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
71 changes: 71 additions & 0 deletions
71
core/src/main/java/org/opensearch/sql/ast/tree/Trendline.java
This file contains 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,71 @@ | ||
/* | ||
* 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 java.util.Optional; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.ToString; | ||
import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
import org.opensearch.sql.ast.Node; | ||
import org.opensearch.sql.ast.expression.Field; | ||
import org.opensearch.sql.ast.expression.UnresolvedExpression; | ||
|
||
@ToString | ||
@Getter | ||
@RequiredArgsConstructor | ||
@EqualsAndHashCode(callSuper = false) | ||
public class Trendline extends UnresolvedPlan { | ||
|
||
private UnresolvedPlan child; | ||
private final Optional<Field> sortByField; | ||
private final List<TrendlineComputation> computations; | ||
|
||
@Override | ||
public Trendline attach(UnresolvedPlan child) { | ||
this.child = child; | ||
return this; | ||
} | ||
|
||
@Override | ||
public List<? extends Node> getChild() { | ||
return ImmutableList.of(child); | ||
} | ||
|
||
@Override | ||
public <T, C> T accept(AbstractNodeVisitor<T, C> visitor, C context) { | ||
return visitor.visitTrendline(this, context); | ||
} | ||
|
||
@Getter | ||
public static class TrendlineComputation extends UnresolvedExpression { | ||
|
||
private final Integer numberOfDataPoints; | ||
private final Field dataField; | ||
private final String alias; | ||
private final TrendlineType computationType; | ||
|
||
public TrendlineComputation( | ||
Integer numberOfDataPoints, Field dataField, String alias, TrendlineType computationType) { | ||
this.numberOfDataPoints = numberOfDataPoints; | ||
this.dataField = dataField; | ||
this.alias = alias; | ||
this.computationType = computationType; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(AbstractNodeVisitor<R, C> nodeVisitor, C context) { | ||
return nodeVisitor.visitTrendlineComputation(this, context); | ||
} | ||
} | ||
|
||
public enum TrendlineType { | ||
SMA | ||
} | ||
} |
This file contains 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 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 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 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.
Should we have this into 2 different files?
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.
This is pulled from the corresponding Spark PR opensearch-spark/#748 though this file has changed in that PR too. I think it makes sense as an inner class here as it is Trendline-specific, though it does get used by both LogicalTrendline and TrendlineOperator.
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 just compared list of classes with other features we added in past. I don't have a preference there.