use of org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc in project hive by apache.
the class TestVectorizationContext method testBetweenFilters.
@Test
public void testBetweenFilters() throws HiveException {
// string tests
ExprNodeColumnDesc col1Expr = new ExprNodeColumnDesc(String.class, "col1", "table", false);
ExprNodeConstantDesc constDesc = new ExprNodeConstantDesc("Alpha");
ExprNodeConstantDesc constDesc2 = new ExprNodeConstantDesc("Bravo");
// string BETWEEN
GenericUDFBetween udf = new GenericUDFBetween();
List<ExprNodeDesc> children1 = new ArrayList<ExprNodeDesc>();
// no NOT keyword
children1.add(new ExprNodeConstantDesc(new Boolean(false)));
children1.add(col1Expr);
children1.add(constDesc);
children1.add(constDesc2);
ExprNodeGenericFuncDesc exprDesc = new ExprNodeGenericFuncDesc(TypeInfoFactory.booleanTypeInfo, udf, children1);
List<String> columns = new ArrayList<String>();
columns.add("col0");
columns.add("col1");
columns.add("col2");
VectorizationContext vc = new VectorizationContext("name", columns);
VectorExpression ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterStringColumnBetween);
// string NOT BETWEEN
// has NOT keyword
children1.set(0, new ExprNodeConstantDesc(new Boolean(true)));
ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterStringColumnNotBetween);
// CHAR tests
CharTypeInfo charTypeInfo = new CharTypeInfo(10);
col1Expr = new ExprNodeColumnDesc(charTypeInfo, "col1", "table", false);
constDesc = new ExprNodeConstantDesc(charTypeInfo, new HiveChar("Alpha", 10));
constDesc2 = new ExprNodeConstantDesc(charTypeInfo, new HiveChar("Bravo", 10));
// CHAR BETWEEN
udf = new GenericUDFBetween();
children1 = new ArrayList<ExprNodeDesc>();
// no NOT keyword
children1.add(new ExprNodeConstantDesc(new Boolean(false)));
children1.add(col1Expr);
children1.add(constDesc);
children1.add(constDesc2);
exprDesc = new ExprNodeGenericFuncDesc(TypeInfoFactory.booleanTypeInfo, udf, children1);
vc = new VectorizationContext("name", columns);
ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterCharColumnBetween);
// CHAR NOT BETWEEN
// has NOT keyword
children1.set(0, new ExprNodeConstantDesc(new Boolean(true)));
ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterCharColumnNotBetween);
// VARCHAR tests
VarcharTypeInfo varcharTypeInfo = new VarcharTypeInfo(10);
col1Expr = new ExprNodeColumnDesc(varcharTypeInfo, "col1", "table", false);
constDesc = new ExprNodeConstantDesc(varcharTypeInfo, new HiveVarchar("Alpha", 10));
constDesc2 = new ExprNodeConstantDesc(varcharTypeInfo, new HiveVarchar("Bravo", 10));
// VARCHAR BETWEEN
udf = new GenericUDFBetween();
children1 = new ArrayList<ExprNodeDesc>();
// no NOT keyword
children1.add(new ExprNodeConstantDesc(new Boolean(false)));
children1.add(col1Expr);
children1.add(constDesc);
children1.add(constDesc2);
exprDesc = new ExprNodeGenericFuncDesc(TypeInfoFactory.booleanTypeInfo, udf, children1);
vc = new VectorizationContext("name", columns);
ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterVarCharColumnBetween);
// VARCHAR NOT BETWEEN
// has NOT keyword
children1.set(0, new ExprNodeConstantDesc(new Boolean(true)));
ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterVarCharColumnNotBetween);
// long BETWEEN
children1.set(0, new ExprNodeConstantDesc(new Boolean(false)));
children1.set(1, new ExprNodeColumnDesc(Long.class, "col1", "table", false));
children1.set(2, new ExprNodeConstantDesc(10));
children1.set(3, new ExprNodeConstantDesc(20));
ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterLongColumnBetween);
// long NOT BETWEEN
children1.set(0, new ExprNodeConstantDesc(new Boolean(true)));
ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterLongColumnNotBetween);
// double BETWEEN
children1.set(0, new ExprNodeConstantDesc(new Boolean(false)));
children1.set(1, new ExprNodeColumnDesc(Double.class, "col1", "table", false));
children1.set(2, new ExprNodeConstantDesc(10.0d));
children1.set(3, new ExprNodeConstantDesc(20.0d));
ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterDoubleColumnBetween);
// double NOT BETWEEN
children1.set(0, new ExprNodeConstantDesc(new Boolean(true)));
ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterDoubleColumnNotBetween);
// timestamp BETWEEN
children1.set(0, new ExprNodeConstantDesc(new Boolean(false)));
children1.set(1, new ExprNodeColumnDesc(Timestamp.class, "col1", "table", false));
children1.set(2, new ExprNodeConstantDesc("2013-11-05 00:00:00.000"));
children1.set(3, new ExprNodeConstantDesc("2013-11-06 00:00:00.000"));
ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertEquals(FilterTimestampColumnBetween.class, ve.getClass());
// timestamp NOT BETWEEN
children1.set(0, new ExprNodeConstantDesc(new Boolean(true)));
ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertEquals(FilterTimestampColumnNotBetween.class, ve.getClass());
}
use of org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc in project hive by apache.
the class TestVectorizationContext method testFilterBooleanColumnCompareBooleanScalar.
@Test
public void testFilterBooleanColumnCompareBooleanScalar() throws HiveException {
ExprNodeGenericFuncDesc colEqualScalar = new ExprNodeGenericFuncDesc();
GenericUDFOPEqual gudf = new GenericUDFOPEqual();
colEqualScalar.setGenericUDF(gudf);
List<ExprNodeDesc> children = new ArrayList<ExprNodeDesc>(2);
ExprNodeConstantDesc constDesc = new ExprNodeConstantDesc(TypeInfoFactory.booleanTypeInfo, 20);
ExprNodeColumnDesc colDesc = new ExprNodeColumnDesc(Boolean.class, "a", "table", false);
children.add(colDesc);
children.add(constDesc);
colEqualScalar.setChildren(children);
List<String> columns = new ArrayList<String>();
columns.add("a");
VectorizationContext vc = new VectorizationContext("name", columns);
VectorExpression ve = vc.getVectorExpression(colEqualScalar, VectorExpressionDescriptor.Mode.FILTER);
assertEquals(FilterLongColEqualLongScalar.class, ve.getClass());
}
use of org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc in project hive by apache.
the class TestVectorizationContext method testStringFilterExpressions.
@Test
public void testStringFilterExpressions() throws HiveException {
ExprNodeColumnDesc col1Expr = new ExprNodeColumnDesc(String.class, "col1", "table", false);
ExprNodeConstantDesc constDesc = new ExprNodeConstantDesc("Alpha");
GenericUDFOPGreaterThan udf = new GenericUDFOPGreaterThan();
ExprNodeGenericFuncDesc exprDesc = new ExprNodeGenericFuncDesc();
exprDesc.setGenericUDF(udf);
List<ExprNodeDesc> children1 = new ArrayList<ExprNodeDesc>(2);
children1.add(col1Expr);
children1.add(constDesc);
exprDesc.setChildren(children1);
List<String> columns = new ArrayList<String>();
columns.add("col0");
columns.add("col1");
columns.add("col2");
VectorizationContext vc = new VectorizationContext("name", columns);
VectorExpression ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterStringGroupColGreaterStringScalar);
}
use of org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc in project hive by apache.
the class TestVectorizationContext method testInFiltersAndExprs.
// Test translation of both IN filters and boolean-valued IN expressions (non-filters).
@Test
public void testInFiltersAndExprs() throws HiveException {
ExprNodeColumnDesc col1Expr = new ExprNodeColumnDesc(String.class, "col1", "table", false);
ExprNodeConstantDesc constDesc = new ExprNodeConstantDesc("Alpha");
ExprNodeConstantDesc constDesc2 = new ExprNodeConstantDesc("Bravo");
// string IN
GenericUDFIn udf = new GenericUDFIn();
List<ExprNodeDesc> children1 = new ArrayList<ExprNodeDesc>();
children1.add(col1Expr);
children1.add(constDesc);
children1.add(constDesc2);
ExprNodeGenericFuncDesc exprDesc = new ExprNodeGenericFuncDesc(TypeInfoFactory.booleanTypeInfo, udf, children1);
List<String> columns = new ArrayList<String>();
columns.add("col0");
columns.add("col1");
columns.add("col2");
VectorizationContext vc = new VectorizationContext("name", columns);
VectorExpression ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterStringColumnInList);
ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.PROJECTION);
assertTrue(ve instanceof StringColumnInList);
// long IN
children1.set(0, new ExprNodeColumnDesc(Long.class, "col1", "table", false));
children1.set(1, new ExprNodeConstantDesc(10));
children1.set(2, new ExprNodeConstantDesc(20));
ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterLongColumnInList);
ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.PROJECTION);
assertTrue(ve instanceof LongColumnInList);
// double IN
children1.set(0, new ExprNodeColumnDesc(Double.class, "col1", "table", false));
children1.set(1, new ExprNodeConstantDesc(10d));
children1.set(2, new ExprNodeConstantDesc(20d));
ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertTrue(ve instanceof FilterDoubleColumnInList);
ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.PROJECTION);
assertTrue(ve instanceof DoubleColumnInList);
}
use of org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc in project phoenix by apache.
the class IndexPredicateAnalyzer method processingInOperator.
private void processingInOperator(ExprNodeGenericFuncDesc expr, List<IndexSearchCondition> searchConditions, boolean isNot, Object... nodeOutputs) {
ExprNodeColumnDesc columnDesc = null;
String[] fields = null;
if (LOG.isTraceEnabled()) {
LOG.trace("Processing In Operator. nodeOutputs : " + Lists.newArrayList(nodeOutputs));
}
if (nodeOutputs[0] instanceof ExprNodeFieldDesc) {
// rowKey field
ExprNodeFieldDesc fieldDesc = (ExprNodeFieldDesc) nodeOutputs[0];
fields = ExprNodeDescUtils.extractFields(fieldDesc);
ExprNodeDesc[] extracted = ExprNodeDescUtils.extractComparePair((ExprNodeDesc) nodeOutputs[0], (ExprNodeDesc) nodeOutputs[1]);
if (extracted == null) {
// adding for tez
return;
}
if (LOG.isTraceEnabled()) {
LOG.trace("nodeOutputs[0] : " + nodeOutputs[0] + ", nodeOutputs[1] : " + nodeOutputs[1] + " => " + Lists.newArrayList(extracted));
}
columnDesc = (ExprNodeColumnDesc) extracted[0];
} else if (nodeOutputs[0] instanceof ExprNodeGenericFuncDesc) {
columnDesc = (ExprNodeColumnDesc) ((ExprNodeGenericFuncDesc) nodeOutputs[0]).getChildren().get(0);
} else {
columnDesc = (ExprNodeColumnDesc) nodeOutputs[0];
}
String udfName = expr.getGenericUDF().getUdfName();
ExprNodeConstantDesc[] inConstantDescs = new ExprNodeConstantDesc[nodeOutputs.length - 1];
for (int i = 0, limit = inConstantDescs.length; i < limit; i++) {
if (!(nodeOutputs[i + 1] instanceof ExprNodeConstantDesc)) {
// adding for tez
return;
}
inConstantDescs[i] = (ExprNodeConstantDesc) nodeOutputs[i + 1];
}
searchConditions.add(new IndexSearchCondition(columnDesc, udfName, inConstantDescs, expr, fields, isNot));
}
Aggregations