-
Notifications
You must be signed in to change notification settings - Fork 181
Support bin command with Calcite
#3878
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
Changes from all commits
a141c22
36d3d2c
366ff5f
0426092
bfce28c
9a79063
6ef78c4
7d0e75b
47b6764
52f55dd
410c088
39525bd
a664bd2
ead4169
6e2d5ec
f5d60a3
727c9b2
be3b123
bcf5408
3c79545
7145101
2fae14c
367031a
1e00bc4
4e731b8
2cc7d36
6370d0c
a86cd6d
a55e93e
edfaf6f
7f2a874
71873b4
8478df3
e1824de
ff7447d
04bffcd
66e33a0
acc9d94
47bd4ad
fd8d488
4eced40
dd711e4
70ce83b
230696f
5a988cc
9c8f749
dba465b
b749400
44bd865
a2c040d
9d56ada
aebfb2d
b26379f
d6d036f
3815fc0
fc11a62
a936353
4db6506
f988430
26debf1
c0a1bba
f2c3401
0b2d843
c7bd21a
4d81ccd
350eaf4
c844af2
e3a765e
6f7ae56
598e84a
7baf3f1
f2232fb
cd3b499
679368c
183dbdc
4079fdf
5731736
b2fbe70
6f4c801
2291506
10dd000
71ee3d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * 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 javax.annotation.Nullable; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
| import lombok.ToString; | ||
| import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
| import org.opensearch.sql.ast.expression.UnresolvedExpression; | ||
|
|
||
| /** Abstract AST node representing Bin operations with type-safe derived classes. */ | ||
| @Getter | ||
| @Setter | ||
| @ToString | ||
| @EqualsAndHashCode(callSuper = false) | ||
| public abstract class Bin extends UnresolvedPlan { | ||
|
|
||
| private UnresolvedPlan child; | ||
|
|
||
| protected final UnresolvedExpression field; | ||
|
|
||
| @Nullable protected final String alias; | ||
|
Member
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. It's okey but I don't suggest to use
Contributor
Author
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. Updated to use
Collaborator
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. @LantaoJin Using optional as a field type will cause a warning, e.g.
Member
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. Thanks @yuancu. For now, there is no harmful to use |
||
|
|
||
| protected Bin(UnresolvedExpression field, @Nullable String alias) { | ||
| this.field = field; | ||
| this.alias = alias; | ||
| } | ||
|
|
||
| /** | ||
| * Validates the parameters specific to this bin type. Each subclass implements its own validation | ||
| * logic. | ||
| */ | ||
| public abstract void validate(); | ||
|
|
||
| @Override | ||
| public Bin attach(UnresolvedPlan child) { | ||
| this.child = child; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public List<UnresolvedPlan> getChild() { | ||
| return this.child == null ? ImmutableList.of() : ImmutableList.of(this.child); | ||
| } | ||
|
|
||
| @Override | ||
| public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) { | ||
| return nodeVisitor.visitBin(this, context); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.ast.tree; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import lombok.Builder; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.ToString; | ||
| import org.opensearch.sql.ast.expression.UnresolvedExpression; | ||
| import org.opensearch.sql.calcite.utils.binning.BinConstants; | ||
|
|
||
| /** | ||
| * AST node representing count-based bin operation. This is the third priority bin type that uses | ||
| * "nice number" algorithm to create a specific number of bins. Supports start/end range parameters. | ||
| */ | ||
| @Getter | ||
| @ToString(callSuper = true) | ||
| @EqualsAndHashCode(callSuper = true) | ||
| public class CountBin extends Bin { | ||
|
|
||
| private final Integer bins; | ||
|
|
||
| @Nullable private final UnresolvedExpression start; | ||
|
|
||
| @Nullable private final UnresolvedExpression end; | ||
|
|
||
| @Builder | ||
| public CountBin( | ||
| UnresolvedExpression field, | ||
| @Nullable String alias, | ||
| Integer bins, | ||
| @Nullable UnresolvedExpression start, | ||
| @Nullable UnresolvedExpression end) { | ||
| super(field, alias); | ||
| this.bins = bins; | ||
| this.start = start; | ||
| this.end = end; | ||
| validate(); | ||
| } | ||
|
|
||
| @Override | ||
| public void validate() { | ||
| // Bins count validation based on documentation | ||
| if (bins < BinConstants.MIN_BINS || bins > BinConstants.MAX_BINS) { | ||
| throw new IllegalArgumentException( | ||
| String.format( | ||
| "The bins parameter must be between %d and %d, got: %d", | ||
| BinConstants.MIN_BINS, BinConstants.MAX_BINS, bins)); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.ast.tree; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import lombok.Builder; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.ToString; | ||
| import org.opensearch.sql.ast.expression.UnresolvedExpression; | ||
|
|
||
| /** | ||
| * AST node representing default magnitude-based bin operation. This is the lowest priority bin type | ||
| * that uses automatic magnitude-based algorithm when no explicit binning parameters are specified. | ||
| */ | ||
| @Getter | ||
| @ToString(callSuper = true) | ||
| @EqualsAndHashCode(callSuper = true) | ||
| public class DefaultBin extends Bin { | ||
|
|
||
| @Builder | ||
| public DefaultBin(UnresolvedExpression field, @Nullable String alias) { | ||
| super(field, alias); | ||
| validate(); | ||
| } | ||
|
|
||
| @Override | ||
| public void validate() { | ||
| // Default bin has no additional parameters to validate | ||
| // Field validation is already handled in the base class | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.ast.tree; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import lombok.Builder; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.ToString; | ||
| import org.opensearch.sql.ast.expression.UnresolvedExpression; | ||
|
|
||
| /** | ||
| * AST node representing minimum span-based bin operation. This is the second priority bin type that | ||
| * uses magnitude-based algorithm with minimum span constraint. Supports start/end range parameters. | ||
| */ | ||
| @Getter | ||
| @ToString(callSuper = true) | ||
| @EqualsAndHashCode(callSuper = true) | ||
| public class MinSpanBin extends Bin { | ||
|
|
||
| private final UnresolvedExpression minspan; | ||
|
|
||
| @Nullable private final UnresolvedExpression start; | ||
|
|
||
| @Nullable private final UnresolvedExpression end; | ||
|
|
||
| @Builder | ||
| public MinSpanBin( | ||
| UnresolvedExpression field, | ||
| @Nullable String alias, | ||
| UnresolvedExpression minspan, | ||
| @Nullable UnresolvedExpression start, | ||
| @Nullable UnresolvedExpression end) { | ||
| super(field, alias); | ||
| this.minspan = minspan; | ||
| this.start = start; | ||
| this.end = end; | ||
| validate(); | ||
| } | ||
|
|
||
| @Override | ||
| public void validate() {} | ||
| } |
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.
I doubt whether changes to
AstDSL.javais necessary since you have marked bin command as only available when Calcite is enabled.AstDSL.javais mainly used to build expression AST for v2. (Please correct me if I am wrong)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 AST layer. We can keep this API.