diff options
author | Jacques Nadeau <jacques@apache.org> | 2014-07-27 14:45:10 -0700 |
---|---|---|
committer | Jacques Nadeau <jacques@apache.org> | 2014-07-27 14:45:10 -0700 |
commit | 0a603df36f53cf7a8d6025745cafd3f30843b5be (patch) | |
tree | f23733590a616f033ee85825d808740deae922c2 /exec/java-exec/src/main | |
parent | 913fad858bbb751cde47b15a2cffda7f4797bcad (diff) |
DRILL-1153: Add $sum0 implementations
Diffstat (limited to 'exec/java-exec/src/main')
-rw-r--r-- | exec/java-exec/src/main/codegen/config.fmpp | 1 | ||||
-rw-r--r-- | exec/java-exec/src/main/codegen/data/SumZero.tdd | 31 | ||||
-rw-r--r-- | exec/java-exec/src/main/codegen/templates/SumZeroAggr.java | 96 |
3 files changed, 128 insertions, 0 deletions
diff --git a/exec/java-exec/src/main/codegen/config.fmpp b/exec/java-exec/src/main/codegen/config.fmpp index 72520f6a3..ff6135dff 100644 --- a/exec/java-exec/src/main/codegen/config.fmpp +++ b/exec/java-exec/src/main/codegen/config.fmpp @@ -35,6 +35,7 @@ data: { dateIntervalFunc: tdd(../data/DateIntervalFunc.tdd), intervalNumericTypes: tdd(../data/IntervalNumericTypes.tdd), extract: tdd(../data/ExtractTypes.tdd), + sumzero: tdd(../data/SumZero.tdd), numericTypes: tdd(../data/NumericTypes.tdd) } freemarkerLinks: { diff --git a/exec/java-exec/src/main/codegen/data/SumZero.tdd b/exec/java-exec/src/main/codegen/data/SumZero.tdd new file mode 100644 index 000000000..b270d928d --- /dev/null +++ b/exec/java-exec/src/main/codegen/data/SumZero.tdd @@ -0,0 +1,31 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http:# www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +{ +types: [ + {inputType: "Bit", outputType: "NullableBit", runningType: "Bit", major: "Numeric"}, + {inputType: "Int", outputType: "NullableBigInt", runningType: "BigInt", major: "Numeric"}, + {inputType: "BigInt", outputType: "NullableBigInt", runningType: "BigInt", major: "Numeric"}, + {inputType: "NullableBit", outputType: "NullableBit", runningType: "Bit", major: "Numeric"}, + {inputType: "NullableInt", outputType: "NullableBigInt", runningType: "BigInt", major: "Numeric"}, + {inputType: "NullableBigInt", outputType: "NullableBigInt", runningType: "BigInt", major: "Numeric"}, + {inputType: "Float4", outputType: "NullableFloat8", runningType: "Float8", major: "Numeric"}, + {inputType: "Float8", outputType: "NullableFloat8", runningType: "Float8", major: "Numeric"}, + {inputType: "NullableFloat4", outputType: "NullableFloat8", runningType: "Float8", major: "Numeric"}, + {inputType: "NullableFloat8", outputType: "NullableFloat8", runningType: "Float8", major: "Numeric"} + ] +} +
\ No newline at end of file diff --git a/exec/java-exec/src/main/codegen/templates/SumZeroAggr.java b/exec/java-exec/src/main/codegen/templates/SumZeroAggr.java new file mode 100644 index 000000000..0eab23d99 --- /dev/null +++ b/exec/java-exec/src/main/codegen/templates/SumZeroAggr.java @@ -0,0 +1,96 @@ +/** + * 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. + */ +<@pp.dropOutputFile /> + + + + +<@pp.changeOutputFile name="/org/apache/drill/exec/expr/fn/impl/gaggr/SumZeroFunctions.java" /> + +<#include "/@includes/license.ftl" /> + +/* + * This class is automatically generated from SumZero.tdd using FreeMarker. + */ + +package org.apache.drill.exec.expr.fn.impl.gaggr; + +import org.apache.drill.exec.expr.DrillAggFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.annotations.Workspace; +import org.apache.drill.exec.expr.holders.*; +import org.apache.drill.exec.record.RecordBatch; + +@SuppressWarnings("unused") + +public class SumZeroFunctions { + static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SumZeroFunctions.class); + + <#list sumzero.types as type> + + @FunctionTemplate(name = "$sum0", scope = FunctionTemplate.FunctionScope.POINT_AGGREGATE) + public static class ${type.inputType}SumZero implements DrillAggFunc{ + + @Param ${type.inputType}Holder in; + @Workspace ${type.runningType}Holder value; + @Workspace BigIntHolder callCount; + @Output ${type.outputType}Holder out; + + + public void setup(RecordBatch b) { + value.value = 0; + callCount.value = 0; + } + + @Override + public void add() { + callCount.value++; + <#if type.inputType?starts_with("Nullable") > + if(in.isSet == 1){ + value.value += in.value; + } + <#else> + value.value += in.value; + </#if> + } + + @Override + public void output() { + if(callCount.value > 0){ + out.value = value.value; + out.isSet = 1; + }else{ + out.isSet = 0; + } + + } + + @Override + public void reset() { + value.value = 0; + callCount.value = 0; + } + + } + +</#list> +} + |