You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by dl...@apache.org on 2018/10/12 21:10:22 UTC
[03/10] asterixdb git commit: [ASTERIXDB-2459][FUN] Add sttdev()
aggregate function
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
index f2be330..910c159 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
@@ -81,6 +81,7 @@ import org.apache.asterix.om.typecomputer.impl.IfNanOrInfTypeComputer;
import org.apache.asterix.om.typecomputer.impl.IfNullTypeComputer;
import org.apache.asterix.om.typecomputer.impl.InjectFailureTypeComputer;
import org.apache.asterix.om.typecomputer.impl.LocalAvgTypeComputer;
+import org.apache.asterix.om.typecomputer.impl.LocalSingleVarStatisticsTypeComputer;
import org.apache.asterix.om.typecomputer.impl.MinMaxAggTypeComputer;
import org.apache.asterix.om.typecomputer.impl.MissingIfTypeComputer;
import org.apache.asterix.om.typecomputer.impl.NonTaggedGetItemResultType;
@@ -468,6 +469,14 @@ public class BuiltinFunctions {
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-first-element", 1);
public static final FunctionIdentifier LOCAL_FIRST_ELEMENT =
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-local-first-element", 1);
+ public static final FunctionIdentifier STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-stddev", 1);
+ public static final FunctionIdentifier GLOBAL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-global-stddev", 1);
+ public static final FunctionIdentifier INTERMEDIATE_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-intermediate-stddev", 1);
+ public static final FunctionIdentifier LOCAL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-local-stddev", 1);
public static final FunctionIdentifier SCALAR_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "avg", 1);
public static final FunctionIdentifier SCALAR_COUNT =
@@ -481,6 +490,12 @@ public class BuiltinFunctions {
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "local-avg", 1);
public static final FunctionIdentifier SCALAR_FIRST_ELEMENT =
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "first-element", 1);
+ public static final FunctionIdentifier SCALAR_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "stddev", 1);
+ public static final FunctionIdentifier SCALAR_GLOBAL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "global-stddev", 1);
+ public static final FunctionIdentifier SCALAR_LOCAL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "local-stddev", 1);
// serializable aggregate functions
public static final FunctionIdentifier SERIAL_AVG =
@@ -497,6 +512,14 @@ public class BuiltinFunctions {
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "local-avg-serial", 1);
public static final FunctionIdentifier SERIAL_INTERMEDIATE_AVG =
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "intermediate-avg-serial", 1);
+ public static final FunctionIdentifier SERIAL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "stddev-serial", 1);
+ public static final FunctionIdentifier SERIAL_GLOBAL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "global-stddev-serial", 1);
+ public static final FunctionIdentifier SERIAL_LOCAL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "local-stddev-serial", 1);
+ public static final FunctionIdentifier SERIAL_INTERMEDIATE_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "intermediate-stddev-serial", 1);
// distinct aggregate functions
public static final FunctionIdentifier COUNT_DISTINCT =
@@ -543,6 +566,14 @@ public class BuiltinFunctions {
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-global-sql-avg", 1);
public static final FunctionIdentifier LOCAL_SQL_AVG =
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-local-sql-avg", 1);
+ public static final FunctionIdentifier SQL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-sql-stddev", 1);
+ public static final FunctionIdentifier INTERMEDIATE_SQL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "intermediate-agg-sql-stddev", 1);
+ public static final FunctionIdentifier GLOBAL_SQL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-global-sql-stddev", 1);
+ public static final FunctionIdentifier LOCAL_SQL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-local-sql-stddev", 1);
public static final FunctionIdentifier SCALAR_SQL_AVG =
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "sql-avg", 1);
@@ -558,6 +589,12 @@ public class BuiltinFunctions {
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "global-sql-avg", 1);
public static final FunctionIdentifier SCALAR_LOCAL_SQL_AVG =
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "local-sql-avg", 1);
+ public static final FunctionIdentifier SCALAR_SQL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "sql-stddev", 1);
+ public static final FunctionIdentifier SCALAR_GLOBAL_SQL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "global-sql-stddev", 1);
+ public static final FunctionIdentifier SCALAR_LOCAL_SQL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "local-sql-stddev", 1);
// serializable sql aggregate functions
public static final FunctionIdentifier SERIAL_SQL_AVG =
@@ -574,6 +611,14 @@ public class BuiltinFunctions {
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "intermediate-sql-avg-serial", 1);
public static final FunctionIdentifier SERIAL_LOCAL_SQL_AVG =
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "local-sql-avg-serial", 1);
+ public static final FunctionIdentifier SERIAL_SQL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "sql-stddev-serial", 1);
+ public static final FunctionIdentifier SERIAL_GLOBAL_SQL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "global-sql-stddev-serial", 1);
+ public static final FunctionIdentifier SERIAL_INTERMEDIATE_SQL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "intermediate-sql-stddev-serial", 1);
+ public static final FunctionIdentifier SERIAL_LOCAL_SQL_STDDEV =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "local-sql-stddev-serial", 1);
// distinct sql aggregate functions
public static final FunctionIdentifier SQL_COUNT_DISTINCT =
@@ -1333,6 +1378,9 @@ public class BuiltinFunctions {
addPrivateFunction(SCALAR_FIRST_ELEMENT, CollectionMemberResultType.INSTANCE, true);
addPrivateFunction(FIRST_ELEMENT, PropagateTypeComputer.INSTANCE, true);
addPrivateFunction(LOCAL_FIRST_ELEMENT, PropagateTypeComputer.INSTANCE, true);
+ addPrivateFunction(LOCAL_STDDEV, LocalSingleVarStatisticsTypeComputer.INSTANCE, true);
+ addFunction(STDDEV, NullableDoubleTypeComputer.INSTANCE, true);
+ addPrivateFunction(GLOBAL_STDDEV, NullableDoubleTypeComputer.INSTANCE, true);
addPrivateFunction(SERIAL_SQL_AVG, NullableDoubleTypeComputer.INSTANCE, true);
addPrivateFunction(SERIAL_SQL_COUNT, AInt64TypeComputer.INSTANCE, true);
@@ -1349,6 +1397,14 @@ public class BuiltinFunctions {
addFunction(SCALAR_MIN, ScalarVersionOfAggregateResultType.INSTANCE, true);
addFunction(SCALAR_SUM, ScalarVersionOfAggregateResultType.INSTANCE, true);
addPrivateFunction(INTERMEDIATE_AVG, LocalAvgTypeComputer.INSTANCE, true);
+ addFunction(SCALAR_STDDEV, NullableDoubleTypeComputer.INSTANCE, true);
+ addPrivateFunction(SCALAR_GLOBAL_STDDEV, NullableDoubleTypeComputer.INSTANCE, true);
+ addPrivateFunction(SCALAR_LOCAL_STDDEV, NullableDoubleTypeComputer.INSTANCE, true);
+ addPrivateFunction(INTERMEDIATE_STDDEV, LocalSingleVarStatisticsTypeComputer.INSTANCE, true);
+ addPrivateFunction(SERIAL_SQL_STDDEV, NullableDoubleTypeComputer.INSTANCE, true);
+ addPrivateFunction(SERIAL_GLOBAL_SQL_STDDEV, NullableDoubleTypeComputer.INSTANCE, true);
+ addPrivateFunction(SERIAL_LOCAL_SQL_STDDEV, LocalSingleVarStatisticsTypeComputer.INSTANCE, true);
+ addPrivateFunction(SERIAL_INTERMEDIATE_SQL_STDDEV, LocalSingleVarStatisticsTypeComputer.INSTANCE, true);
addFunction(SQL_AVG, NullableDoubleTypeComputer.INSTANCE, true);
addPrivateFunction(GLOBAL_SQL_AVG, NullableDoubleTypeComputer.INSTANCE, true);
@@ -1369,6 +1425,13 @@ public class BuiltinFunctions {
addFunction(SCALAR_SQL_MIN, ScalarVersionOfAggregateResultType.INSTANCE, true);
addFunction(SCALAR_SQL_SUM, ScalarVersionOfAggregateResultType.INSTANCE, true);
addPrivateFunction(INTERMEDIATE_SQL_AVG, LocalAvgTypeComputer.INSTANCE, true);
+ addFunction(SQL_STDDEV, NullableDoubleTypeComputer.INSTANCE, true);
+ addPrivateFunction(GLOBAL_SQL_STDDEV, NullableDoubleTypeComputer.INSTANCE, true);
+ addPrivateFunction(LOCAL_SQL_STDDEV, LocalSingleVarStatisticsTypeComputer.INSTANCE, true);
+ addPrivateFunction(INTERMEDIATE_SQL_STDDEV, LocalSingleVarStatisticsTypeComputer.INSTANCE, true);
+ addFunction(SCALAR_SQL_STDDEV, NullableDoubleTypeComputer.INSTANCE, true);
+ addPrivateFunction(SCALAR_GLOBAL_SQL_STDDEV, NullableDoubleTypeComputer.INSTANCE, true);
+ addPrivateFunction(SCALAR_LOCAL_SQL_STDDEV, NullableDoubleTypeComputer.INSTANCE, true);
addPrivateFunction(SERIAL_AVG, NullableDoubleTypeComputer.INSTANCE, true);
addPrivateFunction(SERIAL_COUNT, AInt64TypeComputer.INSTANCE, true);
@@ -1377,6 +1440,10 @@ public class BuiltinFunctions {
addPrivateFunction(SERIAL_INTERMEDIATE_AVG, LocalAvgTypeComputer.INSTANCE, true);
addPrivateFunction(SERIAL_SUM, NumericAggTypeComputer.INSTANCE, true);
addPrivateFunction(SERIAL_LOCAL_SUM, NumericAggTypeComputer.INSTANCE, true);
+ addPrivateFunction(SERIAL_STDDEV, NullableDoubleTypeComputer.INSTANCE, true);
+ addPrivateFunction(SERIAL_GLOBAL_STDDEV, NullableDoubleTypeComputer.INSTANCE, true);
+ addPrivateFunction(SERIAL_LOCAL_STDDEV, LocalSingleVarStatisticsTypeComputer.INSTANCE, true);
+ addPrivateFunction(SERIAL_INTERMEDIATE_STDDEV, LocalSingleVarStatisticsTypeComputer.INSTANCE, true);
// Distinct aggregate functions
@@ -1727,6 +1794,33 @@ public class BuiltinFunctions {
addDistinctAgg(MAX_DISTINCT, SCALAR_MAX);
addScalarAgg(MAX_DISTINCT, SCALAR_MAX_DISTINCT);
+ // STDDEV
+
+ addAgg(STDDEV);
+ addAgg(LOCAL_STDDEV);
+ addAgg(GLOBAL_STDDEV);
+ addLocalAgg(STDDEV, LOCAL_STDDEV);
+ addIntermediateAgg(STDDEV, INTERMEDIATE_STDDEV);
+ addIntermediateAgg(LOCAL_STDDEV, INTERMEDIATE_STDDEV);
+ addIntermediateAgg(GLOBAL_STDDEV, INTERMEDIATE_STDDEV);
+ addGlobalAgg(STDDEV, GLOBAL_STDDEV);
+
+ addScalarAgg(STDDEV, SCALAR_STDDEV);
+ addScalarAgg(GLOBAL_STDDEV, SCALAR_GLOBAL_STDDEV);
+ addScalarAgg(LOCAL_STDDEV, SCALAR_LOCAL_STDDEV);
+
+ addSerialAgg(STDDEV, SERIAL_STDDEV);
+ addSerialAgg(LOCAL_STDDEV, SERIAL_LOCAL_STDDEV);
+ addSerialAgg(GLOBAL_STDDEV, SERIAL_GLOBAL_STDDEV);
+ addAgg(SERIAL_STDDEV);
+ addAgg(SERIAL_LOCAL_STDDEV);
+ addAgg(SERIAL_GLOBAL_STDDEV);
+ addLocalAgg(SERIAL_STDDEV, SERIAL_LOCAL_STDDEV);
+ addIntermediateAgg(SERIAL_STDDEV, SERIAL_INTERMEDIATE_STDDEV);
+ addIntermediateAgg(SERIAL_LOCAL_STDDEV, SERIAL_INTERMEDIATE_STDDEV);
+ addIntermediateAgg(SERIAL_GLOBAL_STDDEV, SERIAL_INTERMEDIATE_STDDEV);
+ addGlobalAgg(SERIAL_STDDEV, SERIAL_GLOBAL_STDDEV);
+
// FIRST_ELEMENT
addAgg(SCALAR_FIRST_ELEMENT);
@@ -1811,6 +1905,33 @@ public class BuiltinFunctions {
addIntermediateAgg(SERIAL_GLOBAL_SQL_AVG, SERIAL_INTERMEDIATE_SQL_AVG);
addGlobalAgg(SERIAL_SQL_AVG, SERIAL_GLOBAL_SQL_AVG);
+ // SQL STDDEV
+
+ addAgg(SQL_STDDEV);
+ addAgg(LOCAL_SQL_STDDEV);
+ addAgg(GLOBAL_SQL_STDDEV);
+ addLocalAgg(SQL_STDDEV, LOCAL_SQL_STDDEV);
+ addIntermediateAgg(SQL_STDDEV, INTERMEDIATE_SQL_STDDEV);
+ addIntermediateAgg(LOCAL_SQL_STDDEV, INTERMEDIATE_SQL_STDDEV);
+ addIntermediateAgg(GLOBAL_SQL_STDDEV, INTERMEDIATE_SQL_STDDEV);
+ addGlobalAgg(SQL_STDDEV, GLOBAL_SQL_STDDEV);
+
+ addScalarAgg(SQL_STDDEV, SCALAR_SQL_STDDEV);
+ addScalarAgg(GLOBAL_SQL_STDDEV, SCALAR_GLOBAL_SQL_STDDEV);
+ addScalarAgg(LOCAL_SQL_STDDEV, SCALAR_LOCAL_SQL_STDDEV);
+
+ addSerialAgg(SQL_STDDEV, SERIAL_SQL_STDDEV);
+ addSerialAgg(LOCAL_SQL_STDDEV, SERIAL_LOCAL_SQL_STDDEV);
+ addSerialAgg(GLOBAL_SQL_STDDEV, SERIAL_GLOBAL_SQL_STDDEV);
+ addAgg(SERIAL_SQL_STDDEV);
+ addAgg(SERIAL_LOCAL_SQL_STDDEV);
+ addAgg(SERIAL_GLOBAL_SQL_STDDEV);
+ addLocalAgg(SERIAL_SQL_STDDEV, SERIAL_LOCAL_SQL_STDDEV);
+ addIntermediateAgg(SERIAL_SQL_STDDEV, SERIAL_INTERMEDIATE_SQL_STDDEV);
+ addIntermediateAgg(SERIAL_LOCAL_SQL_STDDEV, SERIAL_INTERMEDIATE_SQL_STDDEV);
+ addIntermediateAgg(SERIAL_GLOBAL_SQL_STDDEV, SERIAL_INTERMEDIATE_SQL_STDDEV);
+ addGlobalAgg(SERIAL_SQL_STDDEV, SERIAL_GLOBAL_SQL_STDDEV);
+
// SQL AVG DISTINCT
addDistinctAgg(SQL_AVG_DISTINCT, SCALAR_SQL_AVG);
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/LocalSingleVarStatisticsTypeComputer.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/LocalSingleVarStatisticsTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/LocalSingleVarStatisticsTypeComputer.java
new file mode 100644
index 0000000..7650687
--- /dev/null
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/LocalSingleVarStatisticsTypeComputer.java
@@ -0,0 +1,44 @@
+/*
+ * 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.asterix.om.typecomputer.impl;
+
+import org.apache.asterix.om.typecomputer.base.IResultTypeComputer;
+import org.apache.asterix.om.types.ARecordType;
+import org.apache.asterix.om.types.AUnionType;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import org.apache.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+
+public class LocalSingleVarStatisticsTypeComputer implements IResultTypeComputer {
+
+ public static final LocalSingleVarStatisticsTypeComputer INSTANCE = new LocalSingleVarStatisticsTypeComputer();
+
+ @Override
+ public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
+ IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
+ return new ARecordType(null, new String[] { "m1", "m2", "count" },
+ new IAType[] { AUnionType.createNullableType(BuiltinType.ADOUBLE, "OptionalDouble"),
+ AUnionType.createNullableType(BuiltinType.ADOUBLE, "OptionalDouble"), BuiltinType.AINT64 },
+ false);
+ }
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-om/src/test/java/org/apache/asterix/om/typecomputer/TypeComputerTest.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/test/java/org/apache/asterix/om/typecomputer/TypeComputerTest.java b/asterixdb/asterix-om/src/test/java/org/apache/asterix/om/typecomputer/TypeComputerTest.java
index 9f6a8eb..d18472c 100644
--- a/asterixdb/asterix-om/src/test/java/org/apache/asterix/om/typecomputer/TypeComputerTest.java
+++ b/asterixdb/asterix-om/src/test/java/org/apache/asterix/om/typecomputer/TypeComputerTest.java
@@ -96,6 +96,7 @@ public class TypeComputerTest {
exceptionalTypeComputers.add("NullableDoubleTypeComputer");
exceptionalTypeComputers.add("RecordMergeTypeComputer");
exceptionalTypeComputers.add("BooleanOrMissingTypeComputer");
+ exceptionalTypeComputers.add("LocalSingleVarStatisticsTypeComputer");
// Tests all usual type computers.
Reflections reflections = new Reflections("org.apache.asterix.om.typecomputer", new SubTypesScanner(false));
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/scalar/ScalarSqlStddevAggregateDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/scalar/ScalarSqlStddevAggregateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/scalar/ScalarSqlStddevAggregateDescriptor.java
new file mode 100644
index 0000000..0b80fe4
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/scalar/ScalarSqlStddevAggregateDescriptor.java
@@ -0,0 +1,49 @@
+/*
+ * 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.asterix.runtime.aggregates.scalar;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptor;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.runtime.aggregates.std.SqlStddevAggregateDescriptor;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+
+public class ScalarSqlStddevAggregateDescriptor extends AbstractScalarAggregateDescriptor {
+
+ private static final long serialVersionUID = 1L;
+
+ public final static FunctionIdentifier FID = BuiltinFunctions.SCALAR_SQL_STDDEV;
+
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new ScalarSqlStddevAggregateDescriptor(
+ SqlStddevAggregateDescriptor.FACTORY.createFunctionDescriptor());
+ }
+ };
+
+ private ScalarSqlStddevAggregateDescriptor(IFunctionDescriptor aggFuncDesc) {
+ super(aggFuncDesc);
+ }
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return FID;
+ }
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/scalar/ScalarStddevAggregateDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/scalar/ScalarStddevAggregateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/scalar/ScalarStddevAggregateDescriptor.java
new file mode 100644
index 0000000..00d26c9
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/scalar/ScalarStddevAggregateDescriptor.java
@@ -0,0 +1,48 @@
+/*
+ * 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.asterix.runtime.aggregates.scalar;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptor;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.runtime.aggregates.std.StddevAggregateDescriptor;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+
+public class ScalarStddevAggregateDescriptor extends AbstractScalarAggregateDescriptor {
+
+ private static final long serialVersionUID = 1L;
+
+ public final static FunctionIdentifier FID = BuiltinFunctions.SCALAR_STDDEV;
+
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new ScalarStddevAggregateDescriptor(StddevAggregateDescriptor.FACTORY.createFunctionDescriptor());
+ }
+ };
+
+ private ScalarStddevAggregateDescriptor(IFunctionDescriptor aggFuncDesc) {
+ super(aggFuncDesc);
+ }
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return FID;
+ }
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/AbstractSerializableAvgAggregateFunction.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/AbstractSerializableAvgAggregateFunction.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/AbstractSerializableAvgAggregateFunction.java
index 563ff00..1270cdc 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/AbstractSerializableAvgAggregateFunction.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/AbstractSerializableAvgAggregateFunction.java
@@ -137,7 +137,13 @@ public abstract class AbstractSerializableAvgAggregateFunction extends AbstractS
} else if (aggType == ATypeTag.SYSTEM_NULL) {
aggType = typeTag;
} else if (typeTag != ATypeTag.SYSTEM_NULL && !ATypeHierarchy.isCompatible(typeTag, aggType)) {
- throw new IncompatibleTypeException(sourceLoc, BuiltinFunctions.AVG, bytes[offset], aggType.serialize());
+ if (typeTag.ordinal() > aggType.ordinal()) {
+ throw new IncompatibleTypeException(sourceLoc, BuiltinFunctions.AVG, bytes[offset],
+ aggType.serialize());
+ } else {
+ throw new IncompatibleTypeException(sourceLoc, BuiltinFunctions.AVG, aggType.serialize(),
+ bytes[offset]);
+ }
} else if (ATypeHierarchy.canPromote(aggType, typeTag)) {
aggType = typeTag;
}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/AbstractSerializableSingleVariableStatisticsAggregateFunction.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/AbstractSerializableSingleVariableStatisticsAggregateFunction.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/AbstractSerializableSingleVariableStatisticsAggregateFunction.java
new file mode 100644
index 0000000..0b16b68
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/AbstractSerializableSingleVariableStatisticsAggregateFunction.java
@@ -0,0 +1,296 @@
+/*
+ * 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.asterix.runtime.aggregates.serializable.std;
+
+import org.apache.asterix.common.config.GlobalConfig;
+import org.apache.asterix.dataflow.data.nontagged.serde.*;
+import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
+import org.apache.asterix.om.base.*;
+import org.apache.asterix.om.types.*;
+import org.apache.asterix.om.types.hierachy.ATypeHierarchy;
+import org.apache.asterix.runtime.aggregates.utils.SingleVarFunctionsUtil;
+import org.apache.asterix.runtime.evaluators.common.AccessibleByteArrayEval;
+import org.apache.asterix.runtime.evaluators.common.ClosedRecordConstructorEvalFactory.ClosedRecordConstructorEval;
+import org.apache.asterix.runtime.exceptions.IncompatibleTypeException;
+import org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
+import org.apache.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import org.apache.hyracks.api.exceptions.SourceLocation;
+
+import java.io.DataOutput;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+public abstract class AbstractSerializableSingleVariableStatisticsAggregateFunction
+ extends AbstractSerializableAggregateFunction {
+
+ /*
+ M1, M2, M3 and M4 are the 1st to 4th central moment of a data sample
+ */
+ private static final int M1_FIELD_ID = 0;
+ private static final int M2_FIELD_ID = 1;
+ private static final int COUNT_FIELD_ID = 2;
+
+ private static final int M1_OFFSET = 0;
+ private static final int M2_OFFSET = 8;
+ private static final int COUNT_OFFSET = 16;
+ protected static final int AGG_TYPE_OFFSET = 24;
+
+ private IPointable inputVal = new VoidPointable();
+ private IScalarEvaluator eval;
+ private AMutableDouble aDouble = new AMutableDouble(0);
+ private AMutableInt64 aInt64 = new AMutableInt64(0);
+ private SingleVarFunctionsUtil moments = new SingleVarFunctionsUtil();
+
+ private IPointable resultBytes = new VoidPointable();
+ private ByteArrayAccessibleOutputStream m1Bytes = new ByteArrayAccessibleOutputStream();
+ private DataOutput m1BytesOutput = new DataOutputStream(m1Bytes);
+ private ByteArrayAccessibleOutputStream m2Bytes = new ByteArrayAccessibleOutputStream();
+ private DataOutput m2BytesOutput = new DataOutputStream(m2Bytes);
+ private ByteArrayAccessibleOutputStream countBytes = new ByteArrayAccessibleOutputStream();
+ private DataOutput countBytesOutput = new DataOutputStream(countBytes);
+ private IScalarEvaluator evalM1 = new AccessibleByteArrayEval(m1Bytes);
+ private IScalarEvaluator evalM2 = new AccessibleByteArrayEval(m2Bytes);
+ private IScalarEvaluator evalCount = new AccessibleByteArrayEval(countBytes);
+ private ClosedRecordConstructorEval recordEval;
+
+ @SuppressWarnings("unchecked")
+ private ISerializerDeserializer<ADouble> doubleSerde =
+ SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
+ @SuppressWarnings("unchecked")
+ private ISerializerDeserializer<AInt64> longSerde =
+ SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
+ @SuppressWarnings("unchecked")
+ private ISerializerDeserializer<ANull> nullSerde =
+ SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ANULL);
+
+ public AbstractSerializableSingleVariableStatisticsAggregateFunction(IScalarEvaluatorFactory[] args,
+ IHyracksTaskContext context, SourceLocation sourceLoc) throws HyracksDataException {
+ super(sourceLoc);
+ eval = args[0].createScalarEvaluator(context);
+ }
+
+ @Override
+ public void init(DataOutput state) throws HyracksDataException {
+ try {
+ state.writeDouble(0.0);
+ state.writeDouble(0.0);
+ state.writeLong(0L);
+ state.writeByte(ATypeTag.SERIALIZED_SYSTEM_NULL_TYPE_TAG);
+ moments.set(0, 0, 0);
+ } catch (IOException e) {
+ throw HyracksDataException.create(e);
+ }
+ }
+
+ @Override
+ public abstract void step(IFrameTupleReference tuple, byte[] state, int start, int len) throws HyracksDataException;
+
+ @Override
+ public abstract void finish(byte[] state, int start, int len, DataOutput result) throws HyracksDataException;
+
+ @Override
+ public abstract void finishPartial(byte[] state, int start, int len, DataOutput result) throws HyracksDataException;
+
+ protected abstract void processNull(byte[] state, int start);
+
+ protected abstract FunctionIdentifier getFunctionIdentifier();
+
+ protected void processDataValues(IFrameTupleReference tuple, byte[] state, int start, int len)
+ throws HyracksDataException {
+ if (skipStep(state, start)) {
+ return;
+ }
+ eval.evaluate(tuple, inputVal);
+ byte[] bytes = inputVal.getByteArray();
+ int offset = inputVal.getStartOffset();
+
+ double m1 = BufferSerDeUtil.getDouble(state, start + M1_OFFSET);
+ double m2 = BufferSerDeUtil.getDouble(state, start + M2_OFFSET);
+ long count = BufferSerDeUtil.getLong(state, start + COUNT_OFFSET);
+ moments.set(m1, m2, count);
+
+ ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]);
+ ATypeTag aggType = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(state[start + AGG_TYPE_OFFSET]);
+ if (typeTag == ATypeTag.MISSING || typeTag == ATypeTag.NULL) {
+ processNull(state, start);
+ return;
+ } else if (aggType == ATypeTag.SYSTEM_NULL) {
+ aggType = typeTag;
+ } else if (typeTag != ATypeTag.SYSTEM_NULL && !ATypeHierarchy.isCompatible(typeTag, aggType)) {
+ if (typeTag.ordinal() > aggType.ordinal()) {
+ throw new IncompatibleTypeException(sourceLoc, getFunctionIdentifier(), bytes[offset],
+ aggType.serialize());
+ } else {
+ throw new IncompatibleTypeException(sourceLoc, getFunctionIdentifier(), aggType.serialize(),
+ bytes[offset]);
+ }
+ } else if (ATypeHierarchy.canPromote(aggType, typeTag)) {
+ aggType = typeTag;
+ }
+ double val;
+ switch (typeTag) {
+ case TINYINT:
+ val = AInt8SerializerDeserializer.getByte(bytes, offset + 1);
+ moments.push(val);
+ break;
+ case SMALLINT:
+ val = AInt16SerializerDeserializer.getShort(bytes, offset + 1);
+ moments.push(val);
+ break;
+ case INTEGER:
+ val = AInt32SerializerDeserializer.getInt(bytes, offset + 1);
+ moments.push(val);
+ break;
+ case BIGINT:
+ val = AInt64SerializerDeserializer.getLong(bytes, offset + 1);
+ moments.push(val);
+ break;
+ case FLOAT:
+ val = AFloatSerializerDeserializer.getFloat(bytes, offset + 1);
+ moments.push(val);
+ break;
+ case DOUBLE:
+ val = ADoubleSerializerDeserializer.getDouble(bytes, offset + 1);
+ moments.push(val);
+ break;
+ default:
+ throw new UnsupportedItemTypeException(sourceLoc, getFunctionIdentifier(), bytes[offset]);
+ }
+ BufferSerDeUtil.writeDouble(moments.getM1(), state, start + M1_OFFSET);
+ BufferSerDeUtil.writeDouble(moments.getM2(), state, start + M2_OFFSET);
+ BufferSerDeUtil.writeLong(moments.getCount(), state, start + COUNT_OFFSET);
+ state[start + AGG_TYPE_OFFSET] = aggType.serialize();
+ }
+
+ protected void finishPartialResults(byte[] state, int start, int len, DataOutput result)
+ throws HyracksDataException {
+ double m1 = BufferSerDeUtil.getDouble(state, start + M1_OFFSET);
+ double m2 = BufferSerDeUtil.getDouble(state, start + M2_OFFSET);
+ long count = BufferSerDeUtil.getLong(state, start + COUNT_OFFSET);
+ ATypeTag aggType = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(state[start + AGG_TYPE_OFFSET]);
+ if (recordEval == null) {
+ ARecordType recType = new ARecordType(null, new String[] { "m1", "m2", "count" },
+ new IAType[] { BuiltinType.ADOUBLE, BuiltinType.ADOUBLE, BuiltinType.AINT64 }, false);
+ recordEval = new ClosedRecordConstructorEval(recType, new IScalarEvaluator[] { evalM1, evalM2, evalCount });
+ }
+
+ try {
+ if (aggType == ATypeTag.SYSTEM_NULL) {
+ if (GlobalConfig.DEBUG) {
+ GlobalConfig.ASTERIX_LOGGER.trace("Single Var statistics aggregate ran over empty input.");
+ }
+ result.writeByte(ATypeTag.SERIALIZED_SYSTEM_NULL_TYPE_TAG);
+ } else if (aggType == ATypeTag.NULL) {
+ result.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
+ } else {
+ m1Bytes.reset();
+ aDouble.setValue(m1);
+ doubleSerde.serialize(aDouble, m1BytesOutput);
+ m2Bytes.reset();
+ aDouble.setValue(m2);
+ doubleSerde.serialize(aDouble, m2BytesOutput);
+ countBytes.reset();
+ aInt64.setValue(count);
+ longSerde.serialize(aInt64, countBytesOutput);
+ recordEval.evaluate(null, resultBytes);
+ result.write(resultBytes.getByteArray(), resultBytes.getStartOffset(), resultBytes.getLength());
+ }
+ } catch (IOException e) {
+ throw HyracksDataException.create(e);
+ }
+ }
+
+ protected void processPartialResults(IFrameTupleReference tuple, byte[] state, int start, int len)
+ throws HyracksDataException {
+ if (skipStep(state, start)) {
+ return;
+ }
+ double m1 = BufferSerDeUtil.getDouble(state, start + M1_OFFSET);
+ double m2 = BufferSerDeUtil.getDouble(state, start + M2_OFFSET);
+ long count = BufferSerDeUtil.getLong(state, start + COUNT_OFFSET);
+ moments.set(m1, m2, count);
+
+ eval.evaluate(tuple, inputVal);
+ byte[] serBytes = inputVal.getByteArray();
+ int offset = inputVal.getStartOffset();
+
+ ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serBytes[offset]);
+ switch (typeTag) {
+ case NULL:
+ processNull(state, start);
+ break;
+ case SYSTEM_NULL:
+ // Ignore and return.
+ break;
+ case OBJECT:
+ // Expected.
+ ATypeTag aggType = ATypeTag.DOUBLE;
+ int nullBitmapSize = 0;
+ int offset1 = ARecordSerializerDeserializer.getFieldOffsetById(serBytes, offset, M1_FIELD_ID,
+ nullBitmapSize, false);
+ int offset2 = ARecordSerializerDeserializer.getFieldOffsetById(serBytes, offset, M2_FIELD_ID,
+ nullBitmapSize, false);
+ int offset3 = ARecordSerializerDeserializer.getFieldOffsetById(serBytes, offset, COUNT_FIELD_ID,
+ nullBitmapSize, false);
+ double temp_m1 = ADoubleSerializerDeserializer.getDouble(serBytes, offset1);
+ double temp_m2 = ADoubleSerializerDeserializer.getDouble(serBytes, offset2);
+ long temp_count = AInt64SerializerDeserializer.getLong(serBytes, offset3);
+ moments.combine(temp_m1, temp_m2, temp_count);
+
+ BufferSerDeUtil.writeDouble(moments.getM1(), state, start + M1_OFFSET);
+ BufferSerDeUtil.writeDouble(moments.getM2(), state, start + M2_OFFSET);
+ BufferSerDeUtil.writeLong(moments.getCount(), state, start + COUNT_OFFSET);
+ state[start + AGG_TYPE_OFFSET] = aggType.serialize();
+ break;
+ default:
+ throw new UnsupportedItemTypeException(sourceLoc, getFunctionIdentifier(), serBytes[offset]);
+ }
+ }
+
+ protected void finishStddevFinalResults(byte[] state, int start, int len, DataOutput result)
+ throws HyracksDataException {
+ double m2 = BufferSerDeUtil.getDouble(state, start + M2_OFFSET);
+ long count = BufferSerDeUtil.getLong(state, start + COUNT_OFFSET);
+ ATypeTag aggType = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(state[start + AGG_TYPE_OFFSET]);
+ try {
+ if (count <= 1 || aggType == ATypeTag.NULL) {
+ nullSerde.serialize(ANull.NULL, result);
+ } else {
+ aDouble.setValue(Math.sqrt(m2 / (count - 1)));
+ doubleSerde.serialize(aDouble, result);
+ }
+ } catch (IOException e) {
+ throw HyracksDataException.create(e);
+ }
+ }
+
+ protected boolean skipStep(byte[] state, int start) {
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/AbstractSerializableSumAggregateFunction.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/AbstractSerializableSumAggregateFunction.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/AbstractSerializableSumAggregateFunction.java
index a4e1090..132fd54 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/AbstractSerializableSumAggregateFunction.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/AbstractSerializableSumAggregateFunction.java
@@ -101,7 +101,13 @@ public abstract class AbstractSerializableSumAggregateFunction extends AbstractS
} else if (aggType == ATypeTag.SYSTEM_NULL) {
aggType = typeTag;
} else if (typeTag != ATypeTag.SYSTEM_NULL && !ATypeHierarchy.isCompatible(typeTag, aggType)) {
- throw new IncompatibleTypeException(sourceLoc, BuiltinFunctions.SUM, bytes[offset], aggType.serialize());
+ if (typeTag.ordinal() > aggType.ordinal()) {
+ throw new IncompatibleTypeException(sourceLoc, BuiltinFunctions.SUM, bytes[offset],
+ aggType.serialize());
+ } else {
+ throw new IncompatibleTypeException(sourceLoc, BuiltinFunctions.SUM, aggType.serialize(),
+ bytes[offset]);
+ }
}
if (ATypeHierarchy.canPromote(aggType, typeTag)) {
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableGlobalSqlStddevAggregateDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableGlobalSqlStddevAggregateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableGlobalSqlStddevAggregateDescriptor.java
new file mode 100644
index 0000000..d06c6aa
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableGlobalSqlStddevAggregateDescriptor.java
@@ -0,0 +1,63 @@
+/*
+ * 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.asterix.runtime.aggregates.serializable.std;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptor;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.runtime.aggregates.base.AbstractSerializableAggregateFunctionDynamicDescriptor;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.ISerializedAggregateEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.ISerializedAggregateEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+public class SerializableGlobalSqlStddevAggregateDescriptor
+ extends AbstractSerializableAggregateFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new SerializableGlobalSqlStddevAggregateDescriptor();
+ }
+ };
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return BuiltinFunctions.SERIAL_GLOBAL_SQL_STDDEV;
+ }
+
+ @Override
+ public ISerializedAggregateEvaluatorFactory createSerializableAggregateEvaluatorFactory(
+ final IScalarEvaluatorFactory[] args) {
+ return new ISerializedAggregateEvaluatorFactory() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public ISerializedAggregateEvaluator createAggregateEvaluator(IHyracksTaskContext ctx)
+ throws HyracksDataException {
+ return new SerializableGlobalSqlStddevAggregateFunction(args, ctx, sourceLoc);
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableGlobalSqlStddevAggregateFunction.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableGlobalSqlStddevAggregateFunction.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableGlobalSqlStddevAggregateFunction.java
new file mode 100644
index 0000000..1be87f6
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableGlobalSqlStddevAggregateFunction.java
@@ -0,0 +1,64 @@
+/*
+ * 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.asterix.runtime.aggregates.serializable.std;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.SourceLocation;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+import java.io.DataOutput;
+
+public class SerializableGlobalSqlStddevAggregateFunction
+ extends AbstractSerializableSingleVariableStatisticsAggregateFunction {
+
+ public SerializableGlobalSqlStddevAggregateFunction(IScalarEvaluatorFactory[] args, IHyracksTaskContext context,
+ SourceLocation sourceLoc) throws HyracksDataException {
+ super(args, context, sourceLoc);
+ }
+
+ @Override
+ public void step(IFrameTupleReference tuple, byte[] state, int start, int len) throws HyracksDataException {
+ processPartialResults(tuple, state, start, len);
+ }
+
+ @Override
+ public void finish(byte[] state, int start, int len, DataOutput result) throws HyracksDataException {
+ finishStddevFinalResults(state, start, len, result);
+ }
+
+ @Override
+ public void finishPartial(byte[] state, int start, int len, DataOutput result) throws HyracksDataException {
+ finishPartialResults(state, start, len, result);
+ }
+
+ @Override
+ protected void processNull(byte[] state, int start) {
+ }
+
+ @Override
+ protected FunctionIdentifier getFunctionIdentifier() {
+ return BuiltinFunctions.STDDEV;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableGlobalStddevAggregateDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableGlobalStddevAggregateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableGlobalStddevAggregateDescriptor.java
new file mode 100644
index 0000000..f17ef2f
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableGlobalStddevAggregateDescriptor.java
@@ -0,0 +1,63 @@
+/*
+ * 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.asterix.runtime.aggregates.serializable.std;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptor;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.runtime.aggregates.base.AbstractSerializableAggregateFunctionDynamicDescriptor;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.ISerializedAggregateEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.ISerializedAggregateEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+public class SerializableGlobalStddevAggregateDescriptor
+ extends AbstractSerializableAggregateFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new SerializableGlobalStddevAggregateDescriptor();
+ }
+ };
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return BuiltinFunctions.SERIAL_GLOBAL_STDDEV;
+ }
+
+ @Override
+ public ISerializedAggregateEvaluatorFactory createSerializableAggregateEvaluatorFactory(
+ final IScalarEvaluatorFactory[] args) {
+ return new ISerializedAggregateEvaluatorFactory() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public ISerializedAggregateEvaluator createAggregateEvaluator(IHyracksTaskContext ctx)
+ throws HyracksDataException {
+ return new SerializableGlobalStddevAggregateFunction(args, ctx, sourceLoc);
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableGlobalStddevAggregateFunction.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableGlobalStddevAggregateFunction.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableGlobalStddevAggregateFunction.java
new file mode 100644
index 0000000..b15cffd
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableGlobalStddevAggregateFunction.java
@@ -0,0 +1,73 @@
+/*
+ * 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.asterix.runtime.aggregates.serializable.std;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.EnumDeserializer;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.SourceLocation;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+import java.io.DataOutput;
+
+public class SerializableGlobalStddevAggregateFunction
+ extends AbstractSerializableSingleVariableStatisticsAggregateFunction {
+
+ public SerializableGlobalStddevAggregateFunction(IScalarEvaluatorFactory[] args, IHyracksTaskContext context,
+ SourceLocation sourceLoc) throws HyracksDataException {
+ super(args, context, sourceLoc);
+ }
+
+ @Override
+ public void step(IFrameTupleReference tuple, byte[] state, int start, int len) throws HyracksDataException {
+ processPartialResults(tuple, state, start, len);
+ }
+
+ @Override
+ public void finish(byte[] state, int start, int len, DataOutput result) throws HyracksDataException {
+ finishStddevFinalResults(state, start, len, result);
+ }
+
+ @Override
+ public void finishPartial(byte[] state, int start, int len, DataOutput result) throws HyracksDataException {
+ finishPartialResults(state, start, len, result);
+ }
+
+ @Override
+ protected void processNull(byte[] state, int start) {
+ state[start + AGG_TYPE_OFFSET] = ATypeTag.SERIALIZED_NULL_TYPE_TAG;
+ }
+
+ @Override
+ protected boolean skipStep(byte[] state, int start) {
+ ATypeTag aggType = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(state[start + AGG_TYPE_OFFSET]);
+ return aggType == ATypeTag.NULL;
+ }
+
+ @Override
+ protected FunctionIdentifier getFunctionIdentifier() {
+ return BuiltinFunctions.STDDEV;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableIntermediateSqlStddevAggregateDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableIntermediateSqlStddevAggregateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableIntermediateSqlStddevAggregateDescriptor.java
new file mode 100644
index 0000000..e5d788a
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableIntermediateSqlStddevAggregateDescriptor.java
@@ -0,0 +1,63 @@
+/*
+ * 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.asterix.runtime.aggregates.serializable.std;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptor;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.runtime.aggregates.base.AbstractSerializableAggregateFunctionDynamicDescriptor;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.ISerializedAggregateEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.ISerializedAggregateEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+public class SerializableIntermediateSqlStddevAggregateDescriptor
+ extends AbstractSerializableAggregateFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new SerializableIntermediateSqlStddevAggregateDescriptor();
+ }
+ };
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return BuiltinFunctions.SERIAL_INTERMEDIATE_SQL_STDDEV;
+ }
+
+ @Override
+ public ISerializedAggregateEvaluatorFactory createSerializableAggregateEvaluatorFactory(
+ final IScalarEvaluatorFactory[] args) {
+ return new ISerializedAggregateEvaluatorFactory() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public ISerializedAggregateEvaluator createAggregateEvaluator(IHyracksTaskContext ctx)
+ throws HyracksDataException {
+ return new SerializableIntermediateSqlStddevAggregateFunction(args, ctx, sourceLoc);
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableIntermediateSqlStddevAggregateFunction.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableIntermediateSqlStddevAggregateFunction.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableIntermediateSqlStddevAggregateFunction.java
new file mode 100644
index 0000000..498801b
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableIntermediateSqlStddevAggregateFunction.java
@@ -0,0 +1,63 @@
+/*
+ * 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.asterix.runtime.aggregates.serializable.std;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.SourceLocation;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+import java.io.DataOutput;
+
+public class SerializableIntermediateSqlStddevAggregateFunction
+ extends AbstractSerializableSingleVariableStatisticsAggregateFunction {
+
+ public SerializableIntermediateSqlStddevAggregateFunction(IScalarEvaluatorFactory[] args,
+ IHyracksTaskContext context, SourceLocation sourceLoc) throws HyracksDataException {
+ super(args, context, sourceLoc);
+ }
+
+ @Override
+ public void step(IFrameTupleReference tuple, byte[] state, int start, int len) throws HyracksDataException {
+ processPartialResults(tuple, state, start, len);
+ }
+
+ @Override
+ public void finish(byte[] state, int start, int len, DataOutput result) throws HyracksDataException {
+ finishPartialResults(state, start, len, result);
+ }
+
+ @Override
+ public void finishPartial(byte[] state, int start, int len, DataOutput result) throws HyracksDataException {
+ finishPartialResults(state, start, len, result);
+ }
+
+ @Override
+ protected void processNull(byte[] state, int start) {
+ }
+
+ @Override
+ protected FunctionIdentifier getFunctionIdentifier() {
+ return BuiltinFunctions.STDDEV;
+ }
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableIntermediateStddevAggregateDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableIntermediateStddevAggregateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableIntermediateStddevAggregateDescriptor.java
new file mode 100644
index 0000000..d17e5b7
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableIntermediateStddevAggregateDescriptor.java
@@ -0,0 +1,63 @@
+/*
+ * 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.asterix.runtime.aggregates.serializable.std;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptor;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.runtime.aggregates.base.AbstractSerializableAggregateFunctionDynamicDescriptor;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.ISerializedAggregateEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.ISerializedAggregateEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+public class SerializableIntermediateStddevAggregateDescriptor
+ extends AbstractSerializableAggregateFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new SerializableIntermediateStddevAggregateDescriptor();
+ }
+ };
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return BuiltinFunctions.SERIAL_INTERMEDIATE_STDDEV;
+ }
+
+ @Override
+ public ISerializedAggregateEvaluatorFactory createSerializableAggregateEvaluatorFactory(
+ final IScalarEvaluatorFactory[] args) {
+ return new ISerializedAggregateEvaluatorFactory() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public ISerializedAggregateEvaluator createAggregateEvaluator(IHyracksTaskContext ctx)
+ throws HyracksDataException {
+ return new SerializableIntermediateStddevAggregateFunction(args, ctx, sourceLoc);
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableIntermediateStddevAggregateFunction.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableIntermediateStddevAggregateFunction.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableIntermediateStddevAggregateFunction.java
new file mode 100644
index 0000000..8bc8e14
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableIntermediateStddevAggregateFunction.java
@@ -0,0 +1,73 @@
+/*
+ * 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.asterix.runtime.aggregates.serializable.std;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.EnumDeserializer;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.SourceLocation;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+import java.io.DataOutput;
+
+public class SerializableIntermediateStddevAggregateFunction
+ extends AbstractSerializableSingleVariableStatisticsAggregateFunction {
+
+ public SerializableIntermediateStddevAggregateFunction(IScalarEvaluatorFactory[] args, IHyracksTaskContext context,
+ SourceLocation sourceLoc) throws HyracksDataException {
+ super(args, context, sourceLoc);
+ }
+
+ @Override
+ public void step(IFrameTupleReference tuple, byte[] state, int start, int len) throws HyracksDataException {
+ processPartialResults(tuple, state, start, len);
+ }
+
+ @Override
+ public void finish(byte[] state, int start, int len, DataOutput result) throws HyracksDataException {
+ finishPartialResults(state, start, len, result);
+ }
+
+ @Override
+ public void finishPartial(byte[] state, int start, int len, DataOutput result) throws HyracksDataException {
+ finishPartialResults(state, start, len, result);
+ }
+
+ @Override
+ protected void processNull(byte[] state, int start) {
+ state[start + AGG_TYPE_OFFSET] = ATypeTag.SERIALIZED_NULL_TYPE_TAG;
+ }
+
+ @Override
+ protected boolean skipStep(byte[] state, int start) {
+ ATypeTag aggType = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(state[start + AGG_TYPE_OFFSET]);
+ return aggType == ATypeTag.NULL;
+ }
+
+ @Override
+ protected FunctionIdentifier getFunctionIdentifier() {
+ return BuiltinFunctions.STDDEV;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableLocalSqlStddevAggregateDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableLocalSqlStddevAggregateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableLocalSqlStddevAggregateDescriptor.java
new file mode 100644
index 0000000..9fd7381
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableLocalSqlStddevAggregateDescriptor.java
@@ -0,0 +1,63 @@
+/*
+ * 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.asterix.runtime.aggregates.serializable.std;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptor;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.runtime.aggregates.base.AbstractSerializableAggregateFunctionDynamicDescriptor;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.ISerializedAggregateEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.ISerializedAggregateEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+public class SerializableLocalSqlStddevAggregateDescriptor
+ extends AbstractSerializableAggregateFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new SerializableLocalSqlStddevAggregateDescriptor();
+ }
+ };
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return BuiltinFunctions.SERIAL_LOCAL_SQL_STDDEV;
+ }
+
+ @Override
+ public ISerializedAggregateEvaluatorFactory createSerializableAggregateEvaluatorFactory(
+ final IScalarEvaluatorFactory[] args) {
+ return new ISerializedAggregateEvaluatorFactory() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public ISerializedAggregateEvaluator createAggregateEvaluator(IHyracksTaskContext ctx)
+ throws HyracksDataException {
+ return new SerializableLocalSqlStddevAggregateFunction(args, ctx, sourceLoc);
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableLocalSqlStddevAggregateFunction.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableLocalSqlStddevAggregateFunction.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableLocalSqlStddevAggregateFunction.java
new file mode 100644
index 0000000..d0ef10e
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableLocalSqlStddevAggregateFunction.java
@@ -0,0 +1,63 @@
+/*
+ * 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.asterix.runtime.aggregates.serializable.std;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.SourceLocation;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+import java.io.DataOutput;
+
+public class SerializableLocalSqlStddevAggregateFunction
+ extends AbstractSerializableSingleVariableStatisticsAggregateFunction {
+
+ public SerializableLocalSqlStddevAggregateFunction(IScalarEvaluatorFactory[] args, IHyracksTaskContext context,
+ SourceLocation sourceLoc) throws HyracksDataException {
+ super(args, context, sourceLoc);
+ }
+
+ @Override
+ public void step(IFrameTupleReference tuple, byte[] state, int start, int len) throws HyracksDataException {
+ processDataValues(tuple, state, start, len);
+ }
+
+ @Override
+ public void finish(byte[] state, int start, int len, DataOutput result) throws HyracksDataException {
+ finishPartialResults(state, start, len, result);
+ }
+
+ @Override
+ public void finishPartial(byte[] state, int start, int len, DataOutput result) throws HyracksDataException {
+ finish(state, start, len, result);
+ }
+
+ @Override
+ protected void processNull(byte[] state, int start) {
+ }
+
+ @Override
+ protected FunctionIdentifier getFunctionIdentifier() {
+ return BuiltinFunctions.STDDEV;
+ }
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableLocalStddevAggregateDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableLocalStddevAggregateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableLocalStddevAggregateDescriptor.java
new file mode 100644
index 0000000..f4d3bd8
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableLocalStddevAggregateDescriptor.java
@@ -0,0 +1,62 @@
+/*
+ * 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.asterix.runtime.aggregates.serializable.std;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptor;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.runtime.aggregates.base.AbstractSerializableAggregateFunctionDynamicDescriptor;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.ISerializedAggregateEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.ISerializedAggregateEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+public class SerializableLocalStddevAggregateDescriptor extends AbstractSerializableAggregateFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new SerializableLocalStddevAggregateDescriptor();
+ }
+ };
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return BuiltinFunctions.SERIAL_LOCAL_STDDEV;
+ }
+
+ @Override
+ public ISerializedAggregateEvaluatorFactory createSerializableAggregateEvaluatorFactory(
+ final IScalarEvaluatorFactory[] args) {
+ return new ISerializedAggregateEvaluatorFactory() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public ISerializedAggregateEvaluator createAggregateEvaluator(IHyracksTaskContext ctx)
+ throws HyracksDataException {
+ return new SerializableLocalStddevAggregateFunction(args, ctx, sourceLoc);
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableLocalStddevAggregateFunction.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableLocalStddevAggregateFunction.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableLocalStddevAggregateFunction.java
new file mode 100644
index 0000000..3693d4b
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableLocalStddevAggregateFunction.java
@@ -0,0 +1,72 @@
+/*
+ * 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.asterix.runtime.aggregates.serializable.std;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.EnumDeserializer;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.SourceLocation;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+import java.io.DataOutput;
+
+public class SerializableLocalStddevAggregateFunction
+ extends AbstractSerializableSingleVariableStatisticsAggregateFunction {
+
+ public SerializableLocalStddevAggregateFunction(IScalarEvaluatorFactory[] args, IHyracksTaskContext context,
+ SourceLocation sourceLoc) throws HyracksDataException {
+ super(args, context, sourceLoc);
+ }
+
+ @Override
+ public void step(IFrameTupleReference tuple, byte[] state, int start, int len) throws HyracksDataException {
+ processDataValues(tuple, state, start, len);
+ }
+
+ @Override
+ public void finish(byte[] state, int start, int len, DataOutput result) throws HyracksDataException {
+ finishPartialResults(state, start, len, result);
+ }
+
+ @Override
+ public void finishPartial(byte[] state, int start, int len, DataOutput result) throws HyracksDataException {
+ finish(state, start, len, result);
+ }
+
+ @Override
+ protected void processNull(byte[] state, int start) {
+ state[start + AGG_TYPE_OFFSET] = ATypeTag.SERIALIZED_NULL_TYPE_TAG;
+ }
+
+ @Override
+ protected boolean skipStep(byte[] state, int start) {
+ ATypeTag aggType = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(state[start + AGG_TYPE_OFFSET]);
+ return aggType == ATypeTag.NULL;
+ }
+
+ @Override
+ protected FunctionIdentifier getFunctionIdentifier() {
+ return BuiltinFunctions.STDDEV;
+ }
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ab4bed0c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableSqlStddevAggregateDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableSqlStddevAggregateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableSqlStddevAggregateDescriptor.java
new file mode 100644
index 0000000..a2c2a16
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/serializable/std/SerializableSqlStddevAggregateDescriptor.java
@@ -0,0 +1,60 @@
+/*
+ * 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.asterix.runtime.aggregates.serializable.std;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptor;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.runtime.aggregates.base.AbstractSerializableAggregateFunctionDynamicDescriptor;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.ISerializedAggregateEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.ISerializedAggregateEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+public class SerializableSqlStddevAggregateDescriptor extends AbstractSerializableAggregateFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new SerializableSqlStddevAggregateDescriptor();
+ }
+ };
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return BuiltinFunctions.SERIAL_SQL_STDDEV;
+ }
+
+ @Override
+ public ISerializedAggregateEvaluatorFactory createSerializableAggregateEvaluatorFactory(
+ final IScalarEvaluatorFactory[] args) {
+ return new ISerializedAggregateEvaluatorFactory() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public ISerializedAggregateEvaluator createAggregateEvaluator(IHyracksTaskContext ctx)
+ throws HyracksDataException {
+ return new SerializableSqlStddevAggregateFunction(args, ctx, sourceLoc);
+ }
+ };
+ }
+}