use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF in project hive by apache.
the class TestVectorizationContext method testUnaryStringExpressions.
@Test
public void testUnaryStringExpressions() throws HiveException {
ExprNodeGenericFuncDesc stringUnary = new ExprNodeGenericFuncDesc();
stringUnary.setTypeInfo(TypeInfoFactory.stringTypeInfo);
ExprNodeColumnDesc colDesc = new ExprNodeColumnDesc(String.class, "a", "table", false);
List<ExprNodeDesc> children = new ArrayList<ExprNodeDesc>();
children.add(colDesc);
stringUnary.setChildren(children);
List<String> columns = new ArrayList<String>();
columns.add("b");
columns.add("a");
VectorizationContext vc = new VectorizationContext("name", columns);
GenericUDF stringLower = new GenericUDFLower();
stringUnary.setGenericUDF(stringLower);
VectorExpression ve = vc.getVectorExpression(stringUnary);
assertEquals(StringLower.class, ve.getClass());
assertEquals(1, ((StringLower) ve).getColNum());
assertEquals(2, ((StringLower) ve).getOutputColumn());
vc = new VectorizationContext("name", columns);
ExprNodeGenericFuncDesc anotherUnary = new ExprNodeGenericFuncDesc();
anotherUnary.setTypeInfo(TypeInfoFactory.stringTypeInfo);
List<ExprNodeDesc> children2 = new ArrayList<ExprNodeDesc>();
children2.add(stringUnary);
anotherUnary.setChildren(children2);
GenericUDFBridge udfbridge = new GenericUDFBridge("ltrim", false, GenericUDFLTrim.class.getName());
anotherUnary.setGenericUDF(udfbridge);
ve = vc.getVectorExpression(anotherUnary);
VectorExpression childVe = ve.getChildExpressions()[0];
assertEquals(StringLower.class, childVe.getClass());
assertEquals(1, ((StringLower) childVe).getColNum());
assertEquals(2, ((StringLower) childVe).getOutputColumn());
assertEquals(StringLTrim.class, ve.getClass());
assertEquals(2, ((StringLTrim) ve).getInputColumn());
assertEquals(3, ((StringLTrim) ve).getOutputColumn());
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF in project hive by apache.
the class TestVectorSelectOperator method testSelectOperator.
@Test
public void testSelectOperator() throws HiveException {
List<String> columns = new ArrayList<String>();
columns.add("a");
columns.add("b");
columns.add("c");
VectorizationContext vc = new VectorizationContext("name", columns);
SelectDesc selDesc = new SelectDesc(false);
List<ExprNodeDesc> colList = new ArrayList<ExprNodeDesc>();
ExprNodeColumnDesc colDesc1 = new ExprNodeColumnDesc(Long.class, "a", "table", false);
ExprNodeColumnDesc colDesc2 = new ExprNodeColumnDesc(Long.class, "b", "table", false);
ExprNodeColumnDesc colDesc3 = new ExprNodeColumnDesc(Long.class, "c", "table", false);
ExprNodeGenericFuncDesc plusDesc = new ExprNodeGenericFuncDesc();
GenericUDF gudf = new GenericUDFOPPlus();
plusDesc.setGenericUDF(gudf);
List<ExprNodeDesc> children = new ArrayList<ExprNodeDesc>();
children.add(colDesc1);
children.add(colDesc2);
plusDesc.setChildren(children);
plusDesc.setTypeInfo(TypeInfoFactory.longTypeInfo);
colList.add(plusDesc);
colList.add(colDesc3);
selDesc.setColList(colList);
List<String> outputColNames = new ArrayList<String>();
outputColNames.add("_col0");
outputColNames.add("_col1");
selDesc.setOutputColumnNames(outputColNames);
// CONSIDER unwinding ValidatorVectorSelectOperator as a subclass of VectorSelectOperator.
VectorSelectDesc vectorSelectDesc = new VectorSelectDesc();
selDesc.setVectorDesc(vectorSelectDesc);
List<ExprNodeDesc> selectColList = selDesc.getColList();
VectorExpression[] vectorSelectExprs = new VectorExpression[selectColList.size()];
for (int i = 0; i < selectColList.size(); i++) {
ExprNodeDesc expr = selectColList.get(i);
VectorExpression ve = vc.getVectorExpression(expr);
vectorSelectExprs[i] = ve;
}
vectorSelectDesc.setSelectExpressions(vectorSelectExprs);
vectorSelectDesc.setProjectedOutputColumns(new int[] { 3, 2 });
ValidatorVectorSelectOperator vso = new ValidatorVectorSelectOperator(new CompilationOpContext(), vc, selDesc);
VectorizedRowBatch vrg = VectorizedRowGroupGenUtil.getVectorizedRowBatch(VectorizedRowBatch.DEFAULT_SIZE, 4, 17);
vso.process(vrg, 0);
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF in project hive by apache.
the class TestFunctionRegistry method testIsPermanentFunction.
public void testIsPermanentFunction() throws Exception {
// Setup exprNode
GenericUDF udf = new GenericUDFCurrentTimestamp();
List<ExprNodeDesc> children = new ArrayList<ExprNodeDesc>();
ExprNodeGenericFuncDesc fnExpr = new ExprNodeGenericFuncDesc(TypeInfoFactory.timestampTypeInfo, udf, children);
assertFalse("Function not added as permanent yet", FunctionRegistry.isPermanentFunction(fnExpr));
// Now register as permanent function
FunctionResource[] emptyResources = new FunctionResource[] {};
FunctionRegistry.registerPermanentFunction("default.perm_current_timestamp", GenericUDFCurrentTimestamp.class.getName(), true, emptyResources);
assertTrue("Function should now be recognized as permanent function", FunctionRegistry.isPermanentFunction(fnExpr));
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF in project hive by apache.
the class TestColumnPrunerProcCtx method testGetSelectNestedColPathsFromChildren7.
// Test select pow(root.col1.b, root.col2) from table test(root
// struct<col1:struct<a:boolean,b:double>, col2:double>);
@Test
public void testGetSelectNestedColPathsFromChildren7() {
ColumnPrunerProcCtx ctx = new ColumnPrunerProcCtx(null);
ExprNodeDesc colDesc = new ExprNodeColumnDesc(col3Type, "root", "test", false);
ExprNodeDesc col1 = new ExprNodeFieldDesc(col1Type, colDesc, "col1", false);
ExprNodeDesc fieldDesc1 = new ExprNodeFieldDesc(TypeInfoFactory.doubleTypeInfo, col1, "b", false);
colDesc = new ExprNodeColumnDesc(col3Type, "root", "test", false);
ExprNodeDesc col2 = new ExprNodeFieldDesc(col2Type, colDesc, "col2", false);
final List<FieldNode> paths = Arrays.asList(new FieldNode("_col0"));
GenericUDF udf = mock(GenericUDFPower.class);
List<ExprNodeDesc> list = new ArrayList<>();
list.add(fieldDesc1);
list.add(col2);
ExprNodeDesc funcDesc = new ExprNodeGenericFuncDesc(TypeInfoFactory.doubleTypeInfo, udf, "pow", list);
SelectOperator selectOperator = buildSelectOperator(Arrays.asList(funcDesc), paths);
List<FieldNode> groups = ctx.getSelectColsFromChildren(selectOperator, paths);
compareTestResults(groups, "root.col1.b", "root.col2");
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF in project hive by apache.
the class VectorUDFAdaptor method init.
// Initialize transient fields. To be called after deserialization of other fields.
public void init() throws HiveException, UDFArgumentException {
genericUDF = expr.getGenericUDF();
deferredChildren = new GenericUDF.DeferredObject[expr.getChildren().size()];
childrenOIs = new ObjectInspector[expr.getChildren().size()];
writers = VectorExpressionWriterFactory.getExpressionWriters(expr.getChildren());
for (int i = 0; i < childrenOIs.length; i++) {
childrenOIs[i] = writers[i].getObjectInspector();
}
MapredContext context = MapredContext.get();
if (context != null) {
context.setup(genericUDF);
}
outputOI = VectorExpressionWriterFactory.genVectorExpressionWritable(expr).getObjectInspector();
genericUDF.initialize(childrenOIs);
// Initialize constant arguments
for (int i = 0; i < argDescs.length; i++) {
if (argDescs[i].isConstant()) {
argDescs[i].prepareConstant();
}
}
}
Aggregations