use of org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc in project hive by apache.
the class TestVectorizationContext method testFloatInExpressions.
@Test
public void testFloatInExpressions() throws HiveException {
ExprNodeColumnDesc col1Expr = new ExprNodeColumnDesc(Float.class, "col1", "table", false);
ExprNodeConstantDesc constDesc = new ExprNodeConstantDesc(new Integer(10));
GenericUDFOPPlus udf = new GenericUDFOPPlus();
List<ExprNodeDesc> children1 = new ArrayList<ExprNodeDesc>(2);
children1.add(col1Expr);
children1.add(constDesc);
ExprNodeGenericFuncDesc exprDesc = new ExprNodeGenericFuncDesc(TypeInfoFactory.doubleTypeInfo, udf, children1);
List<String> columns = new ArrayList<String>();
columns.add("col1");
VectorizationContext vc = new VectorizationContext("name", columns);
VectorExpression ve = vc.getVectorExpression(exprDesc, VectorExpressionDescriptor.Mode.PROJECTION);
assertTrue(ve.getOutputTypeInfo().equals(TypeInfoFactory.doubleTypeInfo));
}
use of org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc in project hive by apache.
the class TestVectorizationContext method testMathFunctions.
@Test
public void testMathFunctions() throws HiveException {
ExprNodeGenericFuncDesc mathFuncExpr = new ExprNodeGenericFuncDesc();
mathFuncExpr.setTypeInfo(TypeInfoFactory.doubleTypeInfo);
ExprNodeColumnDesc colDesc1 = new ExprNodeColumnDesc(Integer.class, "a", "table", false);
ExprNodeColumnDesc colDesc2 = new ExprNodeColumnDesc(Double.class, "b", "table", false);
List<ExprNodeDesc> children1 = new ArrayList<ExprNodeDesc>();
List<ExprNodeDesc> children2 = new ArrayList<ExprNodeDesc>();
children1.add(colDesc1);
children2.add(colDesc2);
List<String> columns = new ArrayList<String>();
columns.add("b");
columns.add("a");
VectorizationContext vc = new VectorizationContext("name", columns);
// Sin(double)
GenericUDFBridge gudfBridge = new GenericUDFBridge("sin", false, UDFSin.class.getName());
mathFuncExpr.setGenericUDF(gudfBridge);
mathFuncExpr.setChildren(children2);
VectorExpression ve = vc.getVectorExpression(mathFuncExpr, VectorExpressionDescriptor.Mode.PROJECTION);
Assert.assertEquals(FuncSinDoubleToDouble.class, ve.getClass());
// Round without digits
GenericUDFRound udfRound = new GenericUDFRound();
mathFuncExpr.setGenericUDF(udfRound);
mathFuncExpr.setChildren(children2);
ve = vc.getVectorExpression(mathFuncExpr);
Assert.assertEquals(FuncRoundDoubleToDouble.class, ve.getClass());
// BRound without digits
GenericUDFBRound udfBRound = new GenericUDFBRound();
mathFuncExpr.setGenericUDF(udfBRound);
ve = vc.getVectorExpression(mathFuncExpr);
Assert.assertEquals(FuncBRoundDoubleToDouble.class, ve.getClass());
// Round with digits
mathFuncExpr.setGenericUDF(udfRound);
children2.add(new ExprNodeConstantDesc(4));
mathFuncExpr.setChildren(children2);
ve = vc.getVectorExpression(mathFuncExpr);
Assert.assertEquals(RoundWithNumDigitsDoubleToDouble.class, ve.getClass());
Assert.assertEquals(4, ((RoundWithNumDigitsDoubleToDouble) ve).getDecimalPlaces().get());
// BRound with digits
mathFuncExpr.setGenericUDF(udfBRound);
ve = vc.getVectorExpression(mathFuncExpr);
Assert.assertEquals(BRoundWithNumDigitsDoubleToDouble.class, ve.getClass());
Assert.assertEquals(4, ((BRoundWithNumDigitsDoubleToDouble) ve).getDecimalPlaces().get());
// Logger with int base
gudfBridge = new GenericUDFBridge("log", false, UDFLog.class.getName());
mathFuncExpr.setGenericUDF(gudfBridge);
children2.clear();
children2.add(new ExprNodeConstantDesc(4.0));
children2.add(colDesc2);
mathFuncExpr.setChildren(children2);
ve = vc.getVectorExpression(mathFuncExpr);
Assert.assertEquals(FuncLogWithBaseDoubleToDouble.class, ve.getClass());
Assert.assertTrue(4 == ((FuncLogWithBaseDoubleToDouble) ve).getBase());
// Logger with default base
children2.clear();
children2.add(colDesc2);
mathFuncExpr.setChildren(children2);
ve = vc.getVectorExpression(mathFuncExpr);
Assert.assertEquals(FuncLnDoubleToDouble.class, ve.getClass());
// Log with double base
children2.clear();
children2.add(new ExprNodeConstantDesc(4.5));
children2.add(colDesc2);
mathFuncExpr.setChildren(children2);
ve = vc.getVectorExpression(mathFuncExpr);
Assert.assertEquals(FuncLogWithBaseDoubleToDouble.class, ve.getClass());
Assert.assertTrue(4.5 == ((FuncLogWithBaseDoubleToDouble) ve).getBase());
// Log with int input and double base
children2.clear();
children2.add(new ExprNodeConstantDesc(4.5));
children2.add(colDesc1);
mathFuncExpr.setChildren(children2);
ve = vc.getVectorExpression(mathFuncExpr);
Assert.assertEquals(FuncLogWithBaseLongToDouble.class, ve.getClass());
Assert.assertTrue(4.5 == ((FuncLogWithBaseLongToDouble) ve).getBase());
// Power with double power
children2.clear();
children2.add(colDesc2);
children2.add(new ExprNodeConstantDesc(4.5));
mathFuncExpr.setGenericUDF(new GenericUDFPower());
mathFuncExpr.setChildren(children2);
ve = vc.getVectorExpression(mathFuncExpr);
Assert.assertEquals(FuncPowerDoubleToDouble.class, ve.getClass());
Assert.assertTrue(4.5 == ((FuncPowerDoubleToDouble) ve).getPower());
// Round with default decimal places
mathFuncExpr.setGenericUDF(udfRound);
children2.clear();
children2.add(colDesc2);
mathFuncExpr.setChildren(children2);
ve = vc.getVectorExpression(mathFuncExpr);
Assert.assertEquals(FuncRoundDoubleToDouble.class, ve.getClass());
}
use of org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc in project hive by apache.
the class TestVectorizationContext method testVectorizeAndOrProjectionExpression.
@Test
public void testVectorizeAndOrProjectionExpression() throws HiveException {
ExprNodeColumnDesc col1Expr = new ExprNodeColumnDesc(Integer.class, "col1", "table", false);
ExprNodeConstantDesc constDesc = new ExprNodeConstantDesc(new Integer(10));
GenericUDFOPGreaterThan udf = new GenericUDFOPGreaterThan();
ExprNodeGenericFuncDesc greaterExprDesc = new ExprNodeGenericFuncDesc();
greaterExprDesc.setTypeInfo(TypeInfoFactory.booleanTypeInfo);
greaterExprDesc.setGenericUDF(udf);
List<ExprNodeDesc> children1 = new ArrayList<ExprNodeDesc>(2);
children1.add(col1Expr);
children1.add(constDesc);
greaterExprDesc.setChildren(children1);
ExprNodeColumnDesc col2Expr = new ExprNodeColumnDesc(Boolean.class, "col2", "table", false);
GenericUDFOPAnd andUdf = new GenericUDFOPAnd();
ExprNodeGenericFuncDesc andExprDesc = new ExprNodeGenericFuncDesc();
andExprDesc.setTypeInfo(TypeInfoFactory.booleanTypeInfo);
andExprDesc.setGenericUDF(andUdf);
List<ExprNodeDesc> children3 = new ArrayList<ExprNodeDesc>(2);
children3.add(greaterExprDesc);
children3.add(col2Expr);
andExprDesc.setChildren(children3);
List<String> columns = new ArrayList<String>();
columns.add("col1");
columns.add("col2");
VectorizationContext vc = new VectorizationContext("name", columns);
VectorExpression veAnd = vc.getVectorExpression(andExprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertEquals(veAnd.getClass(), FilterExprAndExpr.class);
assertEquals(veAnd.getChildExpressions()[0].getClass(), FilterLongColGreaterLongScalar.class);
assertEquals(veAnd.getChildExpressions()[1].getClass(), SelectColumnIsTrue.class);
veAnd = vc.getVectorExpression(andExprDesc, VectorExpressionDescriptor.Mode.PROJECTION);
assertEquals(veAnd.getClass(), ColAndCol.class);
assertEquals(1, veAnd.getChildExpressions().length);
assertEquals(veAnd.getChildExpressions()[0].getClass(), LongColGreaterLongScalar.class);
assertEquals(3, ((ColAndCol) veAnd).getOutputColumnNum());
// OR
GenericUDFOPOr orUdf = new GenericUDFOPOr();
ExprNodeGenericFuncDesc orExprDesc = new ExprNodeGenericFuncDesc();
orExprDesc.setTypeInfo(TypeInfoFactory.booleanTypeInfo);
orExprDesc.setGenericUDF(orUdf);
List<ExprNodeDesc> children4 = new ArrayList<ExprNodeDesc>(2);
children4.add(greaterExprDesc);
children4.add(col2Expr);
orExprDesc.setChildren(children4);
// Allocate new Vectorization context to reset the intermediate columns.
vc = new VectorizationContext("name", columns);
VectorExpression veOr = vc.getVectorExpression(orExprDesc, VectorExpressionDescriptor.Mode.FILTER);
assertEquals(veOr.getClass(), FilterExprOrExpr.class);
assertEquals(veOr.getChildExpressions()[0].getClass(), FilterLongColGreaterLongScalar.class);
assertEquals(veOr.getChildExpressions()[1].getClass(), SelectColumnIsTrue.class);
veOr = vc.getVectorExpression(orExprDesc, VectorExpressionDescriptor.Mode.PROJECTION);
assertEquals(veOr.getClass(), ColOrCol.class);
assertEquals(1, veAnd.getChildExpressions().length);
assertEquals(veAnd.getChildExpressions()[0].getClass(), LongColGreaterLongScalar.class);
assertEquals(3, ((ColOrCol) veOr).getOutputColumnNum());
}
use of org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc in project hive by apache.
the class TestVectorizationContext method testArithmeticExpressionVectorization.
@Test
public void testArithmeticExpressionVectorization() throws HiveException {
/**
* Create original expression tree for following
* (plus (minus (plus col1 col2) col3) (multiply col4 (mod col5 col6)) )
*/
GenericUDFOPPlus udf1 = new GenericUDFOPPlus();
GenericUDFOPMinus udf2 = new GenericUDFOPMinus();
GenericUDFOPMultiply udf3 = new GenericUDFOPMultiply();
GenericUDFOPPlus udf4 = new GenericUDFOPPlus();
GenericUDFOPMod udf5 = new GenericUDFOPMod();
ExprNodeGenericFuncDesc sumExpr = new ExprNodeGenericFuncDesc();
sumExpr.setTypeInfo(TypeInfoFactory.intTypeInfo);
sumExpr.setGenericUDF(udf1);
ExprNodeGenericFuncDesc minusExpr = new ExprNodeGenericFuncDesc();
minusExpr.setTypeInfo(TypeInfoFactory.intTypeInfo);
minusExpr.setGenericUDF(udf2);
ExprNodeGenericFuncDesc multiplyExpr = new ExprNodeGenericFuncDesc();
multiplyExpr.setTypeInfo(TypeInfoFactory.intTypeInfo);
multiplyExpr.setGenericUDF(udf3);
ExprNodeGenericFuncDesc sum2Expr = new ExprNodeGenericFuncDesc();
sum2Expr.setTypeInfo(TypeInfoFactory.intTypeInfo);
sum2Expr.setGenericUDF(udf4);
ExprNodeGenericFuncDesc modExpr = new ExprNodeGenericFuncDesc();
modExpr.setTypeInfo(TypeInfoFactory.intTypeInfo);
modExpr.setGenericUDF(udf5);
ExprNodeColumnDesc col1Expr = new ExprNodeColumnDesc(Long.class, "col1", "table", false);
ExprNodeColumnDesc col2Expr = new ExprNodeColumnDesc(Long.class, "col2", "table", false);
ExprNodeColumnDesc col3Expr = new ExprNodeColumnDesc(Long.class, "col3", "table", false);
ExprNodeColumnDesc col4Expr = new ExprNodeColumnDesc(Long.class, "col4", "table", false);
ExprNodeColumnDesc col5Expr = new ExprNodeColumnDesc(Long.class, "col5", "table", false);
ExprNodeColumnDesc col6Expr = new ExprNodeColumnDesc(Long.class, "col6", "table", false);
List<ExprNodeDesc> children1 = new ArrayList<ExprNodeDesc>(2);
List<ExprNodeDesc> children2 = new ArrayList<ExprNodeDesc>(2);
List<ExprNodeDesc> children3 = new ArrayList<ExprNodeDesc>(2);
List<ExprNodeDesc> children4 = new ArrayList<ExprNodeDesc>(2);
List<ExprNodeDesc> children5 = new ArrayList<ExprNodeDesc>(2);
children1.add(minusExpr);
children1.add(multiplyExpr);
sumExpr.setChildren(children1);
children2.add(sum2Expr);
children2.add(col3Expr);
minusExpr.setChildren(children2);
children3.add(col1Expr);
children3.add(col2Expr);
sum2Expr.setChildren(children3);
children4.add(col4Expr);
children4.add(modExpr);
multiplyExpr.setChildren(children4);
children5.add(col5Expr);
children5.add(col6Expr);
modExpr.setChildren(children5);
VectorizationContext vc = new VectorizationContext("name");
vc.addInitialColumn("col1");
vc.addInitialColumn("col2");
vc.addInitialColumn("col3");
vc.addInitialColumn("col4");
vc.addInitialColumn("col5");
vc.addInitialColumn("col6");
vc.finishedAddingInitialColumns();
// Generate vectorized expression
VectorExpression ve = vc.getVectorExpression(sumExpr, VectorExpressionDescriptor.Mode.PROJECTION);
// Verify vectorized expression
assertTrue(ve instanceof LongColAddLongColumn);
assertEquals(2, ve.getChildExpressions().length);
VectorExpression childExpr1 = ve.getChildExpressions()[0];
VectorExpression childExpr2 = ve.getChildExpressions()[1];
System.out.println(ve.toString());
assertEquals(6, ve.getOutputColumnNum());
assertTrue(childExpr1 instanceof LongColSubtractLongColumn);
assertEquals(1, childExpr1.getChildExpressions().length);
assertTrue(childExpr1.getChildExpressions()[0] instanceof LongColAddLongColumn);
assertEquals(7, childExpr1.getOutputColumnNum());
assertEquals(6, childExpr1.getChildExpressions()[0].getOutputColumnNum());
assertTrue(childExpr2 instanceof LongColMultiplyLongColumn);
assertEquals(1, childExpr2.getChildExpressions().length);
assertTrue(childExpr2.getChildExpressions()[0] instanceof LongColModuloLongColumn);
assertEquals(8, childExpr2.getOutputColumnNum());
assertEquals(6, childExpr2.getChildExpressions()[0].getOutputColumnNum());
}
use of org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc in project hive by apache.
the class TestVectorizationContext method testBooleanColumnCompareBooleanScalar.
@Test
public void testBooleanColumnCompareBooleanScalar() 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);
colEqualScalar.setTypeInfo(TypeInfoFactory.booleanTypeInfo);
List<String> columns = new ArrayList<String>();
columns.add("a");
VectorizationContext vc = new VectorizationContext("name", columns);
VectorExpression ve = vc.getVectorExpression(colEqualScalar, VectorExpressionDescriptor.Mode.PROJECTION);
assertEquals(LongColEqualLongScalar.class, ve.getClass());
}
Aggregations