Skip to content
Permalink
Browse files
DRILL-6489: Fix filter push down for Hbase & Mapr-DB binary tables wh…
…en convert function is used in a view
  • Loading branch information
arina-ielchiieva committed Jun 13, 2018
1 parent cbcb59d commit 63d0251502ac7a3af5a761b1a70a958ca0be1ae1
Showing 2 changed files with 33 additions and 0 deletions.
@@ -22,6 +22,8 @@

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.drill.common.expression.CastExpression;
import org.apache.drill.common.expression.ConvertExpression;
@@ -51,6 +53,10 @@
import com.google.common.collect.ImmutableSet;

public class CompareFunctionsProcessor extends AbstractExprVisitor<Boolean, LogicalExpression, RuntimeException> {

// to check that function name starts with convert_from disregarding the case and has encoding after
private static final Pattern convertFromPattern = Pattern.compile(String.format("^%s(.+)", ConvertExpression.CONVERT_FROM), Pattern.CASE_INSENSITIVE);

private byte[] value;
private boolean success;
private boolean isEqualityFn;
@@ -511,6 +517,17 @@ public Boolean visitSchemaPath(SchemaPath path, LogicalExpression valueArg) thro
return false;
}

@Override
public Boolean visitFunctionCall(FunctionCall call, LogicalExpression valueArg) {
Matcher matcher = convertFromPattern.matcher(call.getName());
if (matcher.find()) {
// convert function call to ConvertExpression
ConvertExpression convert = new ConvertExpression(ConvertExpression.CONVERT_FROM, matcher.group(1), call.args.get(0), call.getPosition());
return visitConvertExpression(convert, valueArg);
}
return false;
}

protected static ByteBuf newByteBuf(int size, boolean bigEndian) {
return Unpooled.wrappedBuffer(new byte[size])
.order(bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN)
@@ -780,5 +780,21 @@ public void testDummyColumnsAreAvoided() throws Exception {
runHBaseSQLVerifyCount(sql, 2);
}

@Test
public void testConvertFromPushDownWithView() throws Exception {
test("create view dfs.tmp.pd_view as\n" +
"select convert_from(byte_substr(row_key, 1, 8), 'date_epoch_be') as d\n" +
"from hbase.`TestTableCompositeDate`");

String query = "select d from dfs.tmp.pd_view where d > date '2015-06-13' and d < DATE '2015-06-18'";
String[] expectedPlan = {
"startRow=\\\\x00\\\\x00\\\\x01M\\\\xEF\\]\\\\xA0\\\\x00, " +
"stopRow=\\\\x00\\\\x00\\\\x01N\\\\x03\\\\xF7\\\\x10\\\\x00, " +
"filter=null"};
String[] excludedPlan ={"Filter\\("};
PlanTestBase.testPlanMatchingPatterns(query, expectedPlan, excludedPlan);

runHBaseSQLVerifyCount(query, 12);
}
}

0 comments on commit 63d0251

Please sign in to comment.