Yingyi Bu has uploaded a new change for review. https://asterix-gerrit.ics.uci.edu/857
Change subject: Let SQL-92 aggregate functions behave the same as SQL-92. ...................................................................... Let SQL-92 aggregate functions behave the same as SQL-92. Change-Id: Ia2929d1ca6344508bbf772884ea8ef1f39a0e19f --- A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/null/null.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite-open/aggregate.27.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite-open/group-by.26.query.sqlpp M asterixdb/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_number/agg_number.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/group-by/null/null.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite-open/aggregate.27.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite-open/group-by.26.adm M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml M asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java M asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/AbstractAvgAggregateFunction.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/SqlAvgAggregateFunction.java M hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/expressions/AggregateFunctionCallExpression.java 13 files changed, 109 insertions(+), 23 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/57/857/1 diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/null/null.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/null/null.1.query.sqlpp new file mode 100644 index 0000000..f78024e --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/null/null.1.query.sqlpp @@ -0,0 +1,21 @@ +/* + * 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. + */ + +SELECT avg(e) as average, count(e) as count, sum(e) as sum, min(e) as min, max(e) as max +FROM [1, 2, 3, null, 4] AS e; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite-open/aggregate.27.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite-open/aggregate.27.query.sqlpp new file mode 100644 index 0000000..5a25013 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite-open/aggregate.27.query.sqlpp @@ -0,0 +1,29 @@ +/* + * 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. + */ + +USE TinySocial; + + +SELECT avg("get-year"(employment."end-date")) AS average, + count(employment."end-date") AS count, + sum("get-year"(employment."end-date")) AS sum, + min(employment."end-date") AS min, + max(employment."end-date") AS max +FROM FacebookUsers as fbu, fbu.employment AS employment +; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite-open/group-by.26.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite-open/group-by.26.query.sqlpp new file mode 100644 index 0000000..cdebdcc --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tinysocial/tinysocial-suite-open/group-by.26.query.sqlpp @@ -0,0 +1,31 @@ +/* + * 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. + */ + +USE TinySocial; + + +SELECT org AS organization, + avg("get-year"(employment."end-date")) AS average, + count(employment."end-date") AS count, + sum("get-year"(employment."end-date")) AS sum, + min(employment."end-date") AS min, + max(employment."end-date") AS max +FROM FacebookUsers as fbu, fbu.employment AS employment +GROUP BY employment."organization-name" AS org +; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_number/agg_number.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_number/agg_number.1.adm index 91e6906..0e85837 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_number/agg_number.1.adm +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/aggregate-sql/agg_number/agg_number.1.adm @@ -1 +1 @@ -{ "sql-count1": 4, "sql-count2": 4, "average1": 2.3461845695961844E16d, "sql-sum1": 9.3847382783847376E16d, "sql-min1": 1.0d, "sql-max1": 9.3847382783847376E16d, "average2": 2.3461845695961844E16d, "sql-sum2": 9.3847382783847376E16d, "sql-min2": 1.0d, "sql-max2": 9.3847382783847376E16d } +{ "sql-count1": 4, "average1": 2.3461845695961844E16d, "sql-count2": 4, "average2": 2.3461845695961844E16d, "sql-sum1": 9.3847382783847376E16d, "sql-min1": 1.0d, "sql-max1": 9.3847382783847376E16d, "sql-sum2": 9.3847382783847376E16d, "sql-min2": 1.0d, "sql-max2": 9.3847382783847376E16d } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/group-by/null/null.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/group-by/null/null.1.adm new file mode 100644 index 0000000..3c5ff5a --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/group-by/null/null.1.adm @@ -0,0 +1 @@ +{ "average": 2.5d, "count": 4, "sum": 10, "min": 1, "max": 4 } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite-open/aggregate.27.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite-open/aggregate.27.adm new file mode 100644 index 0000000..fe79be3 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite-open/aggregate.27.adm @@ -0,0 +1 @@ +{ "average": 2010.0d, "count": 3, "sum": 6030, "min": date("2009-12-13"), "max": date("2011-11-05") } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite-open/group-by.26.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite-open/group-by.26.adm new file mode 100644 index 0000000..abeda77 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite-open/group-by.26.adm @@ -0,0 +1,10 @@ +{ "average": 2009.0d, "count": 1, "sum": 2009, "organization": "Zuncan", "min": date("2009-12-13"), "max": date("2009-12-13") } +{ "average": null, "count": 0, "sum": null, "organization": "Labzatron", "min": null, "max": null } +{ "average": null, "count": 0, "sum": null, "organization": "Plexlane", "min": null, "max": null } +{ "average": null, "count": 0, "sum": null, "organization": "jaydax", "min": null, "max": null } +{ "average": null, "count": 0, "sum": null, "organization": "Codetechno", "min": null, "max": null } +{ "average": null, "count": 0, "sum": null, "organization": "Hexviafind", "min": null, "max": null } +{ "average": null, "count": 0, "sum": null, "organization": "Zamcorporation", "min": null, "max": null } +{ "average": 2011.0d, "count": 1, "sum": 2011, "organization": "physcane", "min": date("2011-11-05"), "max": date("2011-11-05") } +{ "average": null, "count": 0, "sum": null, "organization": "Kongreen", "min": null, "max": null } +{ "average": 2010.0d, "count": 1, "sum": 2010, "organization": "geomedia", "min": date("2010-01-26"), "max": date("2010-01-26") } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml index b753974..d0e28ee 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -2349,6 +2349,11 @@ <output-dir compare="Text">core-05</output-dir> </compilation-unit> </test-case> + <test-case FilePath="group-by"> + <compilation-unit name="null"> + <output-dir compare="Text">null</output-dir> + </compilation-unit> + </test-case> </test-group> <test-group name="index-join"> <test-case FilePath="index-join"> diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java index cbf05b5..6d19995 100644 --- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java +++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java @@ -32,6 +32,7 @@ public class FunctionMapUtil { private final static String CORE_AGGREGATE_PREFIX = "coll_"; + private final static String SQL_PREFIX = "sql-"; // Maps from a SQL function name to an AQL function name (i.e., AsterixDB internal name). private static final Map<String, String> FUNCTION_NAME_MAP = new HashMap<>(); @@ -94,7 +95,8 @@ if (!isSql92AggregateFunction(fs)) { return fs; } - return new FunctionSignature(fs.getNamespace(), CORE_AGGREGATE_PREFIX + fs.getName(), fs.getArity()); + return new FunctionSignature(fs.getNamespace(), CORE_AGGREGATE_PREFIX + SQL_PREFIX + fs.getName(), + fs.getArity()); } /** diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java index d604f35..e2419f9 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java @@ -872,6 +872,9 @@ // SQL Aggregate Functions addFunction(SQL_AVG, OptionalADoubleTypeComputer.INSTANCE, true); + addPrivateFunction(GLOBAL_SQL_AVG, OptionalADoubleTypeComputer.INSTANCE, true); + addPrivateFunction(LOCAL_SQL_AVG, NonTaggedLocalAvgTypeComputer.INSTANCE, true); + addPrivateFunction(INTERMEDIATE_SQL_AVG, NonTaggedLocalAvgTypeComputer.INSTANCE, true); addFunction(SQL_COUNT, AInt64TypeComputer.INSTANCE, true); addFunction(SQL_MAX, NonTaggedMinMaxAggTypeComputer.INSTANCE, true); addPrivateFunction(LOCAL_SQL_MAX, NonTaggedMinMaxAggTypeComputer.INSTANCE, true); @@ -879,7 +882,7 @@ addPrivateFunction(LOCAL_SQL_MIN, NonTaggedMinMaxAggTypeComputer.INSTANCE, true); addFunction(SQL_SUM, NonTaggedNumericAggTypeComputer.INSTANCE, true); addPrivateFunction(LOCAL_SQL_SUM, NonTaggedNumericAggTypeComputer.INSTANCE, true); - addFunction(SCALAR_SQL_AVG, ScalarVersionOfAggregateResultType.INSTANCE, true); + addFunction(SCALAR_SQL_AVG, OptionalADoubleTypeComputer.INSTANCE, true); addFunction(SCALAR_SQL_COUNT, AInt64TypeComputer.INSTANCE, true); addPrivateFunction(SCALAR_GLOBAL_SQL_AVG, ScalarVersionOfAggregateResultType.INSTANCE, true); addPrivateFunction(SCALAR_LOCAL_SQL_AVG, ScalarVersionOfAggregateResultType.INSTANCE, true); @@ -895,7 +898,6 @@ addPrivateFunction(SERIAL_LOCAL_SQL_SUM, NonTaggedNumericAggTypeComputer.INSTANCE, true); addPrivateFunction(INTERMEDIATE_AVG, NonTaggedLocalAvgTypeComputer.INSTANCE, true); - addPrivateFunction(INTERMEDIATE_SQL_AVG, NonTaggedLocalAvgTypeComputer.INSTANCE, true); addFunction(SCALAR_AVG, ScalarVersionOfAggregateResultType.INSTANCE, true); addFunction(SCALAR_COUNT, AInt64TypeComputer.INSTANCE, true); diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/AbstractAvgAggregateFunction.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/AbstractAvgAggregateFunction.java index a57aacd..4de4b57 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/AbstractAvgAggregateFunction.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/AbstractAvgAggregateFunction.java @@ -234,8 +234,8 @@ break; } default: { - throw new AlgebricksException("Global-Avg is not defined for values of type " - + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serBytes[0])); + throw new AlgebricksException("Intermediate/global-Avg is not defined for values of type " + + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serBytes[offset])); } } } diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/SqlAvgAggregateFunction.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/SqlAvgAggregateFunction.java index dda677a..fd25d4d 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/SqlAvgAggregateFunction.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/SqlAvgAggregateFunction.java @@ -44,7 +44,7 @@ @Override public void finishPartial(IPointable result) throws AlgebricksException { - finish(result); + finishPartialResults(result); } @Override diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/expressions/AggregateFunctionCallExpression.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/expressions/AggregateFunctionCallExpression.java index 67f285d..f09b4c2 100644 --- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/expressions/AggregateFunctionCallExpression.java +++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/expressions/AggregateFunctionCallExpression.java @@ -21,24 +21,19 @@ import java.util.List; import org.apache.commons.lang3.mutable.Mutable; - import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression; import org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo; import org.apache.hyracks.algebricks.core.algebra.visitors.ILogicalExpressionVisitor; /** - * * An aggregate function may be executed in a "two step" mode. First the * "step-one" aggregates are run and then the results are passed to the * "step-two" aggregators. The convention is the following: - * * 1. The step-one aggregate must be able to accept the same arguments as the * original aggregate function call. - * * 2. The step-two aggregate must be a unary function that accepts as input the * output of the step-one aggregate. - * */ public class AggregateFunctionCallExpression extends AbstractFunctionCallExpression { @@ -47,20 +42,9 @@ private IFunctionInfo stepOneAggregate; private IFunctionInfo stepTwoAggregate; - public AggregateFunctionCallExpression(IFunctionInfo finfo, boolean isTwoStep) { - super(FunctionKind.AGGREGATE, finfo); - this.twoStep = isTwoStep; - } - public AggregateFunctionCallExpression(IFunctionInfo finfo, boolean isTwoStep, List<Mutable<ILogicalExpression>> arguments) { super(FunctionKind.AGGREGATE, finfo, arguments); - this.twoStep = isTwoStep; - } - - public AggregateFunctionCallExpression(IFunctionInfo finfo, boolean isTwoStep, - Mutable<ILogicalExpression>... expressions) { - super(FunctionKind.AGGREGATE, finfo, expressions); this.twoStep = isTwoStep; } -- To view, visit https://asterix-gerrit.ics.uci.edu/857 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia2929d1ca6344508bbf772884ea8ef1f39a0e19f Gerrit-PatchSet: 1 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Yingyi Bu <[email protected]>
