diff options
author | Josiah Yan <josiah.yan@gmail.com> | 2017-08-02 22:50:54 +0800 |
---|---|---|
committer | Paul Rogers <progers@maprtech.com> | 2017-10-11 10:19:29 -0700 |
commit | a7b25714d824c7447a73251314383eccb9b7b18b (patch) | |
tree | 72bfa517001ed39957bc7040be1a97b9e9c97fe3 /exec/java-exec/src/main | |
parent | bbc42240483a0658691149aea3c509ccd0db4c79 (diff) |
DRILL-5645: negation of expression causes null pointer exception
closes #892
Diffstat (limited to 'exec/java-exec/src/main')
4 files changed, 20 insertions, 23 deletions
diff --git a/exec/java-exec/src/main/codegen/data/MathFunc.tdd b/exec/java-exec/src/main/codegen/data/MathFunc.tdd index f37310b90..feda49fbb 100644 --- a/exec/java-exec/src/main/codegen/data/MathFunc.tdd +++ b/exec/java-exec/src/main/codegen/data/MathFunc.tdd @@ -56,6 +56,19 @@ unaryMathFunctions : [ {input: "UInt8", outputType: "UInt8", castType: "long"} ] }, + {className: "Negative", funcName: "negative", javaFunc : " - ", types: [ + {input: "Int", outputType: "Int", castType: "int"}, + {input: "BigInt", outputType: "BigInt", castType: "long"}, + {input: "Float4", outputType: "Float4", castType: "float"}, + {input: "Float8", outputType: "Float8", castType: "double"}, + {input: "SmallInt", outputType: "SmallInt", castType: "short"}, + {input: "TinyInt", outputType: "TinyInt", castType: "byte"}, + {input: "UInt1", outputType: "UInt1", castType: "byte"}, + {input: "UInt2", outputType: "UInt2", castType: "char"}, + {input: "UInt4", outputType: "UInt4", castType: "int"}, + {input: "UInt8", outputType: "UInt8", castType: "long"} + ] + }, {className: "Sqrt", funcName: "sqrt", javaFunc : "java.lang.Math.sqrt", types: [ {input: "Int", outputType: "Int", castType: "int"}, {input: "BigInt", outputType: "BigInt", castType: "long"}, diff --git a/exec/java-exec/src/main/codegen/templates/MathFunctions.java b/exec/java-exec/src/main/codegen/templates/MathFunctions.java index 4144fcfd4..50ee6e6c2 100644 --- a/exec/java-exec/src/main/codegen/templates/MathFunctions.java +++ b/exec/java-exec/src/main/codegen/templates/MathFunctions.java @@ -59,7 +59,11 @@ public class GMathFunctions{ <#list func.types as type> + <#if func.funcName=="negative"> + @FunctionTemplate(names = {"negative", "u-", "-"}, scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) + <#else> @FunctionTemplate(name = "${func.funcName}", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) + </#if> public static class ${func.className}${type.input} implements DrillSimpleFunc { @Param ${type.input}Holder in; 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 0d5cd925d..52d1a64f3 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 @@ -35,21 +35,6 @@ public class MathFunctions{ private MathFunctions(){} - @FunctionTemplate(names = {"negative", "u-", "-"}, scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) - public static class Negative implements DrillSimpleFunc{ - - @Param BigIntHolder input; - @Output BigIntHolder out; - - public void setup(){} - - public void eval(){ - out.value = -input.value; - return; - } - - } - @FunctionTemplate(name = "power", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) public static class Power implements DrillSimpleFunc{ diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java index db0cfbd01..0d8efd567 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java @@ -167,14 +167,9 @@ public class DrillOptiq { return FunctionCallFactory.createExpression(call.getOperator().getName().toLowerCase(), ExpressionPosition.UNKNOWN, arg); case MINUS_PREFIX: - final RexBuilder builder = inputs.get(0).getCluster().getRexBuilder(); - final List<RexNode> operands = Lists.newArrayList(); - operands.add(builder.makeExactLiteral(new BigDecimal(-1))); - operands.add(call.getOperands().get(0)); - - return visitCall((RexCall) builder.makeCall( - SqlStdOperatorTable.MULTIPLY, - operands)); + List<LogicalExpression> operands = Lists.newArrayList(); + operands.add(call.getOperands().get(0).accept(this)); + return FunctionCallFactory.createExpression("u-", operands); } throw new AssertionError("todo: implement syntax " + syntax + "(" + call + ")"); case SPECIAL: |