DRILL-437: Add support for POSTFIX operators.
1. IS NULL/IS NOT NULL
2. IS TRUE/IS FALSE
3. IS NOT TRUE/IS NOT FALSE


Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/d3c7abeb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/d3c7abeb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/d3c7abeb

Branch: refs/heads/master
Commit: d3c7abeb556cbb91af81746ed9397af366e5cfd3
Parents: f48d998
Author: vkorukanti <[email protected]>
Authored: Tue Apr 1 12:08:20 2014 -0700
Committer: Jacques Nadeau <[email protected]>
Committed: Sat Apr 19 18:07:10 2014 -0700

----------------------------------------------------------------------
 .../main/codegen/templates/NullOperator.java    | 75 ++++++++++++++++++++
 .../apache/drill/exec/expr/fn/impl/IsFalse.java | 57 +++++++++++++++
 .../drill/exec/expr/fn/impl/IsNotFalse.java     | 57 +++++++++++++++
 .../drill/exec/expr/fn/impl/IsNotNull.java      | 40 -----------
 .../drill/exec/expr/fn/impl/IsNotTrue.java      | 56 +++++++++++++++
 .../apache/drill/exec/expr/fn/impl/IsNull.java  | 40 -----------
 .../apache/drill/exec/expr/fn/impl/IsTrue.java  | 56 +++++++++++++++
 .../drill/exec/planner/logical/DrillOptiq.java  | 11 +++
 .../drill/exec/resolver/TypeCastRules.java      |  8 ++-
 9 files changed, 317 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d3c7abeb/exec/java-exec/src/main/codegen/templates/NullOperator.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/NullOperator.java 
b/exec/java-exec/src/main/codegen/templates/NullOperator.java
new file mode 100644
index 0000000..054294b
--- /dev/null
+++ b/exec/java-exec/src/main/codegen/templates/NullOperator.java
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+<@pp.dropOutputFile />
+<#list vv.modes as mode>
+<#list vv.types as type>
+<#list type.minor as minor>
+
+<#assign className="GNullOp${mode.prefix}${minor.class}Holder" />
+
+<@pp.changeOutputFile 
name="/org/apache/drill/exec/expr/fn/impl/${className}.java" />
+
+<#include "/@includes/license.ftl" />
+
+package org.apache.drill.exec.expr.fn.impl;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.*;
+import org.apache.drill.exec.expr.holders.*;
+import org.apache.drill.exec.record.RecordBatch;
+
+public class ${className} {
+
+  @FunctionTemplate(names = {"isNull", "isnull", "is null"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.INTERNAL)
+  public static class IsNull implements DrillSimpleFunc {
+
+    @Param ${mode.prefix}${minor.class}Holder input;
+    @Output BitHolder out;
+
+    public void setup(RecordBatch incoming) { }
+
+    public void eval() {
+    <#if mode.name == "Optional">
+      out.value = (input.isSet == 0 ? 1 : 0);
+    <#else>
+      out.value = 0;
+    </#if>
+    }
+  }
+
+  @FunctionTemplate(names = {"isNotNull", "isnotnull", "is not null"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.INTERNAL)
+  public static class IsNotNull implements DrillSimpleFunc {
+
+    @Param ${mode.prefix}${minor.class}Holder input;
+    @Output BitHolder out;
+
+    public void setup(RecordBatch incoming) { }
+
+    public void eval() {
+    <#if mode.name == "Optional">
+      out.value = (input.isSet == 0 ? 0 : 1);
+    <#else>
+      out.value = 1;
+    </#if>
+    }
+  }
+}
+
+</#list>
+</#list>
+</#list>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d3c7abeb/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsFalse.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsFalse.java 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsFalse.java
new file mode 100644
index 0000000..72db649
--- /dev/null
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsFalse.java
@@ -0,0 +1,57 @@
+/**
+ * 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.expr.fn.impl;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.*;
+import org.apache.drill.exec.expr.holders.*;
+import org.apache.drill.exec.record.RecordBatch;
+
+public class IsFalse {
+
+  @FunctionTemplate(names = {"isFalse", "isfalse", "is false"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.INTERNAL)
+  public static class Optional implements DrillSimpleFunc {
+
+    @Param NullableBitHolder in;
+    @Output BitHolder out;
+
+    public void setup(RecordBatch incoming) { }
+
+    public void eval() {
+      if (in.isSet == 0)
+        out.value = 0;
+      else
+        out.value = (in.value == 0 ? 1 : 0);
+    }
+  }
+
+  @FunctionTemplate(names = {"isFalse", "isfalse", "is false"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.INTERNAL)
+  public static class Required implements DrillSimpleFunc {
+
+    @Param BitHolder in;
+    @Output BitHolder out;
+
+    public void setup(RecordBatch incoming) { }
+
+    public void eval() {
+      out.value = in.value == 0 ? 1 : 0;
+    }
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d3c7abeb/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotFalse.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotFalse.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotFalse.java
new file mode 100644
index 0000000..7fe5f2b
--- /dev/null
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotFalse.java
@@ -0,0 +1,57 @@
+/**
+ * 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.expr.fn.impl;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.*;
+import org.apache.drill.exec.expr.holders.*;
+import org.apache.drill.exec.record.RecordBatch;
+
+public class IsNotFalse {
+
+  @FunctionTemplate(names = {"isNotFalse", "isnotfalse", "is not false"}, 
scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.INTERNAL)
+  public static class Optional implements DrillSimpleFunc {
+
+    @Param NullableBitHolder in;
+    @Output BitHolder out;
+
+    public void setup(RecordBatch incoming) { }
+
+    public void eval() {
+      if (in.isSet == 0)
+        out.value = 1;
+      else
+        out.value = in.value;
+    }
+  }
+
+  @FunctionTemplate(names = {"isNotFalse", "isnotfalse", "is not false"}, 
scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.INTERNAL)
+  public static class Required implements DrillSimpleFunc {
+
+    @Param BitHolder in;
+    @Output BitHolder out;
+
+    public void setup(RecordBatch incoming) { }
+
+    public void eval() {
+      out.value = in.value;
+    }
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d3c7abeb/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotNull.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotNull.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotNull.java
deleted file mode 100644
index ad7a93e..0000000
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotNull.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * 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.expr.fn.impl;
-
-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.BitHolder;
-import org.apache.drill.exec.expr.holders.NullableFloat8Holder;
-import org.apache.drill.exec.record.RecordBatch;
-
-@FunctionTemplate(names = {"isNotNull", "isnotnull"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE)
-public class IsNotNull implements DrillSimpleFunc {
-
-  @Param NullableFloat8Holder input;
-  @Output BitHolder out;
-
-  public void setup(RecordBatch incoming) { }
-
-  public void eval() {
-    out.value = (input.isSet == 0 ? 0 : 1);
-  }
-}
-

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d3c7abeb/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotTrue.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotTrue.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotTrue.java
new file mode 100644
index 0000000..5e0bf48
--- /dev/null
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotTrue.java
@@ -0,0 +1,56 @@
+/**
+ * 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.expr.fn.impl;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.*;
+import org.apache.drill.exec.expr.holders.*;
+import org.apache.drill.exec.record.RecordBatch;
+
+public class IsNotTrue {
+
+  @FunctionTemplate(names = {"isNotTrue", "isnottrue", "is not true"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.INTERNAL)
+  public static class Optional implements DrillSimpleFunc {
+
+    @Param NullableBitHolder in;
+    @Output BitHolder out;
+
+    public void setup(RecordBatch incoming) { }
+
+    public void eval() {
+      if (in.isSet == 0)
+        out.value = 1;
+      else
+        out.value = (in.value == 0 ? 1 : 0);
+    }
+  }
+
+  @FunctionTemplate(names = {"isNotTrue", "isnottrue", "is not true"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.INTERNAL)
+  public static class Required implements DrillSimpleFunc {
+
+    @Param BitHolder in;
+    @Output BitHolder out;
+
+    public void setup(RecordBatch incoming) { }
+
+    public void eval() {
+      out.value = in.value == 0 ? 1 : 0;
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d3c7abeb/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNull.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNull.java 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNull.java
deleted file mode 100644
index 02905d4..0000000
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNull.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * 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.expr.fn.impl;
-
-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.BitHolder;
-import org.apache.drill.exec.expr.holders.NullableFloat8Holder;
-import org.apache.drill.exec.record.RecordBatch;
-
-@FunctionTemplate(names = {"isNull", "isnull"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.INTERNAL)
-public class IsNull implements DrillSimpleFunc {
-
-  @Param NullableFloat8Holder input;
-  @Output BitHolder out;
-
-  public void setup(RecordBatch incoming) { }
-
-  public void eval() {
-    out.value = (input.isSet == 0 ? 1 : 0);
-  }
-}
-

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d3c7abeb/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsTrue.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsTrue.java 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsTrue.java
new file mode 100644
index 0000000..d85a807
--- /dev/null
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsTrue.java
@@ -0,0 +1,56 @@
+/**
+ * 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.expr.fn.impl;
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.*;
+import org.apache.drill.exec.expr.holders.*;
+import org.apache.drill.exec.record.RecordBatch;
+
+public class IsTrue {
+
+  @FunctionTemplate(names = {"isTrue", "istrue", "is true"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.INTERNAL)
+  public static class Optional implements DrillSimpleFunc {
+
+    @Param NullableBitHolder in;
+    @Output BitHolder out;
+
+    public void setup(RecordBatch incoming) { }
+
+    public void eval() {
+      if (in.isSet == 0)
+        out.value = 0;
+      else
+        out.value = in.value;
+    }
+  }
+
+  @FunctionTemplate(names = {"isTrue", "istrue", "is true"}, scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.INTERNAL)
+  public static class Required implements DrillSimpleFunc {
+
+    @Param BitHolder in;
+    @Output BitHolder out;
+
+    public void setup(RecordBatch incoming) { }
+
+    public void eval() {
+      out.value = in.value;
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d3c7abeb/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
----------------------------------------------------------------------
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 4926d7b..ad6aa3c 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
@@ -105,6 +105,17 @@ public class DrillOptiq {
       case FUNCTION:
         logger.debug("Function");
         return getDrillFunctionFromOptiqCall(call);
+      case POSTFIX:
+        logger.debug("Postfix");
+        switch(call.getKind()){
+        case IS_NULL:
+        case IS_TRUE:
+        case IS_FALSE:
+        case OTHER:
+          return 
FunctionCallFactory.createExpression(call.getOperator().getName().toLowerCase(),
+              ExpressionPosition.UNKNOWN, 
call.getOperands().get(0).accept(this));
+        }
+        throw new AssertionError("todo: implement syntax " + syntax + "(" + 
call + ")");
       case PREFIX:
         logger.debug("Prefix");
         LogicalExpression arg = call.getOperands().get(0).accept(this);

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/d3c7abeb/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
index ed89301..67769c9 100644
--- 
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
@@ -565,8 +565,10 @@ public class TypeCastRules {
     rules.put(MinorType.VARBINARY, rule);
   }
 
-  public static boolean isCastable(MajorType from, MajorType to) {
-    return from.getMinorType().equals(MinorType.NULL) ||      //null could be 
casted to any other type. 
+  public static boolean isCastable(MajorType from, MajorType to, NullHandling 
nullHandling) {
+    if (nullHandling == NullHandling.INTERNAL && from.getMode() != 
to.getMode()) return false;
+
+    return from.getMinorType().equals(MinorType.NULL) ||      //null could be 
casted to any other type.
            (rules.get(to.getMinorType()) == null ? false : 
rules.get(to.getMinorType()).contains(from.getMinorType()));
   }
 
@@ -586,7 +588,7 @@ public class TypeCastRules {
       MajorType argType = call.args.get(i).getMajorType();
       MajorType parmType = holder.getParmMajorType(i);
 
-      if (!TypeCastRules.isCastable(argType, parmType)) {
+      if (!TypeCastRules.isCastable(argType, parmType, 
holder.getNullHandling())) {
         return -1;
       }
 

Reply via email to