use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge in project drill by apache.
the class HiveFunctionRegistry method matchAndCreateUDFHolder.
private HiveFuncHolder matchAndCreateUDFHolder(String udfName, Class<? extends UDF> udfClazz, MajorType[] argTypes, ObjectInspector[] argOIs) {
try {
GenericUDF udfInstance = new GenericUDFBridge(udfName, false, /* is operator */
udfClazz.getName());
ObjectInspector returnOI = udfInstance.initialize(argOIs);
return new HiveFuncHolder(udfName, udfClazz, argTypes, returnOI, Types.optional(ObjectInspectorHelper.getDrillType(returnOI)), nonDeterministicUDFs.contains(udfClazz));
} catch (Exception e) {
/*ignore this*/
}
return null;
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge in project hive by apache.
the class ConstantPropagateProcFactory method isConstantFoldableUdf.
/**
* Can the UDF be used for constant folding.
*/
private static boolean isConstantFoldableUdf(GenericUDF udf, List<ExprNodeDesc> children) {
// Runtime constants + deterministic functions can be folded.
if (!FunctionRegistry.isConsistentWithinQuery(udf)) {
if (udf.getClass().equals(GenericUDFUnixTimeStamp.class) && children != null && children.size() > 0) {
// unix_timestamp is polymorphic (ignore class annotations)
return true;
}
return false;
}
// If udf is requiring additional jars, we can't determine the result in
// compile time.
String[] files;
String[] jars;
if (udf instanceof GenericUDFBridge) {
GenericUDFBridge bridge = (GenericUDFBridge) udf;
String udfClassName = bridge.getUdfClassName();
try {
UDF udfInternal = (UDF) Class.forName(bridge.getUdfClassName(), true, Utilities.getSessionSpecifiedClassLoader()).newInstance();
files = udfInternal.getRequiredFiles();
jars = udfInternal.getRequiredJars();
} catch (Exception e) {
LOG.error("The UDF implementation class '" + udfClassName + "' is not present in the class path");
return false;
}
} else {
files = udf.getRequiredFiles();
jars = udf.getRequiredJars();
}
if (files != null || jars != null) {
return false;
}
return true;
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge in project hive by apache.
the class IndexPredicateAnalyzer method getColumnExpr.
// Check if ExprNodeColumnDesc is wrapped in expr.
// If so, peel off. Otherwise return itself.
private ExprNodeDesc getColumnExpr(ExprNodeDesc expr) {
if (expr instanceof ExprNodeColumnDesc) {
return expr;
}
ExprNodeGenericFuncDesc funcDesc = null;
if (expr instanceof ExprNodeGenericFuncDesc) {
funcDesc = (ExprNodeGenericFuncDesc) expr;
}
if (null == funcDesc) {
return expr;
}
GenericUDF udf = funcDesc.getGenericUDF();
// check if its a simple cast expression.
if ((udf instanceof GenericUDFBridge || udf instanceof GenericUDFToBinary || udf instanceof GenericUDFToChar || udf instanceof GenericUDFToVarchar || udf instanceof GenericUDFToDecimal || udf instanceof GenericUDFToDate || udf instanceof GenericUDFToUnixTimeStamp || udf instanceof GenericUDFToUtcTimestamp) && funcDesc.getChildren().size() == 1 && funcDesc.getChildren().get(0) instanceof ExprNodeColumnDesc) {
return expr.getChildren().get(0);
}
return expr;
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge in project hive by apache.
the class TestVectorizationContext method testTimeStampUdfs.
@Test
public void testTimeStampUdfs() throws HiveException {
ExprNodeGenericFuncDesc tsFuncExpr = new ExprNodeGenericFuncDesc();
tsFuncExpr.setTypeInfo(TypeInfoFactory.intTypeInfo);
ExprNodeColumnDesc colDesc1 = new ExprNodeColumnDesc(TypeInfoFactory.timestampTypeInfo, "a", "table", false);
List<ExprNodeDesc> children = new ArrayList<ExprNodeDesc>();
children.add(colDesc1);
List<String> columns = new ArrayList<String>();
columns.add("b");
columns.add("a");
VectorizationContext vc = new VectorizationContext("name", columns);
// UDFYear
GenericUDFBridge gudfBridge = new GenericUDFBridge("year", false, UDFYear.class.getName());
tsFuncExpr.setGenericUDF(gudfBridge);
tsFuncExpr.setChildren(children);
VectorExpression ve = vc.getVectorExpression(tsFuncExpr);
Assert.assertEquals(VectorUDFYearTimestamp.class, ve.getClass());
// GenericUDFToUnixTimeStamp
GenericUDFToUnixTimeStamp gudf = new GenericUDFToUnixTimeStamp();
tsFuncExpr.setGenericUDF(gudf);
tsFuncExpr.setTypeInfo(TypeInfoFactory.longTypeInfo);
ve = vc.getVectorExpression(tsFuncExpr);
Assert.assertEquals(VectorUDFUnixTimeStampTimestamp.class, ve.getClass());
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge 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(2, ((StringLower) ve).getOutputColumnNum());
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(2, ((StringLower) childVe).getOutputColumnNum());
assertEquals(StringLTrim.class, ve.getClass());
assertEquals(3, ((StringLTrim) ve).getOutputColumnNum());
}
Aggregations