コード例 #1
0
  /**
   * Get the GenericUDAF evaluator for the name and argumentClasses.
   *
   * @param name the name of the UDAF
   * @param argumentOIs
   * @param isDistinct
   * @param isAllColumns
   * @return The UDAF evaluator
   */
  @SuppressWarnings("deprecation")
  public GenericUDAFEvaluator getGenericUDAFEvaluator(
      String name, List<ObjectInspector> argumentOIs, boolean isDistinct, boolean isAllColumns)
      throws SemanticException {

    GenericUDAFResolver udafResolver = getGenericUDAFResolver(name);
    if (udafResolver == null) {
      return null;
    }

    GenericUDAFEvaluator udafEvaluator;
    ObjectInspector args[] = new ObjectInspector[argumentOIs.size()];
    // Can't use toArray here because Java is dumb when it comes to
    // generics + arrays.
    for (int ii = 0; ii < argumentOIs.size(); ++ii) {
      args[ii] = argumentOIs.get(ii);
    }

    GenericUDAFParameterInfo paramInfo =
        new SimpleGenericUDAFParameterInfo(args, isDistinct, isAllColumns);
    if (udafResolver instanceof GenericUDAFResolver2) {
      udafEvaluator = ((GenericUDAFResolver2) udafResolver).getEvaluator(paramInfo);
    } else {
      udafEvaluator = udafResolver.getEvaluator(paramInfo.getParameters());
    }
    return udafEvaluator;
  }
コード例 #2
0
 @Override
 public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info)
     throws SemanticException {
   final ObjectInspector[] inspectors = info.getParameterObjectInspectors();
   if (inspectors.length != 1) {
     throw new UDFArgumentException("One argument expected");
   }
   if (inspectors[0].getCategory() != ObjectInspector.Category.PRIMITIVE) {
     throw new UDFArgumentTypeException(
         0, "Primitive argument expected, but " + inspectors[0].getTypeName() + " was recieved");
   }
   final PrimitiveObjectInspector inspector = (PrimitiveObjectInspector) inspectors[0];
   if (inspector.getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.BINARY) {
     throw new UDFArgumentTypeException(
         0,
         "Binary argument expected, but "
             + inspector.getPrimitiveCategory().name()
             + " was received");
   }
   return createEvaluator();
 }