Skip to content

Commit

Permalink
DRILL-2567: CONVERT_FROM in where clause cause the query to fail in p…
Browse files Browse the repository at this point in the history
…lanning phase

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

+ Added a unit test to exercise the code path.
  • Loading branch information
adityakishore authored and jacques-n committed Mar 26, 2015
1 parent ff3bab7 commit 141a1d6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Expand Up @@ -119,7 +119,7 @@ public Boolean visitConvertExpression(ConvertExpression e, LogicalExpression val
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;
Expand All @@ -129,39 +129,39 @@ public Boolean visitConvertExpression(ConvertExpression e, LogicalExpression val
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;
Expand Down Expand Up @@ -194,6 +194,12 @@ public Boolean visitSchemaPath(SchemaPath path, LogicalExpression valueArg) thro
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();
Expand Down
Expand Up @@ -117,6 +117,19 @@ public void testFilterPushDownConvertExpression() throws Exception {
, 2);
}

@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});
Expand Down

0 comments on commit 141a1d6

Please sign in to comment.