コード例 #1
0
  /**
   * Takes the actual arguments and returns the result. Gets passed the input, does whatever it
   * wants to it, and then returns the output.
   *
   * <p>The input is accessed using the ObjectInspectors that were saved into global variables in
   * the call to initialize()
   *
   * <p>This method is called once for every row of data being processed. UDFs are called during the
   * map phase of the MapReduce job. This means that we have no control over the order in which the
   * records get sent to the UDF.
   *
   * @param arguments
   * @return
   * @throws HiveException
   */
  @Override
  public Object evaluate(DeferredObject[] arguments) throws HiveException {
    assert arguments != null
        : "Method 'evaluate' of HostNormalizerUDF " + "called with null arguments array";
    assert arguments.length == 1
        : "Method 'evaluate' of "
            + "HostNormalizerUDF called arguments of length "
            + arguments.length
            + " (instead of 1)";
    // arguments is an array with exactly 1 entry.

    assert result != null : "Result object has not yet been initialized, " + "but evaluate called";
    // result object has been initialized. So it's an array of objects of
    // the right length.

    String uriHost = argumentOI.getPrimitiveJavaObject(arguments[0].get());

    NormalizedHostInfo normHost = webrequest.normalizeHost(uriHost);

    if (normHost == null) {
      result[IDX_PROJECT_CLASS] = NormalizedHostInfo.EMPTY_NORM_HOST_VALUE;
      result[IDX_PROJECT] = NormalizedHostInfo.EMPTY_NORM_HOST_VALUE;
      result[IDX_QUALIFIERS] = new ArrayList<String>();
      result[IDX_TLD] = NormalizedHostInfo.EMPTY_NORM_HOST_VALUE;
    } else {
      result[IDX_PROJECT_CLASS] = normHost.getProjectClass();
      result[IDX_PROJECT] = normHost.getProject();
      result[IDX_QUALIFIERS] = normHost.getQualifiers();
      result[IDX_TLD] = normHost.getTld();
    }

    return result;
  }