siddharthteotia commented on a change in pull request #4535: Implement DISTINCT
clause
URL: https://github.com/apache/incubator-pinot/pull/4535#discussion_r327248213
##########
File path:
pinot-common/src/main/java/org/apache/pinot/pql/parsers/pql2/ast/FunctionCallAstNode.java
##########
@@ -75,22 +80,53 @@ public String getExpression() {
return _expression;
}
- public AggregationInfo buildAggregationInfo() {
+ AggregationInfo buildAggregationInfo() {
String expression;
// COUNT aggregation function always works on '*'
- if (_name.equalsIgnoreCase("count")) {
+ if (_name.equalsIgnoreCase(AggregationFunctionType.COUNT.getName())) {
expression = "*";
} else {
List<? extends AstNode> children = getChildren();
- if (children == null || children.size() != 1) {
- throw new Pql2CompilationException("Aggregation function expects exact
1 argument");
+ if (children == null || children.size() < 1) {
+ throw new Pql2CompilationException("Aggregation function expects
non-null argument");
+ }
+ if (!_name.equalsIgnoreCase(AggregationFunctionType.DISTINCT.getName()))
{
+ if (children.size() != 1) {
+ throw new Pql2CompilationException("Aggregation function expects
exactly 1 argument as column name");
+ } else {
+ expression =
TransformExpressionTree.getStandardExpression(children.get(0));
+ }
+ } else {
+ // DISTINCT
+ if (!Pql2Compiler.ENABLE_DISTINCT) {
+ throw new Pql2CompilationException("Support for DISTINCT is
currently disabled");
+ }
+ if (children.size() == 1) {
+ // single column DISTINCT query
+ // e.g SELECT DISTINCT(col) FROM foo
+ expression =
TransformExpressionTree.getStandardExpression(children.get(0));
+ } else {
+ // multi-column DISTINCT query
+ // e.g SELECT DISTINCT(col1, col2) FROM foo
+ // we will pass down the column expression to execution code
+ // as col1:col2
+ StringBuilder distinctColumnExpr = new StringBuilder();
+ int numChildren = children.size();
+ for (int i = 0; i < numChildren; ++i) {
+ expression =
TransformExpressionTree.getStandardExpression(children.get(i));
Review comment:
Done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]