org.apache.hadoop.hive.ql.udf.UDFType Java Examples

The following examples show how to use org.apache.hadoop.hive.ql.udf.UDFType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HiveFunctionRegistry.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
private <C,I> void register(Class<? extends I> clazz, ArrayListMultimap<String,Class<? extends I>> methods) {
  Description desc = clazz.getAnnotation(Description.class);
  String[] names;
  if (desc != null) {
    names = desc.name().split(",");
    for (int i=0; i<names.length; i++) {
      names[i] = names[i].trim();
    }
  }else{
    names = new String[]{clazz.getName().replace('.', '_')};
  }

  UDFType type = clazz.getAnnotation(UDFType.class);
  if (type != null && !type.deterministic()) {
    nonDeterministicUDFs.add(clazz);
  }


  for(int i=0; i<names.length;i++) {
    methods.put(names[i].toLowerCase(), clazz);
  }
}
 
Example #2
Source File: HiveFunctionLoader.java    From tajo with Apache License 2.0 4 votes vote down vote up
static void buildFunctionsFromUDF(Set<Class<? extends UDF>> classes, List<FunctionDesc> list, String jarurl) {
  for (Class<? extends UDF> clazz: classes) {
    String [] names;
    String value = null, extended = null;

    Description desc = clazz.getAnnotation(Description.class);

    // Check @Description annotation (if exists)
    if (desc != null) {
      names = desc.name().split(",");
      for (int i=0; i<names.length; i++) {
        names[i] = names[i].trim();
      }

      value = desc.value();
      extended = desc.extended();
    }
    else {
      names = new String [] {clazz.getName().replace('.','_')};
    }

    // actual function descriptor building
    FunctionDescBuilder builder = new FunctionDescBuilder();

    UDFType type = clazz.getDeclaredAnnotation(UDFType.class);
    if (type != null) {
      builder.setDeterministic(type.deterministic());
    }

    builder.setFunctionType(CatalogProtos.FunctionType.UDF);

    if (value != null) {
      builder.setDescription(value);
    }

    if (extended != null) {
      builder.setExample(extended);
    }

    UDFInvocationDesc udfInvocation = new UDFInvocationDesc(CatalogProtos.UDFtype.HIVE, clazz.getName(), jarurl, true);

    // verify 'evaluate' method and extract return type and parameter types
    for (Method method: clazz.getMethods()) {
      if (method.getName().equals("evaluate")) {
        registerMethod(method, names, udfInvocation, builder, list);
      }
    }
  }
}