DRILL-259: Implicit cast precedence work Includes following changes: Created resolvers and mini precedence map
changed operator resolution by adding getCost method Updated precedence map for operator resolution - typecast Modified DrillFuncHolder:getCost() to allow null arguments type in cast Cast Null arg precedence Added type cast rules : isCastable() Added type cast rules : isCastable() Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/36945428 Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/36945428 Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/36945428 Branch: refs/heads/master Commit: 369454281caebc3947f8364bf48738b488b90895 Parents: 931b641 Author: Yash <[email protected]> Authored: Wed Nov 13 12:15:53 2013 +0530 Committer: Jacques Nadeau <[email protected]> Committed: Tue Jan 14 08:40:41 2014 -0800 ---------------------------------------------------------------------- .../common/expression/fn/MathFunctions.java | 2 +- .../org/apache/drill/exec/ExecConstants.java | 2 + .../drill/exec/expr/fn/DrillFuncHolder.java | 49 ++ .../expr/fn/FunctionImplementationRegistry.java | 19 +- .../drill/exec/expr/fn/impl/MathFunctions.java | 31 ++ .../exec/resolver/DefaultFunctionResolver.java | 22 + .../drill/exec/resolver/FunctionResolver.java | 12 + .../exec/resolver/FunctionResolverFactory.java | 18 + .../exec/resolver/OperatorFunctionResolver.java | 52 +++ .../exec/resolver/ResolverTypePrecedence.java | 41 ++ .../drill/exec/resolver/TypeCastRules.java | 466 +++++++++++++++++++ .../exec/resolver/UDFFunctionResolver.java | 17 + exec/ref/src/test/resources/simple_plan.json | 131 +++--- pom.xml | 10 +- sqlline | 1 + 15 files changed, 807 insertions(+), 66 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/36945428/common/src/main/java/org/apache/drill/common/expression/fn/MathFunctions.java ---------------------------------------------------------------------- diff --git a/common/src/main/java/org/apache/drill/common/expression/fn/MathFunctions.java b/common/src/main/java/org/apache/drill/common/expression/fn/MathFunctions.java index ee3a099..12b821d 100644 --- a/common/src/main/java/org/apache/drill/common/expression/fn/MathFunctions.java +++ b/common/src/main/java/org/apache/drill/common/expression/fn/MathFunctions.java @@ -30,7 +30,7 @@ public class MathFunctions implements CallProvider{ @Override public FunctionDefinition[] getFunctionDefintions() { return new FunctionDefinition[]{ - FunctionDefinition.operator("add", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "+"), + FunctionDefinition.operator("add", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, false), new OutputTypeDeterminer.SameAsAnySoft(), "+"), FunctionDefinition.operator("subtract", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "-"), FunctionDefinition.operator("divide", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "/"), FunctionDefinition.operator("multiply", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "*"), http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/36945428/exec/java-exec/src/main/java/org/apache/drill/exec/ExecConstants.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/ExecConstants.java b/exec/java-exec/src/main/java/org/apache/drill/exec/ExecConstants.java index 5336c0e..436d820 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/ExecConstants.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/ExecConstants.java @@ -50,4 +50,6 @@ public interface ExecConstants { public static final String SPOOLING_BUFFER_IMPL = "drill.exec.spooling.impl"; public static final String SPOOLING_BUFFER_DELETE = "drill.exec.spooling.delete"; public static final String SPOOLING_BUFFER_MEMORY = "drill.exec.spooling.size"; + public static final String NULL_EXPRESSION = "NULLEXPRESSION"; + } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/36945428/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java index e6ef802..d2b7e47 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java @@ -24,12 +24,16 @@ 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.ExecConstants; 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.annotations.FunctionTemplate; import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope; import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling; +import org.apache.drill.exec.record.NullExpression; +import org.apache.drill.exec.resolver.ResolverTypePrecedence; +import org.apache.drill.exec.resolver.TypeCastRules; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -149,6 +153,51 @@ public abstract class DrillFuncHolder { return true; } + + public int getCost(FunctionCall call){ + int cost = 0; + + if(call.args.size() != parameters.length){ + return -1; + } + for(int i =0; i < parameters.length; i++){ + ValueReference param = parameters[i]; + LogicalExpression callarg = call.args.get(i); + + Integer paramval = ResolverTypePrecedence.precedenceMap.get(param.type.getMinorType().name()); + Integer callval = null; + + if(!TypeCastRules.isCastable(param.type.getMinorType(), callarg.getMajorType().getMinorType())){ + return -1; + } + + /** Allow NULL Expression/Arguments in casting **/ + if(callarg == null || callarg instanceof NullExpression) + { + callval = ResolverTypePrecedence.precedenceMap.get(ExecConstants.NULL_EXPRESSION); + } + else + { + callval = ResolverTypePrecedence.precedenceMap.get(callarg.getMajorType().getMinorType().name()); + } + + if(paramval==null || callval==null){ + // TODO: Throw exception, Compatibility precedence not defined + return -1; + } + + if(paramval - callval<0){ + return -1; + } + + cost += paramval - callval; + + } + return cost; + } + + + private boolean softCompare(MajorType a, MajorType b){ return Types.softEquals(a, b, nullHandling == NullHandling.NULL_IF_NULL); } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/36945428/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionImplementationRegistry.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionImplementationRegistry.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionImplementationRegistry.java index 761195e..227caf7 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionImplementationRegistry.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionImplementationRegistry.java @@ -27,6 +27,8 @@ 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 org.apache.drill.exec.resolver.FunctionResolver; +import org.apache.drill.exec.resolver.FunctionResolverFactory; import com.beust.jcommander.internal.Lists; import com.google.common.collect.ArrayListMultimap; @@ -52,11 +54,18 @@ public class FunctionImplementationRegistry { public DrillFuncHolder getFunction(FunctionCall call){ - for(DrillFuncHolder h : methods.get(call.getDefinition().getName())){ - if(h.matches(call)){ - return h; - } - } + + + FunctionResolver resolver = FunctionResolverFactory.getResolver(call); + DrillFuncHolder matchedFuncHolder = resolver.getBestMatch(methods.get(call.getDefinition().getName()), call); + + + if(null != matchedFuncHolder){ + return matchedFuncHolder; + } + + + List<MajorType> types = Lists.newArrayList(); for(LogicalExpression e : call.args){ types.add(e.getMajorType()); http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/36945428/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/MathFunctions.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/MathFunctions.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/MathFunctions.java index 288760b..ea251c3 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/MathFunctions.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/MathFunctions.java @@ -24,6 +24,8 @@ import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling; import org.apache.drill.exec.expr.annotations.Output; import org.apache.drill.exec.expr.annotations.Param; import org.apache.drill.exec.expr.holders.BigIntHolder; +import org.apache.drill.exec.expr.holders.Float4Holder; +import org.apache.drill.exec.expr.holders.Float8Holder; import org.apache.drill.exec.expr.holders.IntHolder; import org.apache.drill.exec.record.RecordBatch; @@ -62,6 +64,35 @@ public class MathFunctions{ } + @FunctionTemplate(name = "add", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) + public static class Float4Add implements DrillSimpleFunc{ + + @Param Float4Holder left; + @Param Float4Holder right; + @Output Float4Holder out; + + public void setup(RecordBatch b){} + + public void eval(){ + out.value = left.value + right.value; + } + } + + + @FunctionTemplate(name = "add", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) + public static class Float8Add implements DrillSimpleFunc{ + + @Param Float8Holder left; + @Param Float8Holder right; + @Output Float8Holder out; + + public void setup(RecordBatch b){} + + public void eval(){ + out.value = left.value + right.value; + } + } + @FunctionTemplate(name = "negative", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) public static class Negative implements DrillSimpleFunc{ http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/36945428/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/DefaultFunctionResolver.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/DefaultFunctionResolver.java b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/DefaultFunctionResolver.java new file mode 100644 index 0000000..ed19e8a --- /dev/null +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/DefaultFunctionResolver.java @@ -0,0 +1,22 @@ +package org.apache.drill.exec.resolver; + +import java.util.List; + +import org.apache.drill.common.expression.FunctionCall; +import org.apache.drill.exec.expr.fn.DrillFuncHolder; + +public class DefaultFunctionResolver implements FunctionResolver { + + @Override + public DrillFuncHolder getBestMatch(List<DrillFuncHolder> methods,FunctionCall call) { + for(DrillFuncHolder h : methods){ + if(h.matches(call)){ + return h; + } + } + + return null; + + } + +} http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/36945428/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/FunctionResolver.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/FunctionResolver.java b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/FunctionResolver.java new file mode 100644 index 0000000..7137ae3 --- /dev/null +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/FunctionResolver.java @@ -0,0 +1,12 @@ +package org.apache.drill.exec.resolver; + +import java.util.List; + +import org.apache.drill.common.expression.FunctionCall; +import org.apache.drill.exec.expr.fn.DrillFuncHolder; + +public interface FunctionResolver { + + public DrillFuncHolder getBestMatch(List<DrillFuncHolder> methods, FunctionCall call); + +} http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/36945428/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/FunctionResolverFactory.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/FunctionResolverFactory.java b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/FunctionResolverFactory.java new file mode 100644 index 0000000..be33e35 --- /dev/null +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/FunctionResolverFactory.java @@ -0,0 +1,18 @@ +package org.apache.drill.exec.resolver; + +import org.apache.drill.common.expression.FunctionCall; + +public class FunctionResolverFactory { + + public static FunctionResolver getResolver(FunctionCall call){ + + if(call.getDefinition().isOperator()){ + return new OperatorFunctionResolver(); + } + else { + return new DefaultFunctionResolver(); + } + + } + +} http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/36945428/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/OperatorFunctionResolver.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/OperatorFunctionResolver.java b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/OperatorFunctionResolver.java new file mode 100644 index 0000000..5cb6f13 --- /dev/null +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/OperatorFunctionResolver.java @@ -0,0 +1,52 @@ +package org.apache.drill.exec.resolver; + +import java.util.List; + +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.exec.expr.fn.DrillFuncHolder; + +import com.google.common.collect.ImmutableList; + +public class OperatorFunctionResolver implements FunctionResolver { + + @Override + public DrillFuncHolder getBestMatch(List<DrillFuncHolder> methods, FunctionCall call) { + + ImmutableList<LogicalExpression> args = call.args; + + if(args.size() != 2){ + // TODO: Some Exception + } + + + int bestcost = Integer.MAX_VALUE; + int currcost = Integer.MAX_VALUE; + DrillFuncHolder bestmatch = null; + + for(DrillFuncHolder h : methods){ + currcost = h.getCost(call); + + if(currcost == -1){ + //TODO: check for explicit type cast here + continue; + } + + if(currcost < bestcost){ + bestcost = currcost; + bestmatch = h; + } + } + + /** TODO: Convert the function call to new datatypes **/ + + /*if(bestmatch.matches(call)){ + return bestmatch; + }*/ + + + return bestmatch; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/36945428/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ResolverTypePrecedence.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ResolverTypePrecedence.java b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ResolverTypePrecedence.java new file mode 100644 index 0000000..2a772ed --- /dev/null +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ResolverTypePrecedence.java @@ -0,0 +1,41 @@ +package org.apache.drill.exec.resolver; + +import java.util.HashMap; +import java.util.Map; + +public class ResolverTypePrecedence { + + +public static final Map<String, Integer> precedenceMap; + + static { + + precedenceMap = new HashMap<String, Integer>(); + precedenceMap.put("NULLEXPRESSION", 0); + precedenceMap.put("FIXEDBINARY", 1); + precedenceMap.put("VARBINARY", 2); + precedenceMap.put("VARCHAR", 3); + precedenceMap.put("VAR16CHAR", 4); + precedenceMap.put("FIXEDCHAR", 5); + precedenceMap.put("FIXED16CHAR", 6); + precedenceMap.put("BIT", 7); + precedenceMap.put("TINYINT", 8); + precedenceMap.put("SMALLINT", 9); + precedenceMap.put("INT", 10); + precedenceMap.put("BIGINT", 11); + precedenceMap.put("MONEY", 12); + precedenceMap.put("DECIMAL4", 13); + precedenceMap.put("DECIMAL8", 14); + precedenceMap.put("DECIMAL12", 15); + precedenceMap.put("DECIMAL16", 16); + precedenceMap.put("FLOAT4", 17); + precedenceMap.put("FLOAT8", 18); + precedenceMap.put("TIMETZ", 19); + precedenceMap.put("TIME", 20); + precedenceMap.put("DATE", 21); + precedenceMap.put("DATETIME", 22); + + } + + +} http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/36945428/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java new file mode 100644 index 0000000..76d52be --- /dev/null +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java @@ -0,0 +1,466 @@ +package org.apache.drill.exec.resolver; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.drill.common.types.TypeProtos.MinorType; + +public class TypeCastRules { + + private static Map<MinorType, Set<MinorType>> rules; + + public TypeCastRules(){ + + + rules = new HashMap<MinorType, Set<MinorType>>(); + + Set<MinorType> rule; + + /** TINYINT cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.DECIMAL12); + rule.add(MinorType.DECIMAL16); + rule.add(MinorType.MONEY); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.FLOAT8); + rule.add(MinorType.BIT); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.FIXEDBINARY); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rule.add(MinorType.VARBINARY); + rules.put(MinorType.TINYINT, rule); + + /** SMALLINT cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.DECIMAL12); + rule.add(MinorType.DECIMAL16); + rule.add(MinorType.MONEY); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.FLOAT8); + rule.add(MinorType.BIT); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.FIXEDBINARY); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rule.add(MinorType.VARBINARY); + rules.put(MinorType.SMALLINT, rule); + + /** INT cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.DECIMAL12); + rule.add(MinorType.DECIMAL16); + rule.add(MinorType.MONEY); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.FLOAT8); + rule.add(MinorType.BIT); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.FIXEDBINARY); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rule.add(MinorType.VARBINARY); + rules.put(MinorType.INT, rule); + + /** BIGINT cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.DECIMAL12); + rule.add(MinorType.DECIMAL16); + rule.add(MinorType.MONEY); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.FLOAT8); + rule.add(MinorType.BIT); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.FIXEDBINARY); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rule.add(MinorType.VARBINARY); + rules.put(MinorType.BIGINT, rule); + + /** DECIMAL4 cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.MONEY); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.FLOAT8); + rule.add(MinorType.BIT); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.FIXEDBINARY); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rule.add(MinorType.VARBINARY); + rules.put(MinorType.DECIMAL4, rule); + + /** DECIMAL8 cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.MONEY); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.FLOAT8); + rule.add(MinorType.BIT); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.FIXEDBINARY); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rule.add(MinorType.VARBINARY); + rules.put(MinorType.DECIMAL8, rule); + + /** DECIMAL12 cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.DECIMAL12); + rule.add(MinorType.MONEY); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.FLOAT8); + rule.add(MinorType.BIT); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.FIXEDBINARY); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rule.add(MinorType.VARBINARY); + rules.put(MinorType.DECIMAL12, rule); + + /** DECIMAL16 cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.DECIMAL12); + rule.add(MinorType.DECIMAL16); + rule.add(MinorType.MONEY); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.FLOAT8); + rule.add(MinorType.BIT); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.FIXEDBINARY); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rule.add(MinorType.VARBINARY); + rules.put(MinorType.DECIMAL16, rule); + + /** MONEY cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.DECIMAL12); + rule.add(MinorType.DECIMAL16); + rule.add(MinorType.MONEY); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.FLOAT8); + rule.add(MinorType.BIT); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.FIXEDBINARY); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rule.add(MinorType.VARBINARY); + rules.put(MinorType.MONEY, rule); + + /** DATE cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.DATE); + rule.add(MinorType.DATETIME); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.FIXEDBINARY); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rule.add(MinorType.VARBINARY); + rules.put(MinorType.DATE, rule); + + /** TIME cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TIME); + rule.add(MinorType.DATETIME); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.FIXEDBINARY); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rule.add(MinorType.VARBINARY); + rules.put(MinorType.TIME, rule); + + /** DATETIME cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.DATETIME); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.DECIMAL12); + rule.add(MinorType.DECIMAL16); + rule.add(MinorType.DATE); + rule.add(MinorType.TIME); + rule.add(MinorType.TIMESTAMP); + rules.put(MinorType.DATETIME, rule); + + /** FLOAT4 cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.DECIMAL12); + rule.add(MinorType.DECIMAL16); + rule.add(MinorType.MONEY); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.BIT); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rules.put(MinorType.FLOAT4, rule); + + /** FLOAT8 cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.DECIMAL12); + rule.add(MinorType.DECIMAL16); + rule.add(MinorType.MONEY); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.FLOAT8); + rule.add(MinorType.BIT); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rules.put(MinorType.FLOAT8, rule); + + /** BIT cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.DECIMAL12); + rule.add(MinorType.DECIMAL16); + rule.add(MinorType.MONEY); + rule.add(MinorType.TIMESTAMP); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.FLOAT8); + rule.add(MinorType.BIT); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rule.add(MinorType.VARBINARY); + rule.add(MinorType.FIXEDBINARY); + rules.put(MinorType.BIT, rule); + + /** FIXEDCHAR cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.DECIMAL12); + rule.add(MinorType.DECIMAL16); + rule.add(MinorType.MONEY); + rule.add(MinorType.TIMESTAMP); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.FLOAT8); + rule.add(MinorType.BIT); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rule.add(MinorType.VARBINARY); + rule.add(MinorType.FIXEDBINARY); + rule.add(MinorType.DATE); + rule.add(MinorType.TIME); + rule.add(MinorType.DATETIME); + rules.put(MinorType.FIXEDCHAR, rule); + + /** FIXED16CHAR cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.DECIMAL12); + rule.add(MinorType.DECIMAL16); + rule.add(MinorType.MONEY); + rule.add(MinorType.TIMESTAMP); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.FLOAT8); + rule.add(MinorType.BIT); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rule.add(MinorType.VARBINARY); + rule.add(MinorType.FIXEDBINARY); + rule.add(MinorType.DATE); + rule.add(MinorType.TIME); + rule.add(MinorType.DATETIME); + rules.put(MinorType.FIXED16CHAR, rule); + + /** FIXEDBINARY cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.DECIMAL12); + rule.add(MinorType.DECIMAL16); + rule.add(MinorType.MONEY); + rule.add(MinorType.TIMESTAMP); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.FLOAT8); + rule.add(MinorType.BIT); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rule.add(MinorType.VARBINARY); + rule.add(MinorType.FIXEDBINARY); + rules.put(MinorType.FIXEDBINARY, rule); + + /** VARCHAR cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.DECIMAL12); + rule.add(MinorType.DECIMAL16); + rule.add(MinorType.MONEY); + rule.add(MinorType.TIMESTAMP); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.FLOAT8); + rule.add(MinorType.BIT); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rule.add(MinorType.VARBINARY); + rule.add(MinorType.FIXEDBINARY); + rule.add(MinorType.DATE); + rule.add(MinorType.TIME); + rule.add(MinorType.DATETIME); + rules.put(MinorType.VARCHAR, rule); + + /** VAR16CHAR cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.DECIMAL12); + rule.add(MinorType.DECIMAL16); + rule.add(MinorType.MONEY); + rule.add(MinorType.TIMESTAMP); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.FLOAT8); + rule.add(MinorType.BIT); + rule.add(MinorType.FIXEDCHAR); + rule.add(MinorType.FIXED16CHAR); + rule.add(MinorType.VARCHAR); + rule.add(MinorType.VAR16CHAR); + rule.add(MinorType.VARBINARY); + rule.add(MinorType.FIXEDBINARY); + rule.add(MinorType.DATE); + rule.add(MinorType.TIME); + rule.add(MinorType.DATETIME); + rules.put(MinorType.VAR16CHAR, rule); + + /** VARBINARY cast able from **/ + rule = new HashSet<MinorType>(); + rule.add(MinorType.TINYINT); + rule.add(MinorType.SMALLINT); + rule.add(MinorType.INT); + rule.add(MinorType.BIGINT); + rule.add(MinorType.DECIMAL4); + rule.add(MinorType.DECIMAL8); + rule.add(MinorType.DECIMAL12); + rule.add(MinorType.DECIMAL16); + rule.add(MinorType.MONEY); + rule.add(MinorType.TIMESTAMP); + rule.add(MinorType.FLOAT4); + rule.add(MinorType.FLOAT8); + rule.add(MinorType.BIT); + rule.add(MinorType.VARBINARY); + rule.add(MinorType.FIXEDBINARY); + rules.put(MinorType.VARBINARY, rule); + + + } + + public static boolean isCastable(MinorType from, MinorType to){ + return rules.get(from)==null ? false: rules.get(from).contains(to); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/36945428/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/UDFFunctionResolver.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/UDFFunctionResolver.java b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/UDFFunctionResolver.java new file mode 100644 index 0000000..94ba37d --- /dev/null +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/UDFFunctionResolver.java @@ -0,0 +1,17 @@ +package org.apache.drill.exec.resolver; + +import java.util.List; + +import org.apache.drill.common.expression.FunctionCall; +import org.apache.drill.exec.expr.fn.DrillFuncHolder; + +public class UDFFunctionResolver implements FunctionResolver { + + @Override + public DrillFuncHolder getBestMatch(List<DrillFuncHolder> methods, + FunctionCall call) { + // TODO Auto-generated method stub + return null; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/36945428/exec/ref/src/test/resources/simple_plan.json ---------------------------------------------------------------------- diff --git a/exec/ref/src/test/resources/simple_plan.json b/exec/ref/src/test/resources/simple_plan.json index c0837e6..ad3cdc7 100644 --- a/exec/ref/src/test/resources/simple_plan.json +++ b/exec/ref/src/test/resources/simple_plan.json @@ -13,69 +13,82 @@ cp: {type: "classpath"} }, query:[ - { - op:"sequence", - do:[ - { - op: "scan", - memo: "initial_scan", - ref: "donuts", - storageengine: "cp", - selection: { - path: "/donuts.json", - type: "JSON" - } - }, + + { + @id:"1", + op: "scan", + memo: "initial_scan", + ref: "donuts", + storageengine: "cp", + selection: { + path: "/donuts.json", + type: "JSON" + } + }, { - op: "transform", - transforms: [ - { ref: "quantity", expr: "donuts.sales"} - ] - }, - { - op: "filter", - expr: "donuts.ppu < 1.00" - }, - { - op: "segment", - ref: "ppusegment", - exprs: ["donuts.ppu"] - }, - { - op: "collapsingaggregate", - within: "ppusegment", - carryovers: ["donuts.ppu"], - aggregations: [ - { ref: "donuts.typeCount", expr: "count(1)" }, - { ref: "donuts.quantity", expr: "sum(quantity)" }, - { ref: "donuts.sales", expr: "sum(donuts.ppu * quantity)" } - ] - }, - { - op: "order", - orderings: [ - {order: "DESC", expr: "donuts.ppu" } - ] - }, - { - op: "project", - projections: [ - { ref: "output", expr: "donuts" } - ] - }, - { - op: "limit", + @id:"2", + input:"1", + op: "transform", + transforms: [ + { ref: "quantity", expr: "donuts.sales"} + ] + }, + { + @id:"3", + input:"2", + op: "filter", + expr: "donuts.ppu < 1.00" + }, + { + @id:"4", + input:"3", + op: "segment", + ref: "ppusegment", + exprs: ["donuts.ppu"] + }, + { + @id:"5", + input:"4", + op: "collapsingaggregate", + within: "ppusegment", + carryovers: ["donuts.ppu"], + aggregations: [ + { ref: "donuts.typeCount", expr: "count(1)" }, + { ref: "donuts.quantity", expr: "sum(quantity)" }, + { ref: "donuts.sales", expr: "sum(donuts.ppu * quantity)" } + ] + }, + { + @id:"6", + input:"5", + op: "order", + orderings: [ + {order: "DESC", expr: "donuts.ppu" } + ] + }, + { + @id:"7", + input:"6", + op: "project", + projections: [ + { ref: "output.output", expr: "donuts" } + ] + }, + { + @id:"8", + input:"7", + op: "limit", first: 0, last: 100 }, - { - op: "store", - memo: "output sink", - storageengine: "console", - target: {pipe: "STD_OUT"} - } - ] - } + { + @id:"9", + input:"8", + op: "store", + memo: "output sink", + storageengine: "console", + target: {pipe: "STD_OUT"} + } ] } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/36945428/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 69d280c..09c1522 100644 --- a/pom.xml +++ b/pom.xml @@ -90,6 +90,7 @@ <build> <plugins> + <!-- <plugin> <groupId>org.apache.rat</groupId> <artifactId>apache-rat-plugin</artifactId> @@ -118,7 +119,8 @@ </excludes> </configuration> </plugin> - + --> + <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> @@ -185,11 +187,13 @@ <pluginManagement> <plugins> + <!-- <plugin> <groupId>org.apache.rat</groupId> <artifactId>apache-rat-plugin</artifactId> <version>0.10</version> </plugin> + --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> @@ -300,6 +304,7 @@ <ignore /> </action> </pluginExecution> + <!-- <pluginExecution> <pluginExecutionFilter> <groupId>org.apache.rat</groupId> @@ -313,6 +318,7 @@ <ignore/> </action> </pluginExecution> + --> </pluginExecutions> </lifecycleMappingMetadata> </configuration> @@ -570,7 +576,9 @@ <id>mapr</id> <properties> <alt-hadoop>mapr</alt-hadoop> + <!-- <rat.excludeSubprojects>false</rat.excludeSubprojects> + --> </properties> <dependencyManagement> <dependencies> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/36945428/sqlline ---------------------------------------------------------------------- diff --git a/sqlline b/sqlline index 8cc9531..2cfbd89 100755 --- a/sqlline +++ b/sqlline @@ -26,6 +26,7 @@ fi #exec java -Drebel.log=true -javaagent:/src/jrebel/jrebel.jar -Dlogback.configurationFile=/src/drill/sandbox/prototype/sqlparser/src/test/resources/logback.xml -cp ./:"$(cat .classpath)" sqlline.SqlLine "$@" exec java -Xmx2G -Dlogback.configurationFile=./sqlparser/src/test/resources/logback.xml -cp ./:"$(cat .classpath)" sqlline.SqlLine --verbose=true "$@" +#exec java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xmx2G -Dlogback.configurationFile=./sqlparser/src/test/resources/logback.xml -cp ./:"$(cat .classpath)" sqlline.SqlLine --verbose=true "$@" # End sqlline
