[GitHub] [incubator-druid] jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs
jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs URL: https://github.com/apache/incubator-druid/pull/8487#discussion_r336286772 ## File path: sql/src/main/java/org/apache/druid/sql/calcite/expression/PostAggregatorVisitor.java ## @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.sql.calcite.expression; + +import org.apache.druid.query.aggregation.PostAggregator; + +import java.util.ArrayList; +import java.util.List; + +/** + * This class serves as a tracking structure for managing post aggregator column names and any post aggs that + * are created as part of translation of a Calcite {@code RexNode} into native Druid structures. + */ +public class PostAggregatorVisitor +{ + private String outputNamePrefix; + private int counter = 0; + private List postAggs = new ArrayList<>(); + + public PostAggregatorVisitor( + String outputNamePrefix + ) + { +this.outputNamePrefix = outputNamePrefix; + } + + public int getAndIncrementCounter() + { +int oldVal = counter; +counter++; +return oldVal; + } + + public int getCounter() Review comment: Removed 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org
[GitHub] [incubator-druid] jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs
jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs URL: https://github.com/apache/incubator-druid/pull/8487#discussion_r336286795 ## File path: sql/src/main/java/org/apache/druid/sql/calcite/expression/PostAggregatorVisitor.java ## @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.sql.calcite.expression; + +import org.apache.druid.query.aggregation.PostAggregator; + +import java.util.ArrayList; +import java.util.List; + +/** + * This class serves as a tracking structure for managing post aggregator column names and any post aggs that + * are created as part of translation of a Calcite {@code RexNode} into native Druid structures. + */ +public class PostAggregatorVisitor +{ + private String outputNamePrefix; + private int counter = 0; + private List postAggs = new ArrayList<>(); + + public PostAggregatorVisitor( + String outputNamePrefix + ) + { +this.outputNamePrefix = outputNamePrefix; + } + + public int getAndIncrementCounter() + { +int oldVal = counter; +counter++; +return oldVal; Review comment: Changed to suggested 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org
[GitHub] [incubator-druid] jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs
jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs URL: https://github.com/apache/incubator-druid/pull/8487#discussion_r336286755 ## File path: extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchSetUnionOperatorConversion.java ## @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.query.aggregation.datasketches.hll.sql; + +import org.apache.calcite.rex.RexCall; +import org.apache.calcite.rex.RexLiteral; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.sql.SqlFunction; +import org.apache.calcite.sql.SqlFunctionCategory; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.type.OperandTypes; +import org.apache.calcite.sql.type.ReturnTypes; +import org.apache.calcite.sql.type.SqlOperandCountRanges; +import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.query.aggregation.PostAggregator; +import org.apache.druid.query.aggregation.datasketches.hll.HllSketchUnionPostAggregator; +import org.apache.druid.sql.calcite.expression.DruidExpression; +import org.apache.druid.sql.calcite.expression.OperatorConversions; +import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; +import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; +import org.apache.druid.sql.calcite.planner.Calcites; +import org.apache.druid.sql.calcite.planner.PlannerContext; +import org.apache.druid.sql.calcite.table.RowSignature; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; + +public class HllSketchSetUnionOperatorConversion implements SqlOperatorConversion +{ + private static final SqlFunction SQL_FUNCTION = new SqlFunction( + "HLL_SKETCH_UNION", + SqlKind.OTHER_FUNCTION, + ReturnTypes.explicit( + factory -> Calcites.createSqlType(factory, SqlTypeName.OTHER) + ), + null, + OperandTypes.variadic(SqlOperandCountRanges.from(2)), + SqlFunctionCategory.USER_DEFINED_FUNCTION + ); + + public HllSketchSetUnionOperatorConversion() Review comment: Removed 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org
[GitHub] [incubator-druid] jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs
jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs URL: https://github.com/apache/incubator-druid/pull/8487#discussion_r335718988 ## File path: extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchSetBaseOperatorConversion.java ## @@ -0,0 +1,140 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.query.aggregation.datasketches.theta.sql; + +import org.apache.calcite.rex.RexCall; +import org.apache.calcite.rex.RexLiteral; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.sql.SqlFunction; +import org.apache.calcite.sql.SqlFunctionCategory; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.type.OperandTypes; +import org.apache.calcite.sql.type.ReturnTypes; +import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.query.aggregation.PostAggregator; +import org.apache.druid.query.aggregation.datasketches.theta.SketchSetPostAggregator; +import org.apache.druid.sql.calcite.expression.DruidExpression; +import org.apache.druid.sql.calcite.expression.OperatorConversions; +import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; +import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; +import org.apache.druid.sql.calcite.planner.Calcites; +import org.apache.druid.sql.calcite.planner.PlannerContext; +import org.apache.druid.sql.calcite.table.RowSignature; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; + +public abstract class ThetaSketchSetBaseOperatorConversion implements SqlOperatorConversion +{ + public ThetaSketchSetBaseOperatorConversion() + { + } + + @Override + public SqlOperator calciteOperator() + { +return makeSqlFunction(); + } + + @Nullable + @Override + public DruidExpression toDruidExpression( + PlannerContext plannerContext, + RowSignature rowSignature, + RexNode rexNode + ) + { +return null; + } + + @Nullable + @Override + public PostAggregator toPostAggregator( + PlannerContext plannerContext, + RowSignature rowSignature, + RexNode rexNode, + PostAggregatorVisitor postAggregatorVisitor + ) + { +final List operands = ((RexCall) rexNode).getOperands(); +final List inputPostAggs = new ArrayList<>(); +Integer size = null; + +int operandCounter = 0; +for (RexNode operand : operands) { + final PostAggregator convertedPostAgg = OperatorConversions.toPostAggregator( + plannerContext, + rowSignature, + operand, + postAggregatorVisitor + ); + if (convertedPostAgg == null) { +if (operandCounter == 0) { + try { +size = RexLiteral.intValue(operand); + } + catch (RuntimeException re) { +return null; + } +} else { + return null; +} + } else { +inputPostAggs.add(convertedPostAgg); +operandCounter++; + } +} + +return new SketchSetPostAggregator( +postAggregatorVisitor.getOutputNamePrefix() + postAggregatorVisitor.getAndIncrementCounter(), +getSetOperationName(), +size, +inputPostAggs +); + } + + private SqlFunction makeSqlFunction() + { +return new SqlFunction( +getFunctionName(), +SqlKind.OTHER_FUNCTION, +ReturnTypes.explicit( +factory -> Calcites.createSqlType(factory, SqlTypeName.OTHER) +), +null, +OperandTypes.VARIADIC, +SqlFunctionCategory.USER_DEFINED_FUNCTION +); + } + + public String getSetOperationName() + { +throw new UnsupportedOperationException("getSetOperationName() is not implemented."); Review comment: Changed this to abstract method 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
[GitHub] [incubator-druid] jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs
jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs URL: https://github.com/apache/incubator-druid/pull/8487#discussion_r335718831 ## File path: extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchSetUnionOperatorConversion.java ## @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.query.aggregation.datasketches.hll.sql; + +import org.apache.calcite.rex.RexCall; +import org.apache.calcite.rex.RexLiteral; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.sql.SqlFunction; +import org.apache.calcite.sql.SqlFunctionCategory; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.type.OperandTypes; +import org.apache.calcite.sql.type.ReturnTypes; +import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.query.aggregation.PostAggregator; +import org.apache.druid.query.aggregation.datasketches.hll.HllSketchUnionPostAggregator; +import org.apache.druid.sql.calcite.expression.DruidExpression; +import org.apache.druid.sql.calcite.expression.OperatorConversions; +import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; +import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; +import org.apache.druid.sql.calcite.planner.Calcites; +import org.apache.druid.sql.calcite.planner.PlannerContext; +import org.apache.druid.sql.calcite.table.RowSignature; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; + +public class HllSketchSetUnionOperatorConversion implements SqlOperatorConversion +{ + private static final SqlFunction SQL_FUNCTION = new SqlFunction( + "HLL_SKETCH_UNION", + SqlKind.OTHER_FUNCTION, + ReturnTypes.explicit( + factory -> Calcites.createSqlType(factory, SqlTypeName.OTHER) + ), + null, + OperandTypes.VARIADIC, + SqlFunctionCategory.USER_DEFINED_FUNCTION + ); + + public HllSketchSetUnionOperatorConversion() + { + } + + @Override + public SqlOperator calciteOperator() + { +return SQL_FUNCTION; + } + + @Nullable + @Override + public DruidExpression toDruidExpression( + PlannerContext plannerContext, + RowSignature rowSignature, + RexNode rexNode + ) + { +return null; + } + + @Nullable + @Override + public PostAggregator toPostAggregator( + PlannerContext plannerContext, + RowSignature rowSignature, + RexNode rexNode, + PostAggregatorVisitor postAggregatorVisitor + ) + { +final List operands = ((RexCall) rexNode).getOperands(); +final List inputPostAggs = new ArrayList<>(); +Integer lgK = null; +String tgtHllType = null; + +int operandCounter = 0; +for (RexNode operand : operands) { + final PostAggregator convertedPostAgg = OperatorConversions.toPostAggregator( + plannerContext, + rowSignature, + operand, + postAggregatorVisitor + ); + if (convertedPostAgg == null) { +if (operandCounter == 0) { + try { +lgK = RexLiteral.intValue(operand); + } + catch (RuntimeException re) { Review comment: Narrowed this to `ClassCastException` here and elsewhere 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org
[GitHub] [incubator-druid] jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs
jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs URL: https://github.com/apache/incubator-druid/pull/8487#discussion_r335718915 ## File path: extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchSetBaseOperatorConversion.java ## @@ -0,0 +1,140 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.query.aggregation.datasketches.theta.sql; + +import org.apache.calcite.rex.RexCall; +import org.apache.calcite.rex.RexLiteral; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.sql.SqlFunction; +import org.apache.calcite.sql.SqlFunctionCategory; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.type.OperandTypes; +import org.apache.calcite.sql.type.ReturnTypes; +import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.query.aggregation.PostAggregator; +import org.apache.druid.query.aggregation.datasketches.theta.SketchSetPostAggregator; +import org.apache.druid.sql.calcite.expression.DruidExpression; +import org.apache.druid.sql.calcite.expression.OperatorConversions; +import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; +import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; +import org.apache.druid.sql.calcite.planner.Calcites; +import org.apache.druid.sql.calcite.planner.PlannerContext; +import org.apache.druid.sql.calcite.table.RowSignature; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; + +public abstract class ThetaSketchSetBaseOperatorConversion implements SqlOperatorConversion +{ + public ThetaSketchSetBaseOperatorConversion() + { + } + + @Override + public SqlOperator calciteOperator() + { +return makeSqlFunction(); + } + + @Nullable + @Override + public DruidExpression toDruidExpression( + PlannerContext plannerContext, + RowSignature rowSignature, + RexNode rexNode + ) + { +return null; + } + + @Nullable + @Override + public PostAggregator toPostAggregator( + PlannerContext plannerContext, + RowSignature rowSignature, + RexNode rexNode, + PostAggregatorVisitor postAggregatorVisitor + ) + { +final List operands = ((RexCall) rexNode).getOperands(); +final List inputPostAggs = new ArrayList<>(); +Integer size = null; + +int operandCounter = 0; +for (RexNode operand : operands) { + final PostAggregator convertedPostAgg = OperatorConversions.toPostAggregator( + plannerContext, + rowSignature, + operand, + postAggregatorVisitor + ); + if (convertedPostAgg == null) { +if (operandCounter == 0) { + try { +size = RexLiteral.intValue(operand); Review comment: Fixed 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org
[GitHub] [incubator-druid] jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs
jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs URL: https://github.com/apache/incubator-druid/pull/8487#discussion_r335718720 ## File path: extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchSetUnionOperatorConversion.java ## @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.query.aggregation.datasketches.hll.sql; + +import org.apache.calcite.rex.RexCall; +import org.apache.calcite.rex.RexLiteral; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.sql.SqlFunction; +import org.apache.calcite.sql.SqlFunctionCategory; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.type.OperandTypes; +import org.apache.calcite.sql.type.ReturnTypes; +import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.query.aggregation.PostAggregator; +import org.apache.druid.query.aggregation.datasketches.hll.HllSketchUnionPostAggregator; +import org.apache.druid.sql.calcite.expression.DruidExpression; +import org.apache.druid.sql.calcite.expression.OperatorConversions; +import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; +import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; +import org.apache.druid.sql.calcite.planner.Calcites; +import org.apache.druid.sql.calcite.planner.PlannerContext; +import org.apache.druid.sql.calcite.table.RowSignature; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; + +public class HllSketchSetUnionOperatorConversion implements SqlOperatorConversion +{ + private static final SqlFunction SQL_FUNCTION = new SqlFunction( + "HLL_SKETCH_UNION", + SqlKind.OTHER_FUNCTION, + ReturnTypes.explicit( + factory -> Calcites.createSqlType(factory, SqlTypeName.OTHER) + ), + null, + OperandTypes.VARIADIC, + SqlFunctionCategory.USER_DEFINED_FUNCTION + ); + + public HllSketchSetUnionOperatorConversion() + { + } + + @Override + public SqlOperator calciteOperator() + { +return SQL_FUNCTION; + } + + @Nullable + @Override + public DruidExpression toDruidExpression( + PlannerContext plannerContext, + RowSignature rowSignature, + RexNode rexNode + ) + { +return null; + } + + @Nullable + @Override + public PostAggregator toPostAggregator( + PlannerContext plannerContext, + RowSignature rowSignature, + RexNode rexNode, + PostAggregatorVisitor postAggregatorVisitor + ) + { +final List operands = ((RexCall) rexNode).getOperands(); +final List inputPostAggs = new ArrayList<>(); +Integer lgK = null; +String tgtHllType = null; + +int operandCounter = 0; +for (RexNode operand : operands) { + final PostAggregator convertedPostAgg = OperatorConversions.toPostAggregator( + plannerContext, + rowSignature, + operand, + postAggregatorVisitor + ); + if (convertedPostAgg == null) { +if (operandCounter == 0) { + try { +lgK = RexLiteral.intValue(operand); Review comment: Added sqlkind checks here and in similar places 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org
[GitHub] [incubator-druid] jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs
jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs URL: https://github.com/apache/incubator-druid/pull/8487#discussion_r335718425 ## File path: extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchApproxCountDistinctSqlAggregator.java ## @@ -0,0 +1,211 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.query.aggregation.datasketches.hll.sql; + +import org.apache.calcite.rel.core.AggregateCall; +import org.apache.calcite.rel.core.Project; +import org.apache.calcite.rex.RexBuilder; +import org.apache.calcite.rex.RexLiteral; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.sql.SqlAggFunction; +import org.apache.calcite.sql.SqlFunctionCategory; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.type.InferTypes; +import org.apache.calcite.sql.type.OperandTypes; +import org.apache.calcite.sql.type.ReturnTypes; +import org.apache.calcite.sql.type.SqlTypeFamily; +import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.java.util.common.ISE; +import org.apache.druid.query.aggregation.AggregatorFactory; +import org.apache.druid.query.aggregation.datasketches.hll.HllSketchAggregatorFactory; +import org.apache.druid.query.aggregation.datasketches.hll.HllSketchBuildAggregatorFactory; +import org.apache.druid.query.aggregation.datasketches.hll.HllSketchMergeAggregatorFactory; +import org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator; +import org.apache.druid.query.dimension.DefaultDimensionSpec; +import org.apache.druid.query.dimension.DimensionSpec; +import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.ValueType; +import org.apache.druid.sql.calcite.aggregation.Aggregation; +import org.apache.druid.sql.calcite.aggregation.SqlAggregator; +import org.apache.druid.sql.calcite.expression.DruidExpression; +import org.apache.druid.sql.calcite.expression.Expressions; +import org.apache.druid.sql.calcite.planner.Calcites; +import org.apache.druid.sql.calcite.planner.PlannerContext; +import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; +import org.apache.druid.sql.calcite.table.RowSignature; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class HllSketchApproxCountDistinctSqlAggregator implements SqlAggregator +{ + private static final SqlAggFunction FUNCTION_INSTANCE = new HllSketchApproxCountDistinctSqlAggFunction(); + private static final String NAME = "APPROX_COUNT_DISTINCT_DS_HLL"; + private static final boolean ROUND = true; + + @Override + public SqlAggFunction calciteFunction() + { +return FUNCTION_INSTANCE; + } + + @Nullable + @Override + public Aggregation toDruidAggregation( + PlannerContext plannerContext, + RowSignature rowSignature, + VirtualColumnRegistry virtualColumnRegistry, + RexBuilder rexBuilder, + String name, + AggregateCall aggregateCall, + Project project, + List existingAggregations, + boolean finalizeAggregations + ) + { +// Don't use Aggregations.getArgumentsForSimpleAggregator, since it won't let us use direct column access Review comment: Refactored this to use a base abstract class (also did the same for theta sketches). I also renamed the aggregators that produce a sketch object to `*SketchObjectSqlAggregator` from `*SketchSqlAggregator` 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org
[GitHub] [incubator-druid] jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs
jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs URL: https://github.com/apache/incubator-druid/pull/8487#discussion_r335718521 ## File path: extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchSetUnionOperatorConversion.java ## @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.query.aggregation.datasketches.hll.sql; + +import org.apache.calcite.rex.RexCall; +import org.apache.calcite.rex.RexLiteral; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.sql.SqlFunction; +import org.apache.calcite.sql.SqlFunctionCategory; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.type.OperandTypes; +import org.apache.calcite.sql.type.ReturnTypes; +import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.query.aggregation.PostAggregator; +import org.apache.druid.query.aggregation.datasketches.hll.HllSketchUnionPostAggregator; +import org.apache.druid.sql.calcite.expression.DruidExpression; +import org.apache.druid.sql.calcite.expression.OperatorConversions; +import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; +import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; +import org.apache.druid.sql.calcite.planner.Calcites; +import org.apache.druid.sql.calcite.planner.PlannerContext; +import org.apache.druid.sql.calcite.table.RowSignature; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; + +public class HllSketchSetUnionOperatorConversion implements SqlOperatorConversion +{ + private static final SqlFunction SQL_FUNCTION = new SqlFunction( + "HLL_SKETCH_UNION", + SqlKind.OTHER_FUNCTION, + ReturnTypes.explicit( + factory -> Calcites.createSqlType(factory, SqlTypeName.OTHER) + ), + null, + OperandTypes.VARIADIC, Review comment: Changed to suggested 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org
[GitHub] [incubator-druid] jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs
jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs URL: https://github.com/apache/incubator-druid/pull/8487#discussion_r335718581 ## File path: extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchSetBaseOperatorConversion.java ## @@ -0,0 +1,140 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.query.aggregation.datasketches.theta.sql; + +import org.apache.calcite.rex.RexCall; +import org.apache.calcite.rex.RexLiteral; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.sql.SqlFunction; +import org.apache.calcite.sql.SqlFunctionCategory; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.type.OperandTypes; +import org.apache.calcite.sql.type.ReturnTypes; +import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.query.aggregation.PostAggregator; +import org.apache.druid.query.aggregation.datasketches.theta.SketchSetPostAggregator; +import org.apache.druid.sql.calcite.expression.DruidExpression; +import org.apache.druid.sql.calcite.expression.OperatorConversions; +import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; +import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; +import org.apache.druid.sql.calcite.planner.Calcites; +import org.apache.druid.sql.calcite.planner.PlannerContext; +import org.apache.druid.sql.calcite.table.RowSignature; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; + +public abstract class ThetaSketchSetBaseOperatorConversion implements SqlOperatorConversion +{ + public ThetaSketchSetBaseOperatorConversion() + { + } + + @Override + public SqlOperator calciteOperator() + { +return makeSqlFunction(); + } + + @Nullable + @Override + public DruidExpression toDruidExpression( + PlannerContext plannerContext, + RowSignature rowSignature, + RexNode rexNode + ) + { +return null; + } + + @Nullable + @Override + public PostAggregator toPostAggregator( + PlannerContext plannerContext, + RowSignature rowSignature, + RexNode rexNode, + PostAggregatorVisitor postAggregatorVisitor + ) + { +final List operands = ((RexCall) rexNode).getOperands(); +final List inputPostAggs = new ArrayList<>(); +Integer size = null; + +int operandCounter = 0; +for (RexNode operand : operands) { + final PostAggregator convertedPostAgg = OperatorConversions.toPostAggregator( + plannerContext, + rowSignature, + operand, + postAggregatorVisitor + ); + if (convertedPostAgg == null) { +if (operandCounter == 0) { + try { +size = RexLiteral.intValue(operand); + } + catch (RuntimeException re) { +return null; + } +} else { + return null; +} + } else { +inputPostAggs.add(convertedPostAgg); +operandCounter++; + } +} + +return new SketchSetPostAggregator( +postAggregatorVisitor.getOutputNamePrefix() + postAggregatorVisitor.getAndIncrementCounter(), +getSetOperationName(), +size, +inputPostAggs +); + } + + private SqlFunction makeSqlFunction() + { +return new SqlFunction( +getFunctionName(), +SqlKind.OTHER_FUNCTION, +ReturnTypes.explicit( +factory -> Calcites.createSqlType(factory, SqlTypeName.OTHER) +), +null, +OperandTypes.VARIADIC, Review comment: Changed to suggested 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail:
[GitHub] [incubator-druid] jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs
jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs URL: https://github.com/apache/incubator-druid/pull/8487#discussion_r335718056 ## File path: extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchEstimateOperatorConversion.java ## @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.query.aggregation.datasketches.hll.sql; + +import org.apache.calcite.rex.RexCall; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.sql.SqlFunction; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.type.ReturnTypes; +import org.apache.calcite.sql.type.SqlTypeFamily; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.query.aggregation.PostAggregator; +import org.apache.druid.query.aggregation.datasketches.hll.HllSketchToEstimatePostAggregator; +import org.apache.druid.sql.calcite.expression.DirectOperatorConversion; +import org.apache.druid.sql.calcite.expression.DruidExpression; +import org.apache.druid.sql.calcite.expression.OperatorConversions; +import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; +import org.apache.druid.sql.calcite.planner.PlannerContext; +import org.apache.druid.sql.calcite.table.RowSignature; + +import javax.annotation.Nullable; +import java.util.List; + +public class HllSketchEstimateOperatorConversion extends DirectOperatorConversion +{ + private static String FUNCTION_NAME = "HLL_SKETCH_ESTIMATE"; Review comment: Added final here and in similar places 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org
[GitHub] [incubator-druid] jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs
jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs URL: https://github.com/apache/incubator-druid/pull/8487#discussion_r335718002 ## File path: extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/HllSketchToEstimatePostAggregator.java ## @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.query.aggregation.datasketches.hll; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.yahoo.sketches.hll.HllSketch; +import org.apache.druid.query.aggregation.AggregatorFactory; +import org.apache.druid.query.aggregation.PostAggregator; +import org.apache.druid.query.aggregation.post.ArithmeticPostAggregator; +import org.apache.druid.query.aggregation.post.PostAggregatorIds; +import org.apache.druid.query.cache.CacheKeyBuilder; + +import java.util.Comparator; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +/** + * Returns a distinct count estimate a from a given {@link HllSketch}. + * The result will be a double value. + */ +public class HllSketchToEstimatePostAggregator implements PostAggregator +{ + private final String name; + private final PostAggregator field; + + @JsonCreator + public HllSketchToEstimatePostAggregator( + @JsonProperty("name") final String name, + @JsonProperty("field") final PostAggregator field + ) + { +this.name = name; +this.field = field; + } + + @Override + @JsonProperty + public String getName() + { +return name; + } + + @JsonProperty + public PostAggregator getField() + { +return field; + } + + @Override + public Set getDependentFields() + { +return field.getDependentFields(); + } + + @Override + public Comparator getComparator() + { +return ArithmeticPostAggregator.DEFAULT_COMPARATOR; + } + + @Override + public Object compute(final Map combinedAggregators) + { +final HllSketch sketch = (HllSketch) field.compute(combinedAggregators); +return sketch.getEstimate(); + } + + @Override + public PostAggregator decorate(final Map aggregators) + { +return this; + } + + @Override + public String toString() + { +return getClass().getSimpleName() + "{" + +"name='" + name + '\'' + +", field=" + field + +"}"; + } + + @Override + public boolean equals(final Object o) + { +if (this == o) { + return true; +} +if (!(o instanceof HllSketchToEstimatePostAggregator)) { + return false; +} + +final HllSketchToEstimatePostAggregator that = (HllSketchToEstimatePostAggregator) o; + +if (!name.equals(that.name)) { + return false; +} +return field.equals(that.field); + } + + @Override + public int hashCode() + { +return Objects.hash(name, field); + } + + @Override + public byte[] getCacheKey() + { +return new CacheKeyBuilder(PostAggregatorIds.HLL_SKETCH_TO_ESTIMATE_CACHE_TYPE_ID) +.appendString(name) Review comment: Removed, thanks 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org
[GitHub] [incubator-druid] jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs
jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs URL: https://github.com/apache/incubator-druid/pull/8487#discussion_r335717239 ## File path: docs/querying/sql.md ## @@ -363,6 +366,44 @@ All 'array' references in the multi-value string function documentation can refe | `MV_TO_STRING(arr,str)` | joins all elements of arr by the delimiter specified by str | | `STRING_TO_MV(str1,str2)` | splits str1 into an array on the delimiter specified by str2 | +### Sketch operators + +These functions operate on expressions or columns that return sketch objects. + + HLL sketch operators + +The following functions operate on [DataSketches HLL sketches](../development/extensions-core/datasketches-hll.html). +The [DataSketches extension](../development/extensions-core/datasketches-extension.html) must be loaded to use the following functions. + +|Function|Notes| +||-| +|`HLL_SKETCH_ESTIMATE(expr)`|Returns the distinct count estimate from an HLL sketch. `expr` must return an HLL sketch.| +|`HLL_SKETCH_ESTIMATE_WITH_ERROR_BOUNDS(expr, [numStdDev])`|Returns the distinct count estimate and error bounds from an HLL sketch. `expr` must return an HLL sketch. An optional `numStdDev` argument can be provided.| +|`HLL_SKETCH_UNION([lgK, tgtHllType], expr0, expr1, ...)`|Returns a union of HLL sketches, where each input expression must return an HLL sketch. The `lgK` and `tgtHllType` can be optionally specified as the first parameter; if provided, both optional parameters must be specified.| +|`HLL_SKETCH_TO_STRING(expr)`|Returns a human-readable string representation of an HLL sketch for debugging. `expr` must return an HLL sketch.| + + Theta sketch operators + +The following functions operate on [theta sketches](../development/extensions-core/datasketches-theta.html). +The [DataSketches extension](../development/extensions-core/datasketches-extension.html) must be loaded to use the following functions. + +|Function|Notes| +||-| +|`THETA_SKETCH_ESTIMATE(expr)`|Returns the distinct count estimate from a theta sketch. `expr` must return a theta sketch.| +|`THETA_SKETCH_ESTIMATE_WITH_ERROR_BOUNDS(expr, errorBoundsStdDev)`|Returns the distinct count estimate and error bounds from a theta sketch. `expr` must return a theta sketch.| Review comment: I think given the context and other docs (https://druid.apache.org/docs/latest/development/extensions-core/datasketches-theta.html), `estimate` is clear here 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org
[GitHub] [incubator-druid] jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs
jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs URL: https://github.com/apache/incubator-druid/pull/8487#discussion_r335716800 ## File path: docs/querying/sql.md ## @@ -363,6 +366,44 @@ All 'array' references in the multi-value string function documentation can refe | `MV_TO_STRING(arr,str)` | joins all elements of arr by the delimiter specified by str | | `STRING_TO_MV(str1,str2)` | splits str1 into an array on the delimiter specified by str2 | +### Sketch operators + +These functions operate on expressions or columns that return sketch objects. + + HLL sketch operators + +The following functions operate on [DataSketches HLL sketches](../development/extensions-core/datasketches-hll.html). +The [DataSketches extension](../development/extensions-core/datasketches-extension.html) must be loaded to use the following functions. + +|Function|Notes| +||-| +|`HLL_SKETCH_ESTIMATE(expr)`|Returns the distinct count estimate from an HLL sketch. `expr` must return an HLL sketch.| +|`HLL_SKETCH_ESTIMATE_WITH_ERROR_BOUNDS(expr, [numStdDev])`|Returns the distinct count estimate and error bounds from an HLL sketch. `expr` must return an HLL sketch. An optional `numStdDev` argument can be provided.| +|`HLL_SKETCH_UNION([lgK, tgtHllType], expr0, expr1, ...)`|Returns a union of HLL sketches, where each input expression must return an HLL sketch. The `lgK` and `tgtHllType` can be optionally specified as the first parameter; if provided, both optional parameters must be specified.| +|`HLL_SKETCH_TO_STRING(expr)`|Returns a human-readable string representation of an HLL sketch for debugging. `expr` must return an HLL sketch.| + + Theta sketch operators + +The following functions operate on [theta sketches](../development/extensions-core/datasketches-theta.html). +The [DataSketches extension](../development/extensions-core/datasketches-extension.html) must be loaded to use the following functions. + +|Function|Notes| +||-| +|`THETA_SKETCH_ESTIMATE(expr)`|Returns the distinct count estimate from a theta sketch. `expr` must return a theta sketch.| Review comment: My reasoning here is the same as in this comment: https://github.com/apache/incubator-druid/pull/8487/files#r335716107 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org
[GitHub] [incubator-druid] jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs
jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs URL: https://github.com/apache/incubator-druid/pull/8487#discussion_r335716427 ## File path: docs/querying/sql.md ## @@ -363,6 +366,44 @@ All 'array' references in the multi-value string function documentation can refe | `MV_TO_STRING(arr,str)` | joins all elements of arr by the delimiter specified by str | | `STRING_TO_MV(str1,str2)` | splits str1 into an array on the delimiter specified by str2 | +### Sketch operators + +These functions operate on expressions or columns that return sketch objects. + + HLL sketch operators + +The following functions operate on [DataSketches HLL sketches](../development/extensions-core/datasketches-hll.html). +The [DataSketches extension](../development/extensions-core/datasketches-extension.html) must be loaded to use the following functions. + +|Function|Notes| +||-| +|`HLL_SKETCH_ESTIMATE(expr)`|Returns the distinct count estimate from an HLL sketch. `expr` must return an HLL sketch.| +|`HLL_SKETCH_ESTIMATE_WITH_ERROR_BOUNDS(expr, [numStdDev])`|Returns the distinct count estimate and error bounds from an HLL sketch. `expr` must return an HLL sketch. An optional `numStdDev` argument can be provided.| Review comment: Within the context of this sketch and its documentation (https://druid.apache.org/docs/latest/development/extensions-core/datasketches-hll.html), I think the meaning of `estimate` is clear 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org
[GitHub] [incubator-druid] jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs
jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs URL: https://github.com/apache/incubator-druid/pull/8487#discussion_r335716107 ## File path: docs/querying/sql.md ## @@ -363,6 +366,44 @@ All 'array' references in the multi-value string function documentation can refe | `MV_TO_STRING(arr,str)` | joins all elements of arr by the delimiter specified by str | | `STRING_TO_MV(str1,str2)` | splits str1 into an array on the delimiter specified by str2 | +### Sketch operators + +These functions operate on expressions or columns that return sketch objects. + + HLL sketch operators + +The following functions operate on [DataSketches HLL sketches](../development/extensions-core/datasketches-hll.html). +The [DataSketches extension](../development/extensions-core/datasketches-extension.html) must be loaded to use the following functions. + +|Function|Notes| +||-| +|`HLL_SKETCH_ESTIMATE(expr)`|Returns the distinct count estimate from an HLL sketch. `expr` must return an HLL sketch.| Review comment: Hmm, i actually like the new functions added in this PR more than `APPROX_COUNT_DISTINCT_DS_HLL`, I think they express a clearer boundary between the aggregated sketch object and the operations that can be performed on said object. The new functions names also have a 1-to-1 correspondence with the underlying native aggs/postaggs which I think is nice. If not for backwards compatibility, I would actually consider dropping `APPROX_COUNT_DISTINCT_DS_HLL`, it was introduced as a way to allow people to use the datasketches implementations before we supported postaggs in SQL (with this patch). 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org
[GitHub] [incubator-druid] jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs
jon-wei commented on a change in pull request #8487: Add initial SQL support for non-expression sketch postaggs URL: https://github.com/apache/incubator-druid/pull/8487#discussion_r325954573 ## File path: docs/querying/sql.md ## @@ -363,6 +366,45 @@ All 'array' references in the multi-value string function documentation can refe | `MV_TO_STRING(arr,str)` | joins all elements of arr by the delimiter specified by str | | `STRING_TO_MV(str1,str2)` | splits str1 into an array on the delimiter specified by str2 | +### Sketch operators + +These functions operate on expressions or columns that return sketch objects. + + HLL sketch operators + +The following functions operate on [DataSketches HLL sketches](../development/extensions-core/datasketches-hll.html). +The [DataSketches extension](../development/extensions-core/datasketches-extension.html) must be loaded to use the following functions. + +|Function|Notes| +||-| +|`HLL_SKETCH_ESTIMATE(expr)`|Returns the distinct count estimate from an HLL sketch. `expr` must return an HLL sketch.| +|`HLL_SKETCH_ESTIMATE_WITH_ERROR_BOUNDS(expr, [numStdDev])`|Returns the distinct count estimate and error bounds from an HLL sketch. `expr` must return an HLL sketch. An optional `numStdDev` argument can be provided.| +|`HLL_SKETCH_UNION([lgK, tgtHllType], expr0, expr1, ...)`|Returns a union of HLL sketches, where each input expression must return an HLL sketch. The `lgK` and `tgtHllType` can be optionally specified as the first parameter; if provided, both optional parameters must be specified.| +|`HLL_SKETCH_TO_STRING(expr)`|Returns a human-readable string representation of an HLL sketch for debugging. `expr` must return an HLL sketch.| + + Theta sketch operators + +The following functions operate on [theta sketches](../development/extensions-core/datasketches-theta.html). +The [DataSketches extension](../development/extensions-core/datasketches-extension.html) must be loaded to use the following functions. + +|Function|Notes| +||-| +|`THETA_SKETCH_ESTIMATE(expr)`|Returns the distinct count estimate from a theta sketch. `expr` must return a theta sketch.| +|`THETA_SKETCH_ESTIMATE_WITH_ERROR_BOUNDS(expr, errorBoundsStdDev)`|Returns the distinct count estimate and error bounds from a theta sketch. `expr` must return a theta sketch.| +|`THETA_SKETCH_UNION([size], expr0, expr1, ...)`|Returns a union of theta sketches, where each input expression must return an theta sketch. The `size` can be optionally specified as the first parameter.| Review comment: thanks, fixed, looks like there were no spellcheck errors 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: us...@infra.apache.org With regards, Apache Git Services - To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org