-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep aggregation in Calcite consistent with current PPL behavior
Signed-off-by: Lantao Jin <[email protected]>
- Loading branch information
Showing
38 changed files
with
1,489 additions
and
244 deletions.
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
13 changes: 13 additions & 0 deletions
13
core/src/main/java/org/opensearch/sql/ast/expression/CountedAggregation.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,13 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.ast.expression; | ||
|
||
import java.util.Optional; | ||
|
||
/** marker interface for numeric based count aggregation (specific number of returned results) */ | ||
public interface CountedAggregation { | ||
Optional<Literal> getResults(); | ||
} |
35 changes: 35 additions & 0 deletions
35
core/src/main/java/org/opensearch/sql/ast/expression/RareAggregation.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,35 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.ast.expression; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import org.opensearch.sql.ast.tree.Aggregation; | ||
|
||
/** | ||
* Logical plan node of Rare (Aggregation) command, the interface for building aggregation actions | ||
* in queries. | ||
*/ | ||
@ToString | ||
@Getter | ||
@EqualsAndHashCode(callSuper = true) | ||
public class RareAggregation extends Aggregation implements CountedAggregation { | ||
private final Optional<Literal> results; | ||
|
||
/** Aggregation Constructor without span and argument. */ | ||
public RareAggregation( | ||
Optional<Literal> results, | ||
List<UnresolvedExpression> aggExprList, | ||
List<UnresolvedExpression> sortExprList, | ||
List<UnresolvedExpression> groupExprList) { | ||
super(aggExprList, sortExprList, groupExprList, null, Collections.emptyList()); | ||
this.results = results; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
core/src/main/java/org/opensearch/sql/ast/expression/TopAggregation.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,35 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.ast.expression; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import org.opensearch.sql.ast.tree.Aggregation; | ||
|
||
/** | ||
* Logical plan node of Top (Aggregation) command, the interface for building aggregation actions in | ||
* queries. | ||
*/ | ||
@ToString | ||
@Getter | ||
@EqualsAndHashCode(callSuper = true) | ||
public class TopAggregation extends Aggregation implements CountedAggregation { | ||
private final Optional<Literal> results; | ||
|
||
/** Aggregation Constructor without span and argument. */ | ||
public TopAggregation( | ||
Optional<Literal> results, | ||
List<UnresolvedExpression> aggExprList, | ||
List<UnresolvedExpression> sortExprList, | ||
List<UnresolvedExpression> groupExprList) { | ||
super(aggExprList, sortExprList, groupExprList, null, Collections.emptyList()); | ||
this.results = results; | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
core/src/main/java/org/opensearch/sql/calcite/udf/LegacyPPLCountAggFunction.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,44 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.calcite.udf; | ||
|
||
import org.apache.calcite.rel.type.RelDataType; | ||
import org.apache.calcite.sql.SqlAggFunction; | ||
import org.apache.calcite.sql.SqlCall; | ||
import org.apache.calcite.sql.SqlFunctionCategory; | ||
import org.apache.calcite.sql.SqlKind; | ||
import org.apache.calcite.sql.type.OperandTypes; | ||
import org.apache.calcite.sql.type.ReturnTypes; | ||
import org.apache.calcite.sql.type.SqlTypeName; | ||
import org.apache.calcite.sql.validate.SqlValidator; | ||
import org.apache.calcite.sql.validate.SqlValidatorScope; | ||
import org.apache.calcite.util.Optionality; | ||
|
||
/** | ||
* This class is used to support the legacy COUNT(*) function. It extends SqlAggFunction and | ||
* overrides the deriveType method to return INTEGER type. | ||
*/ | ||
public class LegacyPPLCountAggFunction extends SqlAggFunction { | ||
|
||
public LegacyPPLCountAggFunction() { | ||
super( | ||
"COUNT", | ||
null, | ||
SqlKind.COUNT, | ||
ReturnTypes.INTEGER, // Change return type to INTEGER | ||
null, | ||
OperandTypes.ONE_OR_MORE, | ||
SqlFunctionCategory.NUMERIC, | ||
false, | ||
false, | ||
Optionality.FORBIDDEN); | ||
} | ||
|
||
@Override | ||
public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) { | ||
return validator.getTypeFactory().createSqlType(SqlTypeName.INTEGER); | ||
} | ||
} |
Oops, something went wrong.