You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by ja...@apache.org on 2015/03/26 07:26:43 UTC

[04/10] drill git commit: DRILL-2567: CONVERT_FROM in where clause cause the query to fail in planning phase

DRILL-2567: CONVERT_FROM in where clause cause the query to fail in planning phase

Set the writeIndex of ByteBuf returned by Unpooled.wrappedBuffer() to 0.

+ Added a unit test to exercise the code path.


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

Branch: refs/heads/0.8.0
Commit: 1c072fe8ed72bbcea3abf87b256903a42c9d3bec
Parents: 9652836
Author: Aditya Kishore <ad...@apache.org>
Authored: Wed Mar 25 15:00:54 2015 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Wed Mar 25 21:11:22 2015 -0700

----------------------------------------------------------------------
 .../store/hbase/CompareFunctionsProcessor.java  | 20 +++++++++++++-------
 .../drill/hbase/TestHBaseFilterPushDown.java    | 13 +++++++++++++
 2 files changed, 26 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/1c072fe8/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/CompareFunctionsProcessor.java
----------------------------------------------------------------------
diff --git a/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/CompareFunctionsProcessor.java b/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/CompareFunctionsProcessor.java
index 1635c5d..803f520 100644
--- a/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/CompareFunctionsProcessor.java
+++ b/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/CompareFunctionsProcessor.java
@@ -119,7 +119,7 @@ class CompareFunctionsProcessor extends AbstractExprVisitor<Boolean, LogicalExpr
       case "UINT4":
         if (valueArg instanceof IntExpression
             && (isEqualityFn || encodingType.startsWith("U"))) {
-          bb = Unpooled.wrappedBuffer(new byte[4]).order(encodingType.endsWith("_BE") ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
+          bb = newByteBuf(4, encodingType.endsWith("_BE"));
           bb.writeInt(((IntExpression)valueArg).getInt());
         }
         break;
@@ -129,39 +129,39 @@ class CompareFunctionsProcessor extends AbstractExprVisitor<Boolean, LogicalExpr
       case "UINT8":
         if (valueArg instanceof LongExpression
             && (isEqualityFn || encodingType.startsWith("U"))) {
-          bb = Unpooled.wrappedBuffer(new byte[8]).order(encodingType.endsWith("_BE") ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
+          bb = newByteBuf(8, encodingType.endsWith("_BE"));
           bb.writeLong(((LongExpression)valueArg).getLong());
         }
         break;
       case "FLOAT":
         if (valueArg instanceof FloatExpression && isEqualityFn) {
-          bb = Unpooled.wrappedBuffer(new byte[4]).order(ByteOrder.BIG_ENDIAN);
+          bb = newByteBuf(4, true);
           bb.writeFloat(((FloatExpression)valueArg).getFloat());
         }
         break;
       case "DOUBLE":
         if (valueArg instanceof DoubleExpression && isEqualityFn) {
-          bb = Unpooled.wrappedBuffer(new byte[8]).order(ByteOrder.BIG_ENDIAN);;
+          bb = newByteBuf(8, true);
           bb.writeDouble(((DoubleExpression)valueArg).getDouble());
         }
         break;
       case "TIME_EPOCH":
       case "TIME_EPOCH_BE":
         if (valueArg instanceof TimeExpression) {
-          bb = Unpooled.wrappedBuffer(new byte[8]).order(encodingType.endsWith("_BE") ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
+          bb = newByteBuf(8, encodingType.endsWith("_BE"));
           bb.writeLong(((TimeExpression)valueArg).getTime());
         }
         break;
       case "DATE_EPOCH":
       case "DATE_EPOCH_BE":
         if (valueArg instanceof DateExpression) {
-          bb = Unpooled.wrappedBuffer(new byte[8]).order(encodingType.endsWith("_BE") ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
+          bb = newByteBuf(8, encodingType.endsWith("_BE"));
           bb.writeLong(((DateExpression)valueArg).getDate());
         }
         break;
       case "BOOLEAN_BYTE":
         if (valueArg instanceof BooleanExpression) {
-          bb = Unpooled.wrappedBuffer(new byte[1]);
+          bb = newByteBuf(1, false /* does not matter */);
           bb.writeByte(((BooleanExpression)valueArg).getBoolean() ? 1 : 0);
         }
         break;
@@ -194,6 +194,12 @@ class CompareFunctionsProcessor extends AbstractExprVisitor<Boolean, LogicalExpr
     return false;
   }
 
+  private static ByteBuf newByteBuf(int size, boolean bigEndian) {
+    return Unpooled.wrappedBuffer(new byte[size])
+        .order(bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN)
+        .writerIndex(0);
+  }
+
   private static final ImmutableSet<Class<? extends LogicalExpression>> VALUE_EXPRESSION_CLASSES;
   static {
     ImmutableSet.Builder<Class<? extends LogicalExpression>> builder = ImmutableSet.builder();

http://git-wip-us.apache.org/repos/asf/drill/blob/1c072fe8/contrib/storage-hbase/src/test/java/org/apache/drill/hbase/TestHBaseFilterPushDown.java
----------------------------------------------------------------------
diff --git a/contrib/storage-hbase/src/test/java/org/apache/drill/hbase/TestHBaseFilterPushDown.java b/contrib/storage-hbase/src/test/java/org/apache/drill/hbase/TestHBaseFilterPushDown.java
index 4e63a3d..ca4c07c 100644
--- a/contrib/storage-hbase/src/test/java/org/apache/drill/hbase/TestHBaseFilterPushDown.java
+++ b/contrib/storage-hbase/src/test/java/org/apache/drill/hbase/TestHBaseFilterPushDown.java
@@ -118,6 +118,19 @@ public class TestHBaseFilterPushDown extends BaseHBaseTest {
   }
 
   @Test
+  public void testFilterPushDownConvertExpressionWithNumber() throws Exception {
+    setColumnWidths(new int[] {8, 1100});
+    runHBaseSQLVerifyCount("EXPLAIN PLAN FOR\n"
+        + "SELECT\n"
+        + "  row_key\n"
+        + "FROM\n"
+        + "  hbase.`[TABLE_NAME]` tableName\n"
+        + "WHERE\n"
+        + "  convert_from(row_key, 'INT_BE') = 75"
+        , 1);
+  }
+
+  @Test
   public void testFilterPushDownRowKeyLessThanOrEqualTo() throws Exception {
     setColumnWidths(new int[] {8, 74, 38});
     runHBaseSQLVerifyCount("SELECT\n"