use of org.apache.hadoop.hive.metastore.parser.ExpressionTree.LeafNode in project hive by apache.
the class TestHBaseFilterPlanUtil method testTreeNodePlan.
/**
* Test plan generation from TreeNode
*
* @throws MetaException
*/
@Test
public void testTreeNodePlan() throws MetaException {
final String KEY = "k1";
final String VAL1 = "10";
final String VAL2 = "11";
LeafNode l = new LeafNode();
l.keyName = KEY;
l.value = VAL1;
final ScanMarker DEFAULT_SCANMARKER = null;
List<FieldSchema> parts = new ArrayList<FieldSchema>();
parts.add(new FieldSchema("k1", "int", null));
LeafNode r = new LeafNode();
r.keyName = KEY;
r.value = VAL2;
TreeNode tn = new TreeNode(l, LogicalOperator.AND, r);
// verify plan for - k1 >= '10' and k1 < '11'
l.operator = Operator.GREATERTHANOREQUALTO;
r.operator = Operator.LESSTHAN;
verifyPlan(tn, parts, KEY, new ScanMarker(VAL1, INCLUSIVE, "int"), new ScanMarker(VAL2, !INCLUSIVE, "int"));
// verify plan for - k1 >= '10' and k1 > '11'
l.operator = Operator.GREATERTHANOREQUALTO;
r.operator = Operator.GREATERTHAN;
verifyPlan(tn, parts, KEY, new ScanMarker(VAL2, !INCLUSIVE, "int"), DEFAULT_SCANMARKER);
// verify plan for - k1 >= '10' or k1 > '11'
tn = new TreeNode(l, LogicalOperator.OR, r);
ExpressionTree e = new ExpressionTree();
e.setRootForTest(tn);
PlanResult planRes = HBaseFilterPlanUtil.getFilterPlan(e, parts);
Assert.assertEquals(2, planRes.plan.getPlans().size());
Assert.assertEquals(false, planRes.hasUnsupportedCondition);
// verify plan for - k1 >= '10' and (k1 >= '10' or k1 > '11')
TreeNode tn2 = new TreeNode(l, LogicalOperator.AND, tn);
e = new ExpressionTree();
e.setRootForTest(tn2);
planRes = HBaseFilterPlanUtil.getFilterPlan(e, parts);
Assert.assertEquals(2, planRes.plan.getPlans().size());
Assert.assertEquals(false, planRes.hasUnsupportedCondition);
// verify plan for (k1 >= '10' and (k1 >= '10' or k1 > '11')) or k1 LIKE '2'
// plan should return true for hasUnsupportedCondition
LeafNode klike = new LeafNode();
klike.keyName = KEY;
klike.value = VAL1;
klike.operator = Operator.LIKE;
TreeNode tn3 = new TreeNode(tn2, LogicalOperator.OR, klike);
e = new ExpressionTree();
e.setRootForTest(tn3);
planRes = HBaseFilterPlanUtil.getFilterPlan(e, parts);
Assert.assertEquals(3, planRes.plan.getPlans().size());
Assert.assertEquals(false, planRes.hasUnsupportedCondition);
}
use of org.apache.hadoop.hive.metastore.parser.ExpressionTree.LeafNode in project hive by apache.
the class TestHBaseFilterPlanUtil method testLeafNodePlan.
/**
* Test plan generation from LeafNode
*
* @throws MetaException
*/
@Test
public void testLeafNodePlan() throws MetaException {
final String KEY = "k1";
final String VAL = "v1";
final String OTHERKEY = "k2";
LeafNode l = new LeafNode();
l.keyName = KEY;
l.value = VAL;
final ScanMarker DEFAULT_SCANMARKER = null;
List<FieldSchema> parts = new ArrayList<FieldSchema>();
parts.add(new FieldSchema(KEY, "int", null));
parts.add(new FieldSchema(OTHERKEY, "int", null));
l.operator = Operator.EQUALS;
verifyPlan(l, parts, KEY, new ScanMarker(VAL, INCLUSIVE, "int"), new ScanMarker(VAL, INCLUSIVE, "int"));
l.operator = Operator.GREATERTHAN;
verifyPlan(l, parts, KEY, new ScanMarker(VAL, !INCLUSIVE, "int"), DEFAULT_SCANMARKER);
l.operator = Operator.GREATERTHANOREQUALTO;
verifyPlan(l, parts, KEY, new ScanMarker(VAL, INCLUSIVE, "int"), DEFAULT_SCANMARKER);
l.operator = Operator.LESSTHAN;
verifyPlan(l, parts, KEY, DEFAULT_SCANMARKER, new ScanMarker(VAL, !INCLUSIVE, "int"));
l.operator = Operator.LESSTHANOREQUALTO;
verifyPlan(l, parts, KEY, DEFAULT_SCANMARKER, new ScanMarker(VAL, INCLUSIVE, "int"));
// following leaf node plans should currently have true for 'has unsupported condition',
// because of the condition is not on first key
l.operator = Operator.EQUALS;
verifyPlan(l, parts, OTHERKEY, DEFAULT_SCANMARKER, DEFAULT_SCANMARKER, false);
// if tree is null, it should return equivalent of full scan, and true
// for 'has unsupported condition'
verifyPlan(null, parts, KEY, DEFAULT_SCANMARKER, DEFAULT_SCANMARKER, true);
}
Aggregations