Repository: drill
Updated Branches:
refs/heads/master d32acdb90 -> fb25973b4
DRILL-3305: Raise exception if we encounter unknown RexNode in DrillOptiq
Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/fb25973b
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/fb25973b
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/fb25973b
Branch: refs/heads/master
Commit: fb25973b406d856f0edc9332aadd8e7152b27fa8
Parents: c2a2377
Author: Mehant Baid <mehantr@gmail.com>
Authored: Wed Jun 17 14:42:53 2015 -0700
Committer: Mehant Baid <mehantr@gmail.com>
Committed: Wed Jun 17 14:43:02 2015 -0700
----------------------------------------------------------------------
.../drill/exec/planner/logical/DrillOptiq.java | 8 ++-
.../exec/planner/logical/DrillOptiqTest.java | 66 ++++++++++++++++++++
2 files changed, 71 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/drill/blob/fb25973b/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 daf2567..8b95f0b 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
@@ -63,6 +63,7 @@ import org.apache.drill.exec.work.ExecErrorConstants;
* Utilities for Drill's planner.
*/
public class DrillOptiq {
+ public static final String UNSUPPORTED_REX_NODE_ERROR = "Cannot convert RexNode to equivalent
Drill expression. ";
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillOptiq.class);
/**
@@ -206,9 +207,10 @@ public class DrillOptiq {
}
}
- private LogicalExpression doUnknown(Object o){
- logger.warn("Doesn't currently support consumption of {}.", o);
- return NullExpression.INSTANCE;
+ private LogicalExpression doUnknown(RexNode o){
+ // raise an error
+ throw UserException.planError().message(UNSUPPORTED_REX_NODE_ERROR +
+ "RexNode Class: %s, RexNode Digest: %s", o.getClass().getName(), o.toString()).build();
}
@Override
public LogicalExpression visitLocalRef(RexLocalRef localRef) {
http://git-wip-us.apache.org/repos/asf/drill/blob/fb25973b/exec/java-exec/src/test/java/org/apache/drill/exec/planner/logical/DrillOptiqTest.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/planner/logical/DrillOptiqTest.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/planner/logical/DrillOptiqTest.java
new file mode 100644
index 0000000..c3a9c20
--- /dev/null
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/planner/logical/DrillOptiqTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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.planner.logical;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexFieldCollation;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.type.SqlTypeFactoryImpl;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.drill.common.exceptions.UserException;
+import org.apache.drill.exec.planner.types.DrillRelDataTypeSystem;
+import org.junit.Assert;
+import org.junit.Test;
+import java.util.LinkedList;
+import java.util.List;
+
+public class DrillOptiqTest {
+
+ /* Method checks if we raise the appropriate error while dealing with RexNode that cannot
be converted to
+ * equivalent Drill expressions
+ */
+ @Test
+ public void testUnsupportedRexNode() {
+ try {
+ // Create the data type factory.
+ RelDataTypeFactory relFactory = new SqlTypeFactoryImpl(DrillRelDataTypeSystem.DRILL_REL_DATATYPE_SYSTEM);
+ // Create the rex builder
+ RexBuilder rex = new RexBuilder(relFactory);
+ RelDataType anyType = relFactory.createSqlType(SqlTypeName.ANY);
+ List<RexNode> emptyList = new LinkedList<>();
+ ImmutableList<RexFieldCollation> e = ImmutableList.copyOf(new RexFieldCollation[0]);
+
+ // create a dummy RexOver object.
+ RexNode window = rex.makeOver(anyType, SqlStdOperatorTable.AVG, emptyList, emptyList,
e, null, null, true,
+ false, false);
+ DrillOptiq.toDrill(null, null, window);
+ } catch (UserException e) {
+ if (e.getMessage().contains(DrillOptiq.UNSUPPORTED_REX_NODE_ERROR)) {
+ // got expected error return
+ return;
+ }
+ Assert.fail("Hit exception with unexpected error message");
+ }
+
+ Assert.fail("Failed to raise the expected exception");
+ }
+}
|