You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by ja...@apache.org on 2013/08/28 02:30:39 UTC
[4/5] DRILL-185: Extend code/clean code generator and add first
aggregate functions.
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java
index 24ebeaa..33f61de 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java
@@ -15,8 +15,8 @@ import org.apache.drill.exec.expr.annotations.FunctionTemplate;
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.fn.FunctionHolder.ValueReference;
-import org.apache.drill.exec.expr.fn.FunctionHolder.WorkspaceReference;
+import org.apache.drill.exec.expr.fn.DrillFuncHolder.ValueReference;
+import org.apache.drill.exec.expr.fn.DrillFuncHolder.WorkspaceReference;
import org.apache.drill.exec.expr.holders.ValueHolder;
import org.codehaus.commons.compiler.CompileException;
import org.codehaus.janino.Java;
@@ -36,7 +36,7 @@ public class FunctionConverter {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(FunctionConverter.class);
- public <T extends DrillFunc> FunctionHolder getHolder(Class<T> clazz){
+ public <T extends DrillFunc> DrillFuncHolder getHolder(Class<T> clazz){
FunctionTemplate template = clazz.getAnnotation(FunctionTemplate.class);
if(template == null){
return failure("Class does not declare FunctionTemplate annotation.", clazz);
@@ -98,7 +98,7 @@ public class FunctionConverter {
}else{
// workspace work.
- logger.debug("Found workspace field {}:{}", field.getType(), field.getName());
+// logger.debug("Found workspace field {}:{}", field.getType(), field.getName());
workspaceFields.add(new WorkspaceReference(field.getType(), field.getName()));
}
@@ -122,16 +122,13 @@ public class FunctionConverter {
// return holder
ValueReference[] ps = params.toArray(new ValueReference[params.size()]);
WorkspaceReference[] works = workspaceFields.toArray(new WorkspaceReference[workspaceFields.size()]);
- if(!methods.containsKey("eval")){
- return failure("Failure finding eval method for function.", clazz);
- }
try{
switch(template.scope()){
case POINT_AGGREGATE:
return new DrillAggFuncHolder(template.scope(), template.nulls(), template.isBinaryCommutative(), template.name(), ps, outputField, works, methods, imports);
case SIMPLE:
- FunctionHolder fh = new DrillFuncHolder(template.scope(), template.nulls(), template.isBinaryCommutative(), template.name(), ps, outputField, works, methods, imports);
+ DrillFuncHolder fh = new DrillSimpleFuncHolder(template.scope(), template.nulls(), template.isBinaryCommutative(), template.name(), ps, outputField, works, methods, imports);
return fh;
case HOLISTIC_AGGREGATE:
@@ -174,27 +171,27 @@ public class FunctionConverter {
return (T) val;
}
- private static FunctionHolder failure(String message, Throwable t, Class<?> clazz, String fieldName){
+ private static DrillFuncHolder failure(String message, Throwable t, Class<?> clazz, String fieldName){
logger.warn("Failure loading function class {}, field {}. " + message, clazz.getName(), fieldName, t);
return null;
}
- private FunctionHolder failure(String message, Class<?> clazz, String fieldName){
+ private DrillFuncHolder failure(String message, Class<?> clazz, String fieldName){
logger.warn("Failure loading function class {}, field {}. " + message, clazz.getName(), fieldName);
return null;
}
- private FunctionHolder failure(String message, Class<?> clazz){
+ private DrillFuncHolder failure(String message, Class<?> clazz){
logger.warn("Failure loading function class {}. " + message, clazz.getName());
return null;
}
- private FunctionHolder failure(String message, Throwable t, Class<?> clazz){
+ private DrillFuncHolder failure(String message, Throwable t, Class<?> clazz){
logger.warn("Failure loading function class {}. " + message, t, clazz.getName());
return null;
}
- private FunctionHolder failure(String message, Class<?> clazz, Field field){
+ private DrillFuncHolder failure(String message, Class<?> clazz, Field field){
return failure(message, clazz, field.getName());
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionHolder.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionHolder.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionHolder.java
deleted file mode 100644
index 0c9b979..0000000
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionHolder.java
+++ /dev/null
@@ -1,153 +0,0 @@
-package org.apache.drill.exec.expr.fn;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.drill.common.expression.FunctionCall;
-import org.apache.drill.common.expression.LogicalExpression;
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.common.types.Types;
-import org.apache.drill.exec.expr.CodeGenerator;
-import org.apache.drill.exec.expr.CodeGenerator.HoldingContainer;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
-import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.sun.codemodel.JBlock;
-import com.sun.codemodel.JMod;
-import com.sun.codemodel.JVar;
-
-public abstract class FunctionHolder {
-
- static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(FunctionImplementationRegistry.class);
-
- protected final FunctionTemplate.FunctionScope scope;
- protected final FunctionTemplate.NullHandling nullHandling;
- protected final boolean isBinaryCommutative;
- protected final String functionName;
- protected final ImmutableList<String> imports;
- protected final WorkspaceReference[] workspaceVars;
- protected final ValueReference[] parameters;
- protected final ValueReference returnValue;
- protected final ImmutableMap<String, String> methodMap;
-
- public FunctionHolder(FunctionScope scope, NullHandling nullHandling, boolean isBinaryCommutative, String functionName, ValueReference[] parameters, ValueReference returnValue, WorkspaceReference[] workspaceVars, Map<String, String> methods, List<String> imports) {
- super();
- this.scope = scope;
- this.nullHandling = nullHandling;
- this.workspaceVars = workspaceVars;
- this.isBinaryCommutative = isBinaryCommutative;
- this.functionName = functionName;
- this.methodMap = ImmutableMap.copyOf(methods);
- this.parameters = parameters;
- this.returnValue = returnValue;
- this.imports = ImmutableList.copyOf(imports);
-
- }
-
- public List<String> getImports() {
- return imports;
- }
-
- public abstract HoldingContainer renderFunction(CodeGenerator<?> g, HoldingContainer[] inputVariables);
-
- public void addProtectedBlock(CodeGenerator<?> g, JBlock sub, String body, HoldingContainer[] inputVariables){
-
- // create sub block with defined workspace variables.
- JVar[] workspaceJVars = new JVar[workspaceVars.length];
- for(int i =0 ; i < workspaceVars.length; i++){
- workspaceJVars[i] = g.declareClassField("work", g.getModel()._ref(workspaceVars[i].type));
- }
-
- if(inputVariables != null){
- for(int i =0; i < inputVariables.length; i++){
- ValueReference parameter = parameters[i];
- HoldingContainer inputVariable = inputVariables[i];
- sub.decl(JMod.FINAL, inputVariable.getHolder().type(), parameter.name, inputVariable.getHolder());
- }
- }
-
- JVar[] internalVars = new JVar[workspaceJVars.length];
- for(int i =0; i < workspaceJVars.length; i++){
- internalVars[i] = sub.decl(JMod.FINAL, g.getModel()._ref(workspaceVars[i].type), workspaceVars[i].name, workspaceJVars[i]);
- }
-
- Preconditions.checkNotNull(body);
- sub.directStatement(body);
-
- // reassign workspace variables back to global space.
- for(int i =0; i < workspaceJVars.length; i++){
- sub.assign(workspaceJVars[i], internalVars[i]);
- }
- }
-
-
-
-
- public boolean matches(FunctionCall call){
- if(!softCompare(call.getMajorType(), returnValue.type)){
-// logger.debug(String.format("Call [%s] didn't match as return type [%s] was different than expected [%s]. ", call.getDefinition().getName(), returnValue.type, call.getMajorType()));
- return false;
- }
- if(call.args.size() != parameters.length){
-// logger.debug(String.format("Call [%s] didn't match as the number of arguments provided [%d] were different than expected [%d]. ", call.getDefinition().getName(), parameters.length, call.args.size()));
- return false;
- }
- for(int i =0; i < parameters.length; i++){
- ValueReference param = parameters[i];
- LogicalExpression arg = call.args.get(i);
- if(!softCompare(param.type, arg.getMajorType())){
-// logger.debug(String.format("Call [%s] didn't match as the argument [%s] didn't match the expected type [%s]. ", call.getDefinition().getName(), arg.getMajorType(), param.type));
- return false;
- }
- }
-
- return true;
- }
-
- private boolean softCompare(MajorType a, MajorType b){
- return Types.softEquals(a, b, nullHandling == NullHandling.NULL_IF_NULL);
- }
-
- public String getFunctionName() {
- return functionName;
- }
-
- public static class ValueReference{
- MajorType type;
- String name;
- public ValueReference(MajorType type, String name) {
- super();
- Preconditions.checkNotNull(type);
- Preconditions.checkNotNull(name);
- this.type = type;
- this.name = name;
- }
- @Override
- public String toString() {
- return "ValueReference [type=" + type + ", name=" + name + "]";
- }
- }
-
-
- public static class WorkspaceReference{
- Class<?> type;
- String name;
-
-
- public WorkspaceReference(Class<?> type, String name) {
- super();
- Preconditions.checkNotNull(type);
- Preconditions.checkNotNull(name);
- this.type = type;
- this.name = name;
- }
-
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionImplementationRegistry.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionImplementationRegistry.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionImplementationRegistry.java
index 8454bb7..3b45446 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionImplementationRegistry.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionImplementationRegistry.java
@@ -1,25 +1,29 @@
package org.apache.drill.exec.expr.fn;
+import java.util.List;
import java.util.Set;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.expression.FunctionCall;
+import org.apache.drill.common.expression.LogicalExpression;
+import org.apache.drill.common.types.TypeProtos.MajorType;
import org.apache.drill.common.util.PathScanner;
import org.apache.drill.exec.ExecConstants;
import org.apache.drill.exec.expr.DrillFunc;
+import com.beust.jcommander.internal.Lists;
import com.google.common.collect.ArrayListMultimap;
public class FunctionImplementationRegistry {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(FunctionImplementationRegistry.class);
- private ArrayListMultimap<String, FunctionHolder> methods = ArrayListMultimap.create();
+ private ArrayListMultimap<String, DrillFuncHolder> methods = ArrayListMultimap.create();
public FunctionImplementationRegistry(DrillConfig config){
FunctionConverter converter = new FunctionConverter();
Set<Class<? extends DrillFunc>> providerClasses = PathScanner.scanForImplementations(DrillFunc.class, config.getStringList(ExecConstants.FUNCTION_PACKAGES));
for (Class<? extends DrillFunc> clazz : providerClasses) {
- FunctionHolder holder = converter.getHolder(clazz);
+ DrillFuncHolder holder = converter.getHolder(clazz);
if(holder != null){
methods.put(holder.getFunctionName(), holder);
// logger.debug("Registering function {}", holder);
@@ -29,13 +33,18 @@ public class FunctionImplementationRegistry {
}
}
- public FunctionHolder getFunction(FunctionCall call){
- for(FunctionHolder h : methods.get(call.getDefinition().getName())){
+ public DrillFuncHolder getFunction(FunctionCall call){
+ for(DrillFuncHolder h : methods.get(call.getDefinition().getName())){
if(h.matches(call)){
return h;
}
}
- throw new UnsupportedOperationException(String.format("Unable to find matching function implementation for call %s.", call));
+ List<MajorType> types = Lists.newArrayList();
+ for(LogicalExpression e : call.args){
+ types.add(e.getMajorType());
+ }
+
+ throw new UnsupportedOperationException(String.format("Unable to find matching function implementation for call %s with args %s", call.getDefinition().getName(), types));
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/agg/impl/CountFunctions.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/agg/impl/CountFunctions.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/agg/impl/CountFunctions.java
new file mode 100644
index 0000000..08fc941
--- /dev/null
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/agg/impl/CountFunctions.java
@@ -0,0 +1,69 @@
+package org.apache.drill.exec.expr.fn.agg.impl;
+
+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.record.RecordBatch;
+import org.apache.drill.exec.vector.BigIntHolder;
+import org.apache.drill.exec.vector.IntHolder;
+
+public class CountFunctions {
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CountFunctions.class);
+
+ @FunctionTemplate(name = "count", scope = FunctionScope.POINT_AGGREGATE)
+ public static class BigIntCount implements DrillAggFunc{
+
+ @Param BigIntHolder in;
+ @Workspace long count;
+ @Output BigIntHolder out;
+
+ public void setup(RecordBatch incoming) {
+ }
+
+ @Override
+ public void add() {
+ count++;
+ }
+
+ @Override
+ public void output() {
+ out.value = count;
+ }
+
+ @Override
+ public void reset() {
+ count = 0;
+ }
+
+ }
+
+ @FunctionTemplate(name = "count", scope = FunctionScope.POINT_AGGREGATE)
+ public static class IntCount implements DrillAggFunc{
+
+ @Param IntHolder in;
+ @Workspace long count;
+ @Output BigIntHolder out;
+
+ public void setup(RecordBatch incoming) {
+ }
+
+ @Override
+ public void add() {
+ count++;
+ }
+
+ @Override
+ public void output() {
+ out.value = count;
+ }
+
+ @Override
+ public void reset() {
+ count = 0;
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/agg/impl/SumFunctions.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/agg/impl/SumFunctions.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/agg/impl/SumFunctions.java
new file mode 100644
index 0000000..e42636d
--- /dev/null
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/agg/impl/SumFunctions.java
@@ -0,0 +1,69 @@
+package org.apache.drill.exec.expr.fn.agg.impl;
+
+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.record.RecordBatch;
+import org.apache.drill.exec.vector.BigIntHolder;
+import org.apache.drill.exec.vector.IntHolder;
+
+public class SumFunctions {
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SumFunctions.class);
+
+ @FunctionTemplate(name = "sum", scope = FunctionScope.POINT_AGGREGATE)
+ public static class BigIntSum implements DrillAggFunc{
+
+ @Param BigIntHolder in;
+ @Workspace long sum;
+ @Output BigIntHolder out;
+
+ public void setup(RecordBatch incoming) {
+ }
+
+ @Override
+ public void add() {
+ sum += in.value;
+ }
+
+ @Override
+ public void output() {
+ out.value = sum;
+ }
+
+ @Override
+ public void reset() {
+ sum = 0;
+ }
+
+ }
+
+ @FunctionTemplate(name = "sum", scope = FunctionScope.POINT_AGGREGATE)
+ public static class IntSum implements DrillAggFunc{
+
+ @Param IntHolder in;
+ @Workspace int sum;
+ @Output IntHolder out;
+
+ public void setup(RecordBatch incoming) {
+ }
+
+ @Override
+ public void add() {
+ sum += in.value;
+ }
+
+ @Override
+ public void output() {
+ out.value = sum;
+ }
+
+ @Override
+ public void reset() {
+ sum = 0;
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Alternator.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Alternator.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Alternator.java
index d2bcaa2..d79120d 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Alternator.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Alternator.java
@@ -6,7 +6,7 @@ import org.apache.drill.common.expression.NoArgValidator;
import org.apache.drill.common.expression.OutputTypeDeterminer;
import org.apache.drill.common.types.TypeProtos.MinorType;
import org.apache.drill.common.types.Types;
-import org.apache.drill.exec.expr.DrillFunc;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
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;
@@ -19,7 +19,7 @@ import org.apache.drill.exec.vector.BigIntHolder;
public class Alternator {
@FunctionTemplate(name = "alternate", scope = FunctionScope.SIMPLE)
- public static class Alternate2 implements DrillFunc{
+ public static class Alternate2 implements DrillSimpleFunc{
@Workspace int val;
@Output BigIntHolder out;
@@ -39,7 +39,7 @@ public class Alternator {
}
@FunctionTemplate(name = "alternate3", scope = FunctionScope.SIMPLE)
- public static class Alternate3 implements DrillFunc{
+ public static class Alternate3 implements DrillSimpleFunc{
@Workspace int val;
@Output BigIntHolder out;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteSubstring.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteSubstring.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteSubstring.java
index 3cc22a9..e06fee2 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteSubstring.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteSubstring.java
@@ -22,7 +22,7 @@ import org.apache.drill.common.expression.*;
import org.apache.drill.common.types.TypeProtos;
import org.apache.drill.common.types.TypeProtos.MajorType;
import org.apache.drill.common.types.Types;
-import org.apache.drill.exec.expr.DrillFunc;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
import org.apache.drill.exec.expr.annotations.FunctionTemplate;
import org.apache.drill.exec.expr.annotations.Output;
import org.apache.drill.exec.expr.annotations.Param;
@@ -48,7 +48,7 @@ import org.apache.drill.exec.vector.*;
@FunctionTemplate(name = "bytesubstring",
scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
-public class ByteSubstring implements DrillFunc {
+public class ByteSubstring implements DrillSimpleFunc {
@Param VarBinaryHolder string;
@Param BigIntHolder offset;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CharSubstring.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CharSubstring.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CharSubstring.java
index 0fd9648..b60299c 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CharSubstring.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CharSubstring.java
@@ -21,7 +21,7 @@ package org.apache.drill.exec.expr.fn.impl;
import org.apache.drill.common.expression.*;
import org.apache.drill.common.types.TypeProtos;
import org.apache.drill.common.types.Types;
-import org.apache.drill.exec.expr.DrillFunc;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
import org.apache.drill.exec.expr.annotations.FunctionTemplate;
import org.apache.drill.exec.expr.annotations.Output;
import org.apache.drill.exec.expr.annotations.Param;
@@ -51,7 +51,7 @@ import org.apache.drill.exec.vector.*;
@FunctionTemplate(name = "charsubstring",
scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
-public class CharSubstring implements DrillFunc {
+public class CharSubstring implements DrillSimpleFunc {
@Param VarCharHolder string;
@Param BigIntHolder offset;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparatorFunctions.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparatorFunctions.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparatorFunctions.java
index 471bdf0..1ad3c4d 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparatorFunctions.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparatorFunctions.java
@@ -6,7 +6,7 @@ import org.apache.drill.common.expression.FunctionDefinition;
import org.apache.drill.common.expression.OutputTypeDeterminer;
import org.apache.drill.common.types.TypeProtos.MinorType;
import org.apache.drill.common.types.Types;
-import org.apache.drill.exec.expr.DrillFunc;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
import org.apache.drill.exec.expr.annotations.FunctionTemplate;
import org.apache.drill.exec.expr.annotations.Output;
import org.apache.drill.exec.expr.annotations.Param;
@@ -18,7 +18,7 @@ public class ComparatorFunctions {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ComparatorFunctions.class);
@FunctionTemplate(name = "compare_to", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class IntComparator implements DrillFunc {
+ public static class IntComparator implements DrillSimpleFunc {
@Param IntHolder left;
@Param IntHolder right;
@@ -32,7 +32,7 @@ public class ComparatorFunctions {
}
@FunctionTemplate(name = "compare_to", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class Long implements DrillFunc {
+ public static class Long implements DrillSimpleFunc {
@Param BigIntHolder left;
@Param BigIntHolder right;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparisonFunctions.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparisonFunctions.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparisonFunctions.java
index 21263b0..cb47251 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparisonFunctions.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparisonFunctions.java
@@ -4,7 +4,7 @@ import org.apache.drill.common.expression.ArgumentValidators;
import org.apache.drill.common.expression.CallProvider;
import org.apache.drill.common.expression.FunctionDefinition;
import org.apache.drill.common.expression.OutputTypeDeterminer;
-import org.apache.drill.exec.expr.DrillFunc;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
import org.apache.drill.exec.expr.annotations.FunctionTemplate;
import org.apache.drill.exec.expr.annotations.Output;
import org.apache.drill.exec.expr.annotations.Param;
@@ -21,7 +21,7 @@ public class ComparisonFunctions {
private ComparisonFunctions() {}
@FunctionTemplate(name = "equal", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class IntEqual implements DrillFunc {
+ public static class IntEqual implements DrillSimpleFunc {
@Param IntHolder left;
@Param IntHolder right;
@@ -35,7 +35,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "equal", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class BigIntEqual implements DrillFunc {
+ public static class BigIntEqual implements DrillSimpleFunc {
@Param BigIntHolder left;
@Param BigIntHolder right;
@@ -49,7 +49,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "equal", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class Float4Equal implements DrillFunc {
+ public static class Float4Equal implements DrillSimpleFunc {
@Param Float4Holder left;
@Param Float4Holder right;
@@ -63,7 +63,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "equal", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class Float8Equal implements DrillFunc {
+ public static class Float8Equal implements DrillSimpleFunc {
@Param Float8Holder left;
@Param Float8Holder right;
@@ -77,7 +77,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "not equal", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class IntNotEqual implements DrillFunc {
+ public static class IntNotEqual implements DrillSimpleFunc {
@Param IntHolder left;
@Param IntHolder right;
@@ -91,7 +91,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "not equal", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class BigIntNotEqual implements DrillFunc {
+ public static class BigIntNotEqual implements DrillSimpleFunc {
@Param BigIntHolder left;
@Param BigIntHolder right;
@@ -105,7 +105,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "not equal", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class Float4NotEqual implements DrillFunc {
+ public static class Float4NotEqual implements DrillSimpleFunc {
@Param Float4Holder left;
@Param Float4Holder right;
@@ -119,7 +119,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "not equal", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class Float8NotEqual implements DrillFunc {
+ public static class Float8NotEqual implements DrillSimpleFunc {
@Param Float8Holder left;
@Param Float8Holder right;
@@ -133,7 +133,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "greater than", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class IntGreaterThan implements DrillFunc {
+ public static class IntGreaterThan implements DrillSimpleFunc {
@Param IntHolder left;
@Param IntHolder right;
@@ -147,7 +147,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "greater than", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class BigIntGreaterThan implements DrillFunc {
+ public static class BigIntGreaterThan implements DrillSimpleFunc {
@Param BigIntHolder left;
@Param BigIntHolder right;
@@ -161,7 +161,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "greater than", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class Float4GreaterThan implements DrillFunc {
+ public static class Float4GreaterThan implements DrillSimpleFunc {
@Param Float4Holder left;
@Param Float4Holder right;
@@ -175,7 +175,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "greater than", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class Float8GreaterThan implements DrillFunc {
+ public static class Float8GreaterThan implements DrillSimpleFunc {
@Param Float8Holder left;
@Param Float8Holder right;
@@ -189,7 +189,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "greater than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class IntGreaterThanEqual implements DrillFunc {
+ public static class IntGreaterThanEqual implements DrillSimpleFunc {
@Param IntHolder left;
@Param IntHolder right;
@@ -203,7 +203,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "greater than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class BigIntGreaterThanEqual implements DrillFunc {
+ public static class BigIntGreaterThanEqual implements DrillSimpleFunc {
@Param BigIntHolder left;
@Param BigIntHolder right;
@@ -217,7 +217,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "greater than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class Float4GreaterThanEqual implements DrillFunc {
+ public static class Float4GreaterThanEqual implements DrillSimpleFunc {
@Param Float4Holder left;
@Param Float4Holder right;
@@ -231,7 +231,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "greater than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class Float8GreaterThanEqual implements DrillFunc {
+ public static class Float8GreaterThanEqual implements DrillSimpleFunc {
@Param Float8Holder left;
@Param Float8Holder right;
@@ -245,7 +245,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "less than", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class IntLessThan implements DrillFunc {
+ public static class IntLessThan implements DrillSimpleFunc {
@Param IntHolder left;
@Param IntHolder right;
@@ -259,7 +259,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "less than", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class BigIntLessThan implements DrillFunc {
+ public static class BigIntLessThan implements DrillSimpleFunc {
@Param BigIntHolder left;
@Param BigIntHolder right;
@@ -273,7 +273,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "less than", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class Float4LessThan implements DrillFunc {
+ public static class Float4LessThan implements DrillSimpleFunc {
@Param Float4Holder left;
@Param Float4Holder right;
@@ -287,7 +287,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "less than", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class Float8LessThan implements DrillFunc {
+ public static class Float8LessThan implements DrillSimpleFunc {
@Param Float8Holder left;
@Param Float8Holder right;
@@ -301,7 +301,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "less than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class IntLessThanEqual implements DrillFunc {
+ public static class IntLessThanEqual implements DrillSimpleFunc {
@Param IntHolder left;
@Param IntHolder right;
@@ -315,7 +315,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "less than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class BigIntLessThanEqual implements DrillFunc {
+ public static class BigIntLessThanEqual implements DrillSimpleFunc {
@Param BigIntHolder left;
@Param BigIntHolder right;
@@ -329,7 +329,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "less than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class Float4LessThanEqual implements DrillFunc {
+ public static class Float4LessThanEqual implements DrillSimpleFunc {
@Param Float4Holder left;
@Param Float4Holder right;
@@ -343,7 +343,7 @@ public class ComparisonFunctions {
}
@FunctionTemplate(name = "less than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class Float8LessThanEqual implements DrillFunc {
+ public static class Float8LessThanEqual implements DrillSimpleFunc {
@Param Float8Holder left;
@Param Float8Holder right;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparisonFunctionsNullable.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparisonFunctionsNullable.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparisonFunctionsNullable.java
index df844ed..aa6f57e 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparisonFunctionsNullable.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparisonFunctionsNullable.java
@@ -1,6 +1,6 @@
package org.apache.drill.exec.expr.fn.impl;
-import org.apache.drill.exec.expr.DrillFunc;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
import org.apache.drill.exec.expr.annotations.FunctionTemplate;
import org.apache.drill.exec.expr.annotations.Output;
import org.apache.drill.exec.expr.annotations.Param;
@@ -15,7 +15,7 @@ public class ComparisonFunctionsNullable {
private ComparisonFunctionsNullable() {}
@FunctionTemplate(name = "equal", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class NullableIntEqual implements DrillFunc {
+ public static class NullableIntEqual implements DrillSimpleFunc {
@Param NullableIntHolder left;
@Param NullableIntHolder right;
@@ -33,7 +33,7 @@ public class ComparisonFunctionsNullable {
}
@FunctionTemplate(name = "equal", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class NullableBigIntEqual implements DrillFunc {
+ public static class NullableBigIntEqual implements DrillSimpleFunc {
@Param NullableBigIntHolder left;
@Param NullableBigIntHolder right;
@@ -51,7 +51,7 @@ public class ComparisonFunctionsNullable {
}
@FunctionTemplate(name = "not equal", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class NullableIntNotEqual implements DrillFunc {
+ public static class NullableIntNotEqual implements DrillSimpleFunc {
@Param NullableIntHolder left;
@Param NullableIntHolder right;
@@ -69,7 +69,7 @@ public class ComparisonFunctionsNullable {
}
@FunctionTemplate(name = "not equal", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class NullableBigIntNotEqual implements DrillFunc {
+ public static class NullableBigIntNotEqual implements DrillSimpleFunc {
@Param NullableBigIntHolder left;
@Param NullableBigIntHolder right;
@@ -87,7 +87,7 @@ public class ComparisonFunctionsNullable {
}
@FunctionTemplate(name = "less than", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class NullableIntLessThan implements DrillFunc {
+ public static class NullableIntLessThan implements DrillSimpleFunc {
@Param NullableIntHolder left;
@Param NullableIntHolder right;
@@ -105,7 +105,7 @@ public class ComparisonFunctionsNullable {
}
@FunctionTemplate(name = "less than", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class NullableBigIntLessThan implements DrillFunc {
+ public static class NullableBigIntLessThan implements DrillSimpleFunc {
@Param NullableBigIntHolder left;
@Param NullableBigIntHolder right;
@@ -123,7 +123,7 @@ public class ComparisonFunctionsNullable {
}
@FunctionTemplate(name = "less than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class NullableIntLessThanEqual implements DrillFunc {
+ public static class NullableIntLessThanEqual implements DrillSimpleFunc {
@Param NullableIntHolder left;
@Param NullableIntHolder right;
@@ -141,7 +141,7 @@ public class ComparisonFunctionsNullable {
}
@FunctionTemplate(name = "less than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class NullableBigIntLessThanEqual implements DrillFunc {
+ public static class NullableBigIntLessThanEqual implements DrillSimpleFunc {
@Param NullableBigIntHolder left;
@Param NullableBigIntHolder right;
@@ -159,7 +159,7 @@ public class ComparisonFunctionsNullable {
}
@FunctionTemplate(name = "greater than", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class NullableIntGreaterThan implements DrillFunc {
+ public static class NullableIntGreaterThan implements DrillSimpleFunc {
@Param NullableIntHolder left;
@Param NullableIntHolder right;
@@ -177,7 +177,7 @@ public class ComparisonFunctionsNullable {
}
@FunctionTemplate(name = "greater than", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class NullableBigIntGreaterThan implements DrillFunc {
+ public static class NullableBigIntGreaterThan implements DrillSimpleFunc {
@Param NullableBigIntHolder left;
@Param NullableBigIntHolder right;
@@ -195,7 +195,7 @@ public class ComparisonFunctionsNullable {
}
@FunctionTemplate(name = "greater than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class NullableIntGreaterThanEqual implements DrillFunc {
+ public static class NullableIntGreaterThanEqual implements DrillSimpleFunc {
@Param NullableIntHolder left;
@Param NullableIntHolder right;
@@ -213,7 +213,7 @@ public class ComparisonFunctionsNullable {
}
@FunctionTemplate(name = "greater than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class NullableBigIntGreaterThanEqual implements DrillFunc {
+ public static class NullableBigIntGreaterThanEqual implements DrillSimpleFunc {
@Param NullableBigIntHolder left;
@Param NullableBigIntHolder right;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Hash.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Hash.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Hash.java
index 18f7509..bc89b5f 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Hash.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/Hash.java
@@ -19,7 +19,7 @@
package org.apache.drill.exec.expr.fn.impl;
import org.apache.drill.common.expression.*;
-import org.apache.drill.exec.expr.DrillFunc;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
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;
@@ -29,7 +29,7 @@ import org.apache.drill.exec.vector.BigIntHolder;
import org.apache.drill.exec.vector.IntHolder;
@FunctionTemplate(name = "hash", scope = FunctionScope.SIMPLE, nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
-public class Hash implements DrillFunc {
+public class Hash implements DrillSimpleFunc {
@Param BigIntHolder in;
@Output IntHolder out;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotNull.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotNull.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotNull.java
index 51f1a7c..a33dca3 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotNull.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotNull.java
@@ -18,17 +18,20 @@
package org.apache.drill.exec.expr.fn.impl;
-import org.apache.drill.common.expression.*;
-import org.apache.drill.exec.expr.DrillFunc;
+import org.apache.drill.common.expression.ArgumentValidators;
+import org.apache.drill.common.expression.CallProvider;
+import org.apache.drill.common.expression.FunctionDefinition;
+import org.apache.drill.common.expression.OutputTypeDeterminer;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
import org.apache.drill.exec.expr.annotations.FunctionTemplate;
import org.apache.drill.exec.expr.annotations.Output;
import org.apache.drill.exec.expr.annotations.Param;
-import org.apache.drill.exec.expr.holders.*;
import org.apache.drill.exec.record.RecordBatch;
import org.apache.drill.exec.vector.BitHolder;
+import org.apache.drill.exec.vector.NullableFloat8Holder;
@FunctionTemplate(name = "isNotNull", scope = FunctionTemplate.FunctionScope.SIMPLE)
-public class IsNotNull implements DrillFunc {
+public class IsNotNull implements DrillSimpleFunc {
@Param NullableFloat8Holder input;
@Output BitHolder out;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNull.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNull.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNull.java
index f7ccc3f..c8630b7 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNull.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNull.java
@@ -18,17 +18,20 @@
package org.apache.drill.exec.expr.fn.impl;
-import org.apache.drill.common.expression.*;
-import org.apache.drill.exec.expr.DrillFunc;
+import org.apache.drill.common.expression.ArgumentValidators;
+import org.apache.drill.common.expression.CallProvider;
+import org.apache.drill.common.expression.FunctionDefinition;
+import org.apache.drill.common.expression.OutputTypeDeterminer;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
import org.apache.drill.exec.expr.annotations.FunctionTemplate;
import org.apache.drill.exec.expr.annotations.Output;
import org.apache.drill.exec.expr.annotations.Param;
-import org.apache.drill.exec.expr.holders.*;
import org.apache.drill.exec.record.RecordBatch;
import org.apache.drill.exec.vector.BitHolder;
+import org.apache.drill.exec.vector.NullableFloat8Holder;
@FunctionTemplate(name = "isNull", scope = FunctionTemplate.FunctionScope.SIMPLE)
-public class IsNull implements DrillFunc {
+public class IsNull implements DrillSimpleFunc {
@Param NullableFloat8Holder input;
@Output BitHolder out;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/MathFunctions.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/MathFunctions.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/MathFunctions.java
index 78630ba..ccec5e3 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/MathFunctions.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/MathFunctions.java
@@ -1,6 +1,6 @@
package org.apache.drill.exec.expr.fn.impl;
-import org.apache.drill.exec.expr.DrillFunc;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
import org.apache.drill.exec.expr.annotations.FunctionTemplate;
import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
@@ -16,7 +16,7 @@ public class MathFunctions{
private MathFunctions(){}
@FunctionTemplate(name = "add", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class Add1 implements DrillFunc{
+ public static class Add1 implements DrillSimpleFunc{
@Param IntHolder left;
@Param IntHolder right;
@@ -31,7 +31,7 @@ public class MathFunctions{
}
@FunctionTemplate(name = "add", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class LongAdd1 implements DrillFunc{
+ public static class LongAdd1 implements DrillSimpleFunc{
@Param BigIntHolder left;
@Param BigIntHolder right;
@@ -46,7 +46,7 @@ public class MathFunctions{
}
@FunctionTemplate(name = "negative", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class Negative implements DrillFunc{
+ public static class Negative implements DrillSimpleFunc{
@Param BigIntHolder input;
@Output BigIntHolder out;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SimpleRepeatedFunctions.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SimpleRepeatedFunctions.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SimpleRepeatedFunctions.java
index 86f0040..87c2fd8 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SimpleRepeatedFunctions.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SimpleRepeatedFunctions.java
@@ -8,7 +8,7 @@ import org.apache.drill.common.expression.FunctionDefinition;
import org.apache.drill.common.expression.OutputTypeDeterminer;
import org.apache.drill.common.types.TypeProtos.MinorType;
import org.apache.drill.common.types.Types;
-import org.apache.drill.exec.expr.DrillFunc;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
import org.apache.drill.exec.expr.annotations.FunctionTemplate;
import org.apache.drill.exec.expr.annotations.Output;
import org.apache.drill.exec.expr.annotations.Param;
@@ -26,7 +26,7 @@ public class SimpleRepeatedFunctions {
}
@FunctionTemplate(name = "repeated_count", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class RepeatedLengthBigInt implements DrillFunc {
+ public static class RepeatedLengthBigInt implements DrillSimpleFunc {
@Param
RepeatedBigIntHolder input;
@@ -42,7 +42,7 @@ public class SimpleRepeatedFunctions {
}
@FunctionTemplate(name = "repeated_count", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class RepeatedLengthInt implements DrillFunc {
+ public static class RepeatedLengthInt implements DrillSimpleFunc {
@Param RepeatedIntHolder input;
@Output IntHolder out;
@@ -56,7 +56,7 @@ public class SimpleRepeatedFunctions {
}
@FunctionTemplate(name = "repeated_contains", scope = FunctionTemplate.FunctionScope.SIMPLE)
- public static class ContainsBigInt implements DrillFunc {
+ public static class ContainsBigInt implements DrillSimpleFunc {
@Param RepeatedBigIntHolder listToSearch;
@Param BigIntHolder targetValue;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/holders/Float8Holder.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/holders/Float8Holder.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/holders/Float8Holder.java
deleted file mode 100644
index f127b36..0000000
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/holders/Float8Holder.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package org.apache.drill.exec.expr.holders;
-
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.common.types.TypeProtos.MinorType;
-import org.apache.drill.common.types.Types;
-
-public class Float8Holder implements ValueHolder {
- static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Float8Holder.class);
-
- public static final MajorType TYPE = Types.required(MinorType.FLOAT8);
- public double value;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/holders/NullableFloat8Holder.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/holders/NullableFloat8Holder.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/holders/NullableFloat8Holder.java
deleted file mode 100644
index 1938695..0000000
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/expr/holders/NullableFloat8Holder.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package org.apache.drill.exec.expr.holders;
-
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.common.types.TypeProtos.MinorType;
-import org.apache.drill.common.types.Types;
-
-public class NullableFloat8Holder implements ValueHolder{
- static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(NullableFloat8Holder.class);
-
- public static final MajorType TYPE = Types.optional(MinorType.FLOAT8);
- public double value;
- public int isSet;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractBase.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractBase.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractBase.java
index e91257e..08b6bd7 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractBase.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractBase.java
@@ -20,6 +20,8 @@ package org.apache.drill.exec.physical.base;
import org.apache.drill.common.graph.GraphVisitor;
import org.apache.drill.exec.physical.OperatorCost;
+import com.google.common.base.Preconditions;
+
public abstract class AbstractBase implements PhysicalOperator{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(AbstractBase.class);
@@ -30,6 +32,7 @@ public abstract class AbstractBase implements PhysicalOperator{
visitor.enter(this);
if(this.iterator() == null) throw new IllegalArgumentException("Null iterator for pop." + this);
for(PhysicalOperator o : this){
+ Preconditions.checkNotNull(o, String.format("Null in iterator for pop %s.", this));
o.accept(visitor);
}
visitor.leave(this);
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractPhysicalVisitor.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractPhysicalVisitor.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractPhysicalVisitor.java
index 3cd0d7c..cf6cb47 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractPhysicalVisitor.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractPhysicalVisitor.java
@@ -46,6 +46,12 @@ public abstract class AbstractPhysicalVisitor<T, X, E extends Throwable> impleme
public T visitSort(Sort sort, X value) throws E{
return visitOp(sort, value);
}
+
+
+ @Override
+ public T visitStreamingAggregate(StreamingAggregate agg, X value) throws E {
+ return visitOp(agg, value);
+ }
@Override
public T visitSender(Sender sender, X value) throws E {
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/PhysicalVisitor.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/PhysicalVisitor.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/PhysicalVisitor.java
index 39fc105..9f76693 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/PhysicalVisitor.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/PhysicalVisitor.java
@@ -40,7 +40,7 @@ public interface PhysicalVisitor<RETURN, EXTRA, EXCEP extends Throwable> {
public RETURN visitSort(Sort sort, EXTRA value) throws EXCEP;
public RETURN visitSender(Sender sender, EXTRA value) throws EXCEP;
public RETURN visitReceiver(Receiver receiver, EXTRA value) throws EXCEP;
-
+ public RETURN visitStreamingAggregate(StreamingAggregate agg, EXTRA value) throws EXCEP;
public RETURN visitOp(PhysicalOperator op, EXTRA value) throws EXCEP;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/config/Project.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/config/Project.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/config/Project.java
index e869393..1719735 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/config/Project.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/config/Project.java
@@ -17,7 +17,6 @@
******************************************************************************/
package org.apache.drill.exec.physical.config;
-import java.util.Iterator;
import java.util.List;
import org.apache.drill.common.logical.data.NamedExpression;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/config/StreamingAggregate.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/config/StreamingAggregate.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/config/StreamingAggregate.java
new file mode 100644
index 0000000..be63a1a
--- /dev/null
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/config/StreamingAggregate.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * 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.drill.exec.physical.config;
+
+import org.apache.drill.common.logical.data.NamedExpression;
+import org.apache.drill.exec.physical.OperatorCost;
+import org.apache.drill.exec.physical.base.AbstractSingle;
+import org.apache.drill.exec.physical.base.PhysicalOperator;
+import org.apache.drill.exec.physical.base.PhysicalVisitor;
+import org.apache.drill.exec.physical.base.Size;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+
+@JsonTypeName("streaming-aggregate")
+public class StreamingAggregate extends AbstractSingle {
+
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(StreamingAggregate.class);
+
+ private final NamedExpression[] keys;
+ private final NamedExpression[] exprs;
+
+ private final float cardinality;
+
+ @JsonCreator
+ public StreamingAggregate(@JsonProperty("child") PhysicalOperator child, @JsonProperty("keys") NamedExpression[] keys, @JsonProperty("exprs") NamedExpression[] exprs, @JsonProperty("cardinality") float cardinality) {
+ super(child);
+ this.keys = keys;
+ this.exprs = exprs;
+ this.cardinality = cardinality;
+ }
+
+ public NamedExpression[] getKeys() {
+ return keys;
+ }
+
+ public NamedExpression[] getExprs() {
+ return exprs;
+ }
+
+ @Override
+ public <T, X, E extends Throwable> T accept(PhysicalVisitor<T, X, E> physicalVisitor, X value) throws E{
+ return physicalVisitor.visitStreamingAggregate(this, value);
+ }
+
+ @Override
+ public OperatorCost getCost() {
+ return child.getCost();
+ }
+
+ @Override
+ protected PhysicalOperator getNewWithChild(PhysicalOperator child) {
+ return new StreamingAggregate(child, keys, exprs, cardinality);
+ }
+
+ @Override
+ public Size getSize() {
+ // not a great hack...
+ return new Size( (long) (child.getSize().getRecordCount()*cardinality), child.getSize().getRecordSize());
+ }
+
+
+
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ImplCreator.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ImplCreator.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ImplCreator.java
index e69aeae..fb4b371 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ImplCreator.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ImplCreator.java
@@ -34,7 +34,9 @@ import org.apache.drill.exec.physical.config.Screen;
import org.apache.drill.exec.physical.config.SelectionVectorRemover;
import org.apache.drill.exec.physical.config.SingleSender;
import org.apache.drill.exec.physical.config.Sort;
-import org.apache.drill.exec.physical.config.*;
+import org.apache.drill.exec.physical.config.StreamingAggregate;
+import org.apache.drill.exec.physical.config.Union;
+import org.apache.drill.exec.physical.impl.aggregate.AggBatchCreator;
import org.apache.drill.exec.physical.impl.filter.FilterBatchCreator;
import org.apache.drill.exec.physical.impl.partitionsender.PartitionSenderCreator;
import org.apache.drill.exec.physical.impl.project.ProjectBatchCreator;
@@ -70,6 +72,7 @@ public class ImplCreator extends AbstractPhysicalVisitor<RecordBatch, FragmentCo
private UnionBatchCreator unionbc = new UnionBatchCreator();
private SVRemoverCreator svc = new SVRemoverCreator();
private SortBatchCreator sbc = new SortBatchCreator();
+ private AggBatchCreator abc = new AggBatchCreator();
private RootExec root = null;
private ImplCreator(){}
@@ -132,6 +135,13 @@ public class ImplCreator extends AbstractPhysicalVisitor<RecordBatch, FragmentCo
return fbc.getBatch(context, filter, getChildren(filter, context));
}
+
+ @Override
+ public RecordBatch visitStreamingAggregate(StreamingAggregate config, FragmentContext context)
+ throws ExecutionSetupException {
+ return abc.getBatch(context, config, getChildren(config, context));
+ }
+
@Override
public RecordBatch visitUnion(Union union, FragmentContext context) throws ExecutionSetupException {
return unionbc.getBatch(context, union, getChildren(union, context));
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ScanBatch.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ScanBatch.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ScanBatch.java
index ea98c29..192c03c 100644
--- a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ScanBatch.java
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ScanBatch.java
@@ -25,6 +25,7 @@ import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.exec.exception.SchemaChangeException;
import org.apache.drill.exec.ops.FragmentContext;
import org.apache.drill.exec.record.BatchSchema;
+import org.apache.drill.exec.record.BatchSchema.SelectionVectorMode;
import org.apache.drill.exec.record.MaterializedField;
import org.apache.drill.exec.record.RecordBatch;
import org.apache.drill.exec.record.SchemaBuilder;
@@ -47,13 +48,13 @@ public class ScanBatch implements RecordBatch {
final Map<MaterializedField, ValueVector> fieldVectorMap = Maps.newHashMap();
- private VectorContainer holder = new VectorContainer();
- private BatchSchema schema;
+ private final VectorContainer container = new VectorContainer();
private int recordCount;
private boolean schemaChanged = true;
private final FragmentContext context;
private Iterator<RecordReader> readers;
private RecordReader currentReader;
+ private BatchSchema schema;
private final Mutator mutator = new Mutator();
public ScanBatch(FragmentContext context, Iterator<RecordReader> readers) throws ExecutionSetupException {
@@ -65,11 +66,6 @@ public class ScanBatch implements RecordBatch {
this.currentReader.setup(mutator);
}
- private void schemaChanged() {
- schema = null;
- schemaChanged = true;
- }
-
@Override
public FragmentContext getContext() {
return context;
@@ -91,7 +87,7 @@ public class ScanBatch implements RecordBatch {
}
private void releaseAssets() {
- holder.clear();
+ container.clear();
}
@Override
@@ -133,45 +129,43 @@ public class ScanBatch implements RecordBatch {
@Override
public TypedFieldId getValueVectorId(SchemaPath path) {
- return holder.getValueVector(path);
+ return container.getValueVector(path);
}
@Override
public VectorWrapper<?> getValueAccessorById(int fieldId, Class<?> clazz) {
- return holder.getVectorAccessor(fieldId, clazz);
+ return container.getVectorAccessor(fieldId, clazz);
}
private class Mutator implements OutputMutator {
- private SchemaBuilder builder = BatchSchema.newBuilder();
public void removeField(MaterializedField field) throws SchemaChangeException {
- schemaChanged();
ValueVector vector = fieldVectorMap.remove(field);
if (vector == null) throw new SchemaChangeException("Failure attempting to remove an unknown field.");
- holder.remove(vector);
+ container.remove(vector);
vector.close();
}
public void addField(ValueVector vector) {
- holder.add(vector);
+ container.add(vector);
fieldVectorMap.put(vector.getField(), vector);
- builder.addField(vector.getField());
}
@Override
public void removeAllFields() {
- for(VectorWrapper<?> vw : holder){
+ for(VectorWrapper<?> vw : container){
vw.release();
}
- holder.clear();
+ container.clear();
fieldVectorMap.clear();
}
@Override
public void setNewSchema() throws SchemaChangeException {
- ScanBatch.this.schema = this.builder.build();
+ container.buildSchema(SelectionVectorMode.NONE);
+ schema = container.getSchema();
ScanBatch.this.schemaChanged = true;
}
@@ -179,7 +173,7 @@ public class ScanBatch implements RecordBatch {
@Override
public Iterator<VectorWrapper<?>> iterator() {
- return holder.iterator();
+ return container.iterator();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/AggBatch.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/AggBatch.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/AggBatch.java
new file mode 100644
index 0000000..c352b16
--- /dev/null
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/AggBatch.java
@@ -0,0 +1,309 @@
+package org.apache.drill.exec.physical.impl.aggregate;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.drill.common.expression.ErrorCollector;
+import org.apache.drill.common.expression.ErrorCollectorImpl;
+import org.apache.drill.common.expression.ExpressionPosition;
+import org.apache.drill.common.expression.FunctionCall;
+import org.apache.drill.common.expression.LogicalExpression;
+import org.apache.drill.common.logical.data.NamedExpression;
+import org.apache.drill.exec.compile.sig.GeneratorMapping;
+import org.apache.drill.exec.compile.sig.MappingSet;
+import org.apache.drill.exec.exception.ClassTransformationException;
+import org.apache.drill.exec.exception.SchemaChangeException;
+import org.apache.drill.exec.expr.CodeGenerator;
+import org.apache.drill.exec.expr.CodeGenerator.BlockType;
+import org.apache.drill.exec.expr.CodeGenerator.HoldingContainer;
+import org.apache.drill.exec.expr.ExpressionTreeMaterializer;
+import org.apache.drill.exec.expr.HoldingContainerExpression;
+import org.apache.drill.exec.expr.ValueVectorWriteExpression;
+import org.apache.drill.exec.expr.fn.impl.ComparatorFunctions;
+import org.apache.drill.exec.ops.FragmentContext;
+import org.apache.drill.exec.physical.config.StreamingAggregate;
+import org.apache.drill.exec.record.AbstractRecordBatch;
+import org.apache.drill.exec.record.MaterializedField;
+import org.apache.drill.exec.record.RecordBatch;
+import org.apache.drill.exec.record.TypedFieldId;
+import org.apache.drill.exec.record.BatchSchema.SelectionVectorMode;
+import org.apache.drill.exec.record.selection.SelectionVector2;
+import org.apache.drill.exec.record.selection.SelectionVector4;
+import org.apache.drill.exec.vector.TypeHelper;
+import org.apache.drill.exec.vector.ValueVector;
+import org.apache.drill.exec.vector.allocator.VectorAllocator;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+import com.sun.codemodel.JExpr;
+import com.sun.codemodel.JVar;
+
+public class AggBatch extends AbstractRecordBatch<StreamingAggregate> {
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(AggBatch.class);
+
+ private Aggregator aggregator;
+ private final RecordBatch incoming;
+ private boolean done = false;
+
+ public static enum AggOutcome {
+ RETURN_OUTCOME, CLEANUP_AND_RETURN, UPDATE_AGGREGATOR;
+ }
+
+ public AggBatch(StreamingAggregate popConfig, RecordBatch incoming, FragmentContext context) {
+ super(popConfig, context);
+ this.incoming = incoming;
+ }
+
+ @Override
+ public int getRecordCount() {
+ if(done) return 0;
+ return aggregator.getOutputCount();
+ }
+
+ @Override
+ public IterOutcome next() {
+
+ // this is only called on the first batch. Beyond this, the aggregator manages batches.
+ if (aggregator == null) {
+ IterOutcome outcome = incoming.next();
+ logger.debug("Next outcome of {}", outcome);
+ switch (outcome) {
+ case NONE:
+ case NOT_YET:
+ case STOP:
+ return outcome;
+ case OK_NEW_SCHEMA:
+ if (!createAggregator()){
+ done = true;
+ return IterOutcome.STOP;
+ }
+ break;
+ case OK:
+ throw new IllegalStateException("You should never get a first batch without a new schema");
+ default:
+ throw new IllegalStateException(String.format("unknown outcome %s", outcome));
+ }
+ }
+
+ while(true){
+ AggOutcome out = aggregator.doWork();
+ logger.debug("Aggregator response {}, records {}", out, aggregator.getOutputCount());
+ switch(out){
+ case CLEANUP_AND_RETURN:
+ container.clear();
+ done = true;
+ return aggregator.getOutcome();
+ case RETURN_OUTCOME:
+ return aggregator.getOutcome();
+ case UPDATE_AGGREGATOR:
+ aggregator = null;
+ if(!createAggregator()){
+ return IterOutcome.STOP;
+ }
+ continue;
+ default:
+ throw new IllegalStateException(String.format("Unknown state %s.", out));
+ }
+ }
+
+ }
+
+
+
+ /**
+ * Creates a new Aggregator based on the current schema. If setup fails, this method is responsible for cleaning up
+ * and informing the context of the failure state, as well is informing the upstream operators.
+ *
+ * @return true if the aggregator was setup successfully. false if there was a failure.
+ */
+ private boolean createAggregator() {
+ logger.debug("Creating new aggregator.");
+ try{
+ this.aggregator = createAggregatorInternal();
+ return true;
+ }catch(SchemaChangeException | ClassTransformationException | IOException ex){
+ context.fail(ex);
+ container.clear();
+ incoming.kill();
+ return false;
+ }
+ }
+
+
+
+
+ private Aggregator createAggregatorInternal() throws SchemaChangeException, ClassTransformationException, IOException{
+ CodeGenerator<Aggregator> cg = new CodeGenerator<Aggregator>(AggTemplate.TEMPLATE_DEFINITION, context.getFunctionRegistry());
+ container.clear();
+ List<VectorAllocator> allocators = Lists.newArrayList();
+
+ LogicalExpression[] keyExprs = new LogicalExpression[popConfig.getKeys().length];
+ LogicalExpression[] valueExprs = new LogicalExpression[popConfig.getExprs().length];
+ TypedFieldId[] keyOutputIds = new TypedFieldId[popConfig.getKeys().length];
+
+ ErrorCollector collector = new ErrorCollectorImpl();
+
+ for(int i =0; i < keyExprs.length; i++){
+ NamedExpression ne = popConfig.getKeys()[i];
+ final LogicalExpression expr = ExpressionTreeMaterializer.materialize(ne.getExpr(), incoming, collector);
+ if(expr == null) continue;
+ keyExprs[i] = expr;
+ final MaterializedField outputField = MaterializedField.create(ne.getRef(), expr.getMajorType());
+ ValueVector vector = TypeHelper.getNewVector(outputField, context.getAllocator());
+ allocators.add(VectorAllocator.getAllocator(vector, 50));
+ keyOutputIds[i] = container.add(vector);
+ }
+
+ for(int i =0; i < valueExprs.length; i++){
+ NamedExpression ne = popConfig.getExprs()[i];
+ final LogicalExpression expr = ExpressionTreeMaterializer.materialize(ne.getExpr(), incoming, collector);
+ if(expr == null) continue;
+
+ final MaterializedField outputField = MaterializedField.create(ne.getRef(), expr.getMajorType());
+ ValueVector vector = TypeHelper.getNewVector(outputField, context.getAllocator());
+ allocators.add(VectorAllocator.getAllocator(vector, 50));
+ TypedFieldId id = container.add(vector);
+ valueExprs[i] = new ValueVectorWriteExpression(id, expr, true);
+ }
+
+ if(collector.hasErrors()) throw new SchemaChangeException("Failure while materializing expression. " + collector.toErrorString());
+
+ setupIsSame(cg, keyExprs);
+ setupIsSameApart(cg, keyExprs);
+ addRecordValues(cg, valueExprs);
+ outputRecordKeys(cg, keyOutputIds, keyExprs);
+ outputRecordKeysPrev(cg, keyOutputIds, keyExprs);
+
+ cg.getBlock("resetValues")._return(JExpr.TRUE);
+ getIndex(cg);
+
+ container.buildSchema(SelectionVectorMode.NONE);
+ Aggregator agg = context.getImplementationClass(cg);
+ agg.setup(context, incoming, this, allocators.toArray(new VectorAllocator[allocators.size()]));
+ return agg;
+ }
+
+
+
+ private static final GeneratorMapping IS_SAME = GeneratorMapping.create("setupInterior", "isSame", null, null);
+ private static final MappingSet IS_SAME_I1 = new MappingSet("index1", null, IS_SAME, IS_SAME);
+ private static final MappingSet IS_SAME_I2 = new MappingSet("index2", null, IS_SAME, IS_SAME);
+
+ private void setupIsSame(CodeGenerator<Aggregator> cg, LogicalExpression[] keyExprs){
+ cg.setMappingSet(IS_SAME_I1);
+ for(LogicalExpression expr : keyExprs){
+ // first, we rewrite the evaluation stack for each side of the comparison.
+ cg.setMappingSet(IS_SAME_I1);
+ HoldingContainer first = cg.addExpr(expr, false);
+ cg.setMappingSet(IS_SAME_I2);
+ HoldingContainer second = cg.addExpr(expr, false);
+
+ FunctionCall f = new FunctionCall(ComparatorFunctions.COMPARE_TO, ImmutableList.of((LogicalExpression) new HoldingContainerExpression(first), new HoldingContainerExpression(second)), ExpressionPosition.UNKNOWN);
+ HoldingContainer out = cg.addExpr(f, false);
+ cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE);
+ }
+ cg.getEvalBlock()._return(JExpr.TRUE);
+ }
+
+ private static final GeneratorMapping IS_SAME_PREV_INTERNAL_BATCH_READ = GeneratorMapping.create("isSamePrev", "isSamePrev", null, null); // the internal batch changes each time so we need to redo setup.
+ private static final GeneratorMapping IS_SAME_PREV = GeneratorMapping.create("setupInterior", "isSamePrev", null, null);
+ private static final MappingSet ISA_B1 = new MappingSet("b1Index", null, "b1", null, IS_SAME_PREV_INTERNAL_BATCH_READ, IS_SAME_PREV_INTERNAL_BATCH_READ);
+ private static final MappingSet ISA_B2 = new MappingSet("b2Index", null, "incoming", null, IS_SAME_PREV, IS_SAME_PREV);
+
+ private void setupIsSameApart(CodeGenerator<Aggregator> cg, LogicalExpression[] keyExprs){
+ cg.setMappingSet(ISA_B1);
+ for(LogicalExpression expr : keyExprs){
+ // first, we rewrite the evaluation stack for each side of the comparison.
+ cg.setMappingSet(ISA_B1);
+ HoldingContainer first = cg.addExpr(expr, false);
+ cg.setMappingSet(ISA_B2);
+ HoldingContainer second = cg.addExpr(expr, false);
+
+ FunctionCall f = new FunctionCall(ComparatorFunctions.COMPARE_TO, ImmutableList.of((LogicalExpression) new HoldingContainerExpression(first), new HoldingContainerExpression(second)), ExpressionPosition.UNKNOWN);
+ HoldingContainer out = cg.addExpr(f, false);
+ cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE);
+ }
+ cg.getEvalBlock()._return(JExpr.TRUE);
+ }
+
+ private static final GeneratorMapping EVAL_INSIDE = GeneratorMapping.create("setupInterior", "addRecord", null, null);
+ private static final GeneratorMapping EVAL_OUTSIDE = GeneratorMapping.create("setupInterior", "outputRecordValues", "resetValues", "cleanup");
+ private static final MappingSet EVAL = new MappingSet("index", "outIndex", EVAL_INSIDE, EVAL_OUTSIDE, EVAL_INSIDE);
+
+ private void addRecordValues(CodeGenerator<Aggregator> cg, LogicalExpression[] valueExprs){
+ cg.setMappingSet(EVAL);
+ for(LogicalExpression ex : valueExprs){
+ HoldingContainer hc = cg.addExpr(ex);
+ cg.getBlock(BlockType.EVAL)._if(hc.getValue().eq(JExpr.lit(0)))._then()._return(JExpr.FALSE);
+ }
+ cg.getBlock(BlockType.EVAL)._return(JExpr.TRUE);
+ }
+
+ private static final MappingSet RECORD_KEYS = new MappingSet(GeneratorMapping.create("setupInterior", "outputRecordKeys", null, null));
+
+ private void outputRecordKeys(CodeGenerator<Aggregator> cg, TypedFieldId[] keyOutputIds, LogicalExpression[] keyExprs){
+ cg.setMappingSet(RECORD_KEYS);
+ for(int i =0; i < keyExprs.length; i++){
+ HoldingContainer hc = cg.addExpr(new ValueVectorWriteExpression(keyOutputIds[i], keyExprs[i], true));
+ cg.getBlock(BlockType.EVAL)._if(hc.getValue().eq(JExpr.lit(0)))._then()._return(JExpr.FALSE);
+ }
+ cg.getBlock(BlockType.EVAL)._return(JExpr.TRUE);
+ }
+
+ private static final GeneratorMapping PREVIOUS_KEYS_OUT = GeneratorMapping.create("setupInterior", "outputRecordKeysPrev", null, null);
+ private static final MappingSet RECORD_KEYS_PREV_OUT = new MappingSet("previousIndex", "outIndex", "previous", "outgoing", PREVIOUS_KEYS_OUT, PREVIOUS_KEYS_OUT);
+
+ private static final GeneratorMapping PREVIOUS_KEYS = GeneratorMapping.create("outputRecordKeysPrev", "outputRecordKeysPrev", null, null);
+ private static final MappingSet RECORD_KEYS_PREV = new MappingSet("previousIndex", "outIndex", "previous", null, PREVIOUS_KEYS, PREVIOUS_KEYS);
+
+ private void outputRecordKeysPrev(CodeGenerator<Aggregator> cg, TypedFieldId[] keyOutputIds, LogicalExpression[] keyExprs){
+ cg.setMappingSet(RECORD_KEYS_PREV);
+
+ for(int i =0; i < keyExprs.length; i++){
+ // IMPORTANT: there is an implicit assertion here that the TypedFieldIds for the previous batch and the current batch are the same. This is possible because InternalBatch guarantees this.
+ logger.debug("Writing out expr {}", keyExprs[i]);
+ cg.rotateBlock();
+ cg.setMappingSet(RECORD_KEYS_PREV);
+ HoldingContainer innerExpression = cg.addExpr(keyExprs[i], false);
+ cg.setMappingSet(RECORD_KEYS_PREV_OUT);
+ HoldingContainer outerExpression = cg.addExpr(new ValueVectorWriteExpression(keyOutputIds[i], new HoldingContainerExpression(innerExpression), true), false);
+ cg.getBlock(BlockType.EVAL)._if(outerExpression.getValue().eq(JExpr.lit(0)))._then()._return(JExpr.FALSE);
+
+ }
+ cg.getBlock(BlockType.EVAL)._return(JExpr.TRUE);
+ }
+
+ private void getIndex(CodeGenerator<Aggregator> g){
+ switch(incoming.getSchema().getSelectionVectorMode()){
+ case FOUR_BYTE: {
+ JVar var = g.declareClassField("sv4_", g.getModel()._ref(SelectionVector4.class));
+ g.getBlock("setupInterior").assign(var, JExpr.direct("incoming").invoke("getSelectionVector4"));
+ g.getBlock("getVectorIndex")._return(var.invoke("get").arg(JExpr.direct("recordIndex")));;
+ return;
+ }
+ case NONE: {
+ g.getBlock("getVectorIndex")._return(JExpr.direct("recordIndex"));;
+ return;
+ }
+ case TWO_BYTE: {
+ JVar var = g.declareClassField("sv2_", g.getModel()._ref(SelectionVector2.class));
+ g.getBlock("setupInterior").assign(var, JExpr.direct("incoming").invoke("getSelectionVector2"));
+ g.getBlock("getVectorIndex")._return(var.invoke("get").arg(JExpr.direct("recordIndex")));;
+ return;
+ }
+
+ default:
+ throw new IllegalStateException();
+
+ }
+
+ }
+
+
+
+ @Override
+ protected void killIncoming() {
+ incoming.kill();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e43093d9/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/AggBatchCreator.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/AggBatchCreator.java b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/AggBatchCreator.java
new file mode 100644
index 0000000..5a0bc27
--- /dev/null
+++ b/sandbox/prototype/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/AggBatchCreator.java
@@ -0,0 +1,23 @@
+package org.apache.drill.exec.physical.impl.aggregate;
+
+import java.util.List;
+
+import org.apache.drill.common.exceptions.ExecutionSetupException;
+import org.apache.drill.exec.ops.FragmentContext;
+import org.apache.drill.exec.physical.config.StreamingAggregate;
+import org.apache.drill.exec.physical.impl.BatchCreator;
+import org.apache.drill.exec.record.RecordBatch;
+
+import com.google.common.base.Preconditions;
+
+public class AggBatchCreator implements BatchCreator<StreamingAggregate>{
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(AggBatchCreator.class);
+
+ @Override
+ public RecordBatch getBatch(FragmentContext context, StreamingAggregate config, List<RecordBatch> children) throws ExecutionSetupException {
+ Preconditions.checkArgument(children.size() == 1);
+ return new AggBatch(config, children.iterator().next(), context);
+ }
+
+
+}