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

The following examples show how to use org.apache.hadoop.hive.ql.udf.UDFType. These examples are extracted from open source projects. 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 Project: dremio-oss   Source File: HiveFunctionRegistry.java    License: 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 Project: tajo   Source File: HiveFunctionLoader.java    License: 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);
      }
    }
  }
}