use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge in project hive by apache.
the class TestUDFUUID method testUUID.
@Test
public void testUUID() throws Exception {
UDFUUID udf = new UDFUUID();
String id1 = udf.evaluate().toString();
String id2 = udf.evaluate().toString();
assertFalse(id1.equals(id2));
assertEquals(id1.length(), 36);
assertEquals(id2.length(), 36);
GenericUDFBridge bridge = new GenericUDFBridge("uuid", false, UDFUUID.class.getName());
assertFalse(FunctionRegistry.isDeterministic(bridge));
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge in project hive by apache.
the class DruidStorageHandlerUtils method extractColName.
@Nullable
public static String extractColName(ExprNodeDesc expr, List<VirtualColumn> virtualColumns) {
if (!druidSupportedTypeInfos.contains(expr.getTypeInfo())) {
// We cannot pass the bloom filter to druid since bloom filter tests for exact object bytes.
return null;
}
if (expr instanceof ExprNodeColumnDesc) {
return ((ExprNodeColumnDesc) expr).getColumn();
}
ExprNodeGenericFuncDesc funcDesc = null;
if (expr instanceof ExprNodeGenericFuncDesc) {
funcDesc = (ExprNodeGenericFuncDesc) expr;
}
if (null == funcDesc) {
return null;
}
GenericUDF udf = funcDesc.getGenericUDF();
// bail out if its not a simple cast expression.
if (funcDesc.getChildren().size() == 1 && funcDesc.getChildren().get(0) instanceof ExprNodeColumnDesc) {
return null;
}
String columnName = ((ExprNodeColumnDesc) (funcDesc.getChildren().get(0))).getColumn();
ValueType targetType = null;
if (udf instanceof GenericUDFBridge) {
Class<? extends UDF> udfClass = ((GenericUDFBridge) udf).getUdfClass();
if (udfClass.equals(UDFToDouble.class)) {
targetType = ValueType.DOUBLE;
} else if (udfClass.equals(UDFToFloat.class)) {
targetType = ValueType.FLOAT;
} else if (udfClass.equals(UDFToLong.class)) {
targetType = ValueType.LONG;
}
} else if (udf instanceof GenericUDFToString) {
targetType = ValueType.STRING;
}
if (targetType == null) {
return null;
}
String virtualColumnExpr = DruidQuery.format("CAST(%s, '%s')", columnName, targetType.toString());
for (VirtualColumn column : virtualColumns) {
if (column instanceof ExpressionVirtualColumn && ((ExpressionVirtualColumn) column).getExpression().equals(virtualColumnExpr)) {
// Found an existing virtual column with same expression, no need to add another virtual column
return column.getOutputName();
}
}
Set<String> usedColumnNames = virtualColumns.stream().map(col -> col.getOutputName()).collect(Collectors.toSet());
final String name = SqlValidatorUtil.uniquify("vc", usedColumnNames, SqlValidatorUtil.EXPR_SUGGESTER);
ExpressionVirtualColumn expressionVirtualColumn = new ExpressionVirtualColumn(name, virtualColumnExpr, targetType, ExprMacroTable.nil());
virtualColumns.add(expressionVirtualColumn);
return name;
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge in project hive by apache.
the class ConstantPropagateProcFactory method isDeterministicUdf.
private static boolean isDeterministicUdf(GenericUDF udf, List<ExprNodeDesc> children) {
UDFType udfType = udf.getClass().getAnnotation(UDFType.class);
if (udf instanceof GenericUDFBridge) {
udfType = ((GenericUDFBridge) udf).getUdfClass().getAnnotation(UDFType.class);
}
if (udfType.deterministic() == false) {
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 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;
}
Aggregations