Repository: asterixdb Updated Branches: refs/heads/master 776e1c25b -> 2a42da456
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/2a42da45/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/LocalSqlVarPopAggregateDescriptor.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/LocalSqlVarPopAggregateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/LocalSqlVarPopAggregateDescriptor.java new file mode 100644 index 0000000..c636538 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/LocalSqlVarPopAggregateDescriptor.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.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.AbstractAggregateFunctionDynamicDescriptor; +import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator; +import org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluatorFactory; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; +import org.apache.hyracks.api.context.IHyracksTaskContext; +import org.apache.hyracks.api.exceptions.HyracksDataException; + +public class LocalSqlVarPopAggregateDescriptor extends AbstractAggregateFunctionDynamicDescriptor { + + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new LocalSqlVarPopAggregateDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return BuiltinFunctions.LOCAL_SQL_VAR_POP; + } + + @Override + public IAggregateEvaluatorFactory createAggregateEvaluatorFactory(final IScalarEvaluatorFactory[] args) { + return new IAggregateEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IAggregateEvaluator createAggregateEvaluator(final IHyracksTaskContext ctx) + throws HyracksDataException { + return new LocalSqlVarAggregateFunction(args, ctx, true, sourceLoc); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/2a42da45/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/LocalVarAggregateDescriptor.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/LocalVarAggregateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/LocalVarAggregateDescriptor.java new file mode 100644 index 0000000..f25364a --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/LocalVarAggregateDescriptor.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.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.AbstractAggregateFunctionDynamicDescriptor; +import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator; +import org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluatorFactory; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; +import org.apache.hyracks.api.context.IHyracksTaskContext; +import org.apache.hyracks.api.exceptions.HyracksDataException; + +public class LocalVarAggregateDescriptor extends AbstractAggregateFunctionDynamicDescriptor { + + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new LocalVarAggregateDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return BuiltinFunctions.LOCAL_VAR; + } + + @Override + public IAggregateEvaluatorFactory createAggregateEvaluatorFactory(final IScalarEvaluatorFactory[] args) { + return new IAggregateEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IAggregateEvaluator createAggregateEvaluator(final IHyracksTaskContext ctx) + throws HyracksDataException { + return new LocalVarAggregateFunction(args, ctx, false, sourceLoc); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/2a42da45/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/LocalVarAggregateFunction.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/LocalVarAggregateFunction.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/LocalVarAggregateFunction.java new file mode 100644 index 0000000..41ec26d --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/LocalVarAggregateFunction.java @@ -0,0 +1,76 @@ +/* + * 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.std; + +import org.apache.asterix.om.functions.BuiltinFunctions; +import org.apache.asterix.om.types.ATypeTag; +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.data.std.api.IPointable; +import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference; + +public class LocalVarAggregateFunction extends AbstractSingleVarStatisticsAggregateFunction { + + private final boolean isPop; + + public LocalVarAggregateFunction(IScalarEvaluatorFactory[] args, IHyracksTaskContext context, boolean isPop, + SourceLocation sourceLoc) throws HyracksDataException { + super(args, context, sourceLoc); + this.isPop = isPop; + } + + @Override + public void step(IFrameTupleReference tuple) throws HyracksDataException { + processDataValues(tuple); + } + + @Override + public void finish(IPointable result) throws HyracksDataException { + finishPartialResults(result); + } + + @Override + public void finishPartial(IPointable result) throws HyracksDataException { + finish(result); + } + + @Override + protected void processNull() { + aggType = ATypeTag.NULL; + } + + @Override + protected boolean skipStep() { + return aggType == ATypeTag.NULL; + } + + @Override + protected FunctionIdentifier getFunctionIdentifier() { + if (isPop) { + return BuiltinFunctions.VAR_POP; + } else { + return BuiltinFunctions.VAR; + } + } + +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/2a42da45/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/LocalVarPopAggregateDescriptor.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/LocalVarPopAggregateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/LocalVarPopAggregateDescriptor.java new file mode 100644 index 0000000..0e31b7b --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/LocalVarPopAggregateDescriptor.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.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.AbstractAggregateFunctionDynamicDescriptor; +import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator; +import org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluatorFactory; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; +import org.apache.hyracks.api.context.IHyracksTaskContext; +import org.apache.hyracks.api.exceptions.HyracksDataException; + +public class LocalVarPopAggregateDescriptor extends AbstractAggregateFunctionDynamicDescriptor { + + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new LocalVarPopAggregateDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return BuiltinFunctions.LOCAL_VAR_POP; + } + + @Override + public IAggregateEvaluatorFactory createAggregateEvaluatorFactory(final IScalarEvaluatorFactory[] args) { + return new IAggregateEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IAggregateEvaluator createAggregateEvaluator(final IHyracksTaskContext ctx) + throws HyracksDataException { + return new LocalVarAggregateFunction(args, ctx, true, sourceLoc); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/2a42da45/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/SqlVarAggregateDescriptor.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/SqlVarAggregateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/SqlVarAggregateDescriptor.java new file mode 100644 index 0000000..aaa4863 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/SqlVarAggregateDescriptor.java @@ -0,0 +1,61 @@ +/* + * 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.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.AbstractAggregateFunctionDynamicDescriptor; +import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator; +import org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluatorFactory; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; +import org.apache.hyracks.api.context.IHyracksTaskContext; +import org.apache.hyracks.api.exceptions.HyracksDataException; + +public class SqlVarAggregateDescriptor extends AbstractAggregateFunctionDynamicDescriptor { + + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new SqlVarAggregateDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return BuiltinFunctions.SQL_VAR; + } + + @Override + public IAggregateEvaluatorFactory createAggregateEvaluatorFactory(final IScalarEvaluatorFactory[] args) { + return new IAggregateEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IAggregateEvaluator createAggregateEvaluator(final IHyracksTaskContext ctx) + throws HyracksDataException { + return new SqlVarAggregateFunction(args, ctx, false, sourceLoc); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/2a42da45/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/SqlVarAggregateFunction.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/SqlVarAggregateFunction.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/SqlVarAggregateFunction.java new file mode 100644 index 0000000..e1c8793 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/SqlVarAggregateFunction.java @@ -0,0 +1,74 @@ +/* + * 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.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.data.std.api.IPointable; +import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference; + +public class SqlVarAggregateFunction extends AbstractSingleVarStatisticsAggregateFunction { + + private final boolean isPop; + private final int delta; + + public SqlVarAggregateFunction(IScalarEvaluatorFactory[] args, IHyracksTaskContext context, boolean isPop, + SourceLocation sourceLoc) throws HyracksDataException { + super(args, context, sourceLoc); + this.isPop = isPop; + if (isPop) { + delta = 0; + } else { + delta = 1; + } + } + + @Override + public void step(IFrameTupleReference tuple) throws HyracksDataException { + processDataValues(tuple); + } + + @Override + public void finish(IPointable result) throws HyracksDataException { + finishVarFinalResults(result, delta); + } + + @Override + public void finishPartial(IPointable result) throws HyracksDataException { + finishPartialResults(result); + } + + @Override + protected void processNull() { + } + + @Override + protected FunctionIdentifier getFunctionIdentifier() { + if (isPop) { + return BuiltinFunctions.VAR_POP; + } else { + return BuiltinFunctions.VAR; + } + } +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/2a42da45/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/SqlVarPopAggregateDescriptor.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/SqlVarPopAggregateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/SqlVarPopAggregateDescriptor.java new file mode 100644 index 0000000..0e79da6 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/SqlVarPopAggregateDescriptor.java @@ -0,0 +1,61 @@ +/* + * 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.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.AbstractAggregateFunctionDynamicDescriptor; +import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator; +import org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluatorFactory; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; +import org.apache.hyracks.api.context.IHyracksTaskContext; +import org.apache.hyracks.api.exceptions.HyracksDataException; + +public class SqlVarPopAggregateDescriptor extends AbstractAggregateFunctionDynamicDescriptor { + + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new SqlVarPopAggregateDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return BuiltinFunctions.SQL_VAR_POP; + } + + @Override + public IAggregateEvaluatorFactory createAggregateEvaluatorFactory(final IScalarEvaluatorFactory[] args) { + return new IAggregateEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IAggregateEvaluator createAggregateEvaluator(final IHyracksTaskContext ctx) + throws HyracksDataException { + return new SqlVarAggregateFunction(args, ctx, true, sourceLoc); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/2a42da45/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/VarAggregateDescriptor.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/VarAggregateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/VarAggregateDescriptor.java new file mode 100644 index 0000000..5e36fba --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/VarAggregateDescriptor.java @@ -0,0 +1,61 @@ +/* + * 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.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.AbstractAggregateFunctionDynamicDescriptor; +import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator; +import org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluatorFactory; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; +import org.apache.hyracks.api.context.IHyracksTaskContext; +import org.apache.hyracks.api.exceptions.HyracksDataException; + +public class VarAggregateDescriptor extends AbstractAggregateFunctionDynamicDescriptor { + + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new VarAggregateDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return BuiltinFunctions.VAR; + } + + @Override + public IAggregateEvaluatorFactory createAggregateEvaluatorFactory(final IScalarEvaluatorFactory[] args) { + return new IAggregateEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IAggregateEvaluator createAggregateEvaluator(final IHyracksTaskContext ctx) + throws HyracksDataException { + return new VarAggregateFunction(args, ctx, false, sourceLoc); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/2a42da45/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/VarAggregateFunction.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/VarAggregateFunction.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/VarAggregateFunction.java new file mode 100644 index 0000000..aed39ee --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/VarAggregateFunction.java @@ -0,0 +1,82 @@ +/* + * 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.std; + +import org.apache.asterix.om.functions.BuiltinFunctions; +import org.apache.asterix.om.types.ATypeTag; +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.data.std.api.IPointable; +import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference; + +public class VarAggregateFunction extends AbstractSingleVarStatisticsAggregateFunction { + + private final boolean isPop; + private final int delta; + + public VarAggregateFunction(IScalarEvaluatorFactory[] args, IHyracksTaskContext context, boolean isPop, + SourceLocation sourceLoc) throws HyracksDataException { + super(args, context, sourceLoc); + this.isPop = isPop; + if (isPop) { + delta = 0; + } else { + delta = 1; + } + } + + @Override + public void step(IFrameTupleReference tuple) throws HyracksDataException { + processDataValues(tuple); + } + + @Override + public void finish(IPointable result) throws HyracksDataException { + finishVarFinalResults(result, delta); + } + + @Override + public void finishPartial(IPointable result) throws HyracksDataException { + finish(result); + } + + @Override + protected void processNull() { + aggType = ATypeTag.NULL; + } + + @Override + protected boolean skipStep() { + return aggType == ATypeTag.NULL; + } + + @Override + protected FunctionIdentifier getFunctionIdentifier() { + if (isPop) { + return BuiltinFunctions.VAR_POP; + } else { + return BuiltinFunctions.VAR; + } + } + +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/2a42da45/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/VarPopAggregateDescriptor.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/VarPopAggregateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/VarPopAggregateDescriptor.java new file mode 100644 index 0000000..c1a6df1 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/std/VarPopAggregateDescriptor.java @@ -0,0 +1,61 @@ +/* + * 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.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.AbstractAggregateFunctionDynamicDescriptor; +import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator; +import org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluatorFactory; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; +import org.apache.hyracks.api.context.IHyracksTaskContext; +import org.apache.hyracks.api.exceptions.HyracksDataException; + +public class VarPopAggregateDescriptor extends AbstractAggregateFunctionDynamicDescriptor { + + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new VarPopAggregateDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return BuiltinFunctions.VAR_POP; + } + + @Override + public IAggregateEvaluatorFactory createAggregateEvaluatorFactory(final IScalarEvaluatorFactory[] args) { + return new IAggregateEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IAggregateEvaluator createAggregateEvaluator(final IHyracksTaskContext ctx) + throws HyracksDataException { + return new VarAggregateFunction(args, ctx, true, sourceLoc); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/asterixdb/blob/2a42da45/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java index c8f1238..19c33db 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java @@ -42,9 +42,13 @@ import org.apache.asterix.runtime.aggregates.scalar.ScalarSqlMinAggregateDescrip import org.apache.asterix.runtime.aggregates.scalar.ScalarSqlStddevAggregateDescriptor; import org.apache.asterix.runtime.aggregates.scalar.ScalarSqlStddevPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.scalar.ScalarSqlSumAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.scalar.ScalarSqlVarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.scalar.ScalarSqlVarPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.scalar.ScalarStddevAggregateDescriptor; import org.apache.asterix.runtime.aggregates.scalar.ScalarStddevPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.scalar.ScalarSumAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.scalar.ScalarVarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.scalar.ScalarVarPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableAvgAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableCountAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableGlobalAvgAggregateDescriptor; @@ -53,12 +57,20 @@ import org.apache.asterix.runtime.aggregates.serializable.std.SerializableGlobal import org.apache.asterix.runtime.aggregates.serializable.std.SerializableGlobalSqlStddevPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableGlobalStddevAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableGlobalStddevPopAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.serializable.std.SerializableGlobalSqlVarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.serializable.std.SerializableGlobalSqlVarPopAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.serializable.std.SerializableGlobalVarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.serializable.std.SerializableGlobalVarPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableIntermediateAvgAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableIntermediateSqlAvgAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableIntermediateSqlStddevAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableIntermediateSqlStddevPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableIntermediateStddevAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableIntermediateStddevPopAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.serializable.std.SerializableIntermediateSqlVarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.serializable.std.SerializableIntermediateSqlVarPopAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.serializable.std.SerializableIntermediateVarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.serializable.std.SerializableIntermediateVarPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableLocalAvgAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableLocalSqlAvgAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableLocalSqlStddevAggregateDescriptor; @@ -67,14 +79,22 @@ import org.apache.asterix.runtime.aggregates.serializable.std.SerializableLocalS import org.apache.asterix.runtime.aggregates.serializable.std.SerializableLocalStddevPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableLocalSqlSumAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableLocalSumAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.serializable.std.SerializableLocalSqlVarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.serializable.std.SerializableLocalSqlVarPopAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.serializable.std.SerializableLocalVarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.serializable.std.SerializableLocalVarPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableSqlAvgAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableSqlCountAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableSqlStddevAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableSqlStddevPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableSqlSumAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.serializable.std.SerializableSqlVarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.serializable.std.SerializableSqlVarPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableStddevAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableStddevPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.serializable.std.SerializableSumAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.serializable.std.SerializableVarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.serializable.std.SerializableVarPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.AvgAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.CountAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.GlobalAvgAggregateDescriptor; @@ -84,12 +104,20 @@ import org.apache.asterix.runtime.aggregates.std.GlobalSqlStddevAggregateDescrip import org.apache.asterix.runtime.aggregates.std.GlobalSqlStddevPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.GlobalStddevAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.GlobalStddevPopAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.std.GlobalSqlVarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.std.GlobalSqlVarPopAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.std.GlobalVarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.std.GlobalVarPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.IntermediateAvgAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.IntermediateSqlAvgAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.IntermediateSqlStddevAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.IntermediateSqlStddevPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.IntermediateStddevAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.IntermediateStddevPopAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.std.IntermediateSqlVarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.std.IntermediateSqlVarPopAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.std.IntermediateVarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.std.IntermediateVarPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.LocalAvgAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.LocalMaxAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.LocalMinAggregateDescriptor; @@ -100,9 +128,13 @@ import org.apache.asterix.runtime.aggregates.std.LocalSqlMinAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.LocalSqlStddevAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.LocalSqlStddevPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.LocalSqlSumAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.std.LocalSqlVarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.std.LocalSqlVarPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.LocalStddevAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.LocalStddevPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.LocalSumAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.std.LocalVarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.std.LocalVarPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.MaxAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.MinAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.SqlAvgAggregateDescriptor; @@ -112,9 +144,13 @@ import org.apache.asterix.runtime.aggregates.std.SqlMinAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.SqlStddevAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.SqlStddevPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.SqlSumAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.std.SqlVarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.std.SqlVarPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.StddevAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.StddevPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.std.SumAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.std.VarAggregateDescriptor; +import org.apache.asterix.runtime.aggregates.std.VarPopAggregateDescriptor; import org.apache.asterix.runtime.aggregates.stream.EmptyStreamAggregateDescriptor; import org.apache.asterix.runtime.aggregates.stream.NonEmptyStreamAggregateDescriptor; import org.apache.asterix.runtime.evaluators.accessors.CircleCenterAccessor; @@ -484,6 +520,14 @@ public final class FunctionCollection implements IFunctionCollection { fc.add(LocalStddevPopAggregateDescriptor.FACTORY); fc.add(IntermediateStddevPopAggregateDescriptor.FACTORY); fc.add(GlobalStddevPopAggregateDescriptor.FACTORY); + fc.add(VarAggregateDescriptor.FACTORY); + fc.add(LocalVarAggregateDescriptor.FACTORY); + fc.add(IntermediateVarAggregateDescriptor.FACTORY); + fc.add(GlobalVarAggregateDescriptor.FACTORY); + fc.add(VarPopAggregateDescriptor.FACTORY); + fc.add(LocalVarPopAggregateDescriptor.FACTORY); + fc.add(IntermediateVarPopAggregateDescriptor.FACTORY); + fc.add(GlobalVarPopAggregateDescriptor.FACTORY); // serializable aggregates fc.add(SerializableCountAggregateDescriptor.FACTORY); @@ -501,6 +545,14 @@ public final class FunctionCollection implements IFunctionCollection { fc.add(SerializableLocalStddevPopAggregateDescriptor.FACTORY); fc.add(SerializableIntermediateStddevPopAggregateDescriptor.FACTORY); fc.add(SerializableGlobalStddevPopAggregateDescriptor.FACTORY); + fc.add(SerializableVarAggregateDescriptor.FACTORY); + fc.add(SerializableLocalVarAggregateDescriptor.FACTORY); + fc.add(SerializableIntermediateVarAggregateDescriptor.FACTORY); + fc.add(SerializableGlobalVarAggregateDescriptor.FACTORY); + fc.add(SerializableVarPopAggregateDescriptor.FACTORY); + fc.add(SerializableLocalVarPopAggregateDescriptor.FACTORY); + fc.add(SerializableIntermediateVarPopAggregateDescriptor.FACTORY); + fc.add(SerializableGlobalVarPopAggregateDescriptor.FACTORY); // scalar aggregates fc.add(ScalarCountAggregateDescriptor.FACTORY); @@ -512,6 +564,8 @@ public final class FunctionCollection implements IFunctionCollection { fc.add(NonEmptyStreamAggregateDescriptor.FACTORY); fc.add(ScalarStddevAggregateDescriptor.FACTORY); fc.add(ScalarStddevPopAggregateDescriptor.FACTORY); + fc.add(ScalarVarAggregateDescriptor.FACTORY); + fc.add(ScalarVarPopAggregateDescriptor.FACTORY); // SQL aggregates fc.add(SqlCountAggregateDescriptor.FACTORY); @@ -533,6 +587,14 @@ public final class FunctionCollection implements IFunctionCollection { fc.add(LocalSqlStddevPopAggregateDescriptor.FACTORY); fc.add(IntermediateSqlStddevPopAggregateDescriptor.FACTORY); fc.add(GlobalSqlStddevPopAggregateDescriptor.FACTORY); + fc.add(SqlVarAggregateDescriptor.FACTORY); + fc.add(LocalSqlVarAggregateDescriptor.FACTORY); + fc.add(IntermediateSqlVarAggregateDescriptor.FACTORY); + fc.add(GlobalSqlVarAggregateDescriptor.FACTORY); + fc.add(SqlVarPopAggregateDescriptor.FACTORY); + fc.add(LocalSqlVarPopAggregateDescriptor.FACTORY); + fc.add(IntermediateSqlVarPopAggregateDescriptor.FACTORY); + fc.add(GlobalSqlVarPopAggregateDescriptor.FACTORY); // SQL serializable aggregates fc.add(SerializableSqlCountAggregateDescriptor.FACTORY); @@ -550,6 +612,14 @@ public final class FunctionCollection implements IFunctionCollection { fc.add(SerializableLocalSqlStddevPopAggregateDescriptor.FACTORY); fc.add(SerializableIntermediateSqlStddevPopAggregateDescriptor.FACTORY); fc.add(SerializableGlobalSqlStddevPopAggregateDescriptor.FACTORY); + fc.add(SerializableSqlVarAggregateDescriptor.FACTORY); + fc.add(SerializableLocalSqlVarAggregateDescriptor.FACTORY); + fc.add(SerializableIntermediateSqlVarAggregateDescriptor.FACTORY); + fc.add(SerializableGlobalSqlVarAggregateDescriptor.FACTORY); + fc.add(SerializableSqlVarPopAggregateDescriptor.FACTORY); + fc.add(SerializableLocalSqlVarPopAggregateDescriptor.FACTORY); + fc.add(SerializableIntermediateSqlVarPopAggregateDescriptor.FACTORY); + fc.add(SerializableGlobalSqlVarPopAggregateDescriptor.FACTORY); // SQL scalar aggregates fc.add(ScalarSqlCountAggregateDescriptor.FACTORY); @@ -559,6 +629,8 @@ public final class FunctionCollection implements IFunctionCollection { fc.add(ScalarSqlMinAggregateDescriptor.FACTORY); fc.add(ScalarSqlStddevAggregateDescriptor.FACTORY); fc.add(ScalarSqlStddevPopAggregateDescriptor.FACTORY); + fc.add(ScalarSqlVarAggregateDescriptor.FACTORY); + fc.add(ScalarSqlVarPopAggregateDescriptor.FACTORY); // boolean functions fc.add(AndDescriptor.FACTORY);
