Package org.apache.hadoop.hive.ql.exec

Examples of org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException


  public ObjectInspector initialize(ObjectInspector[] arguments)
  throws UDFArgumentException {
    if (arguments.length != 1) {
      throw new UDFArgumentLengthException("The function MAP_VALUES only accepts 1 argument.");
    } else if (!(arguments[0] instanceof MapObjectInspector)) {
      throw new UDFArgumentTypeException(0, "\""
          + Category.MAP.toString().toLowerCase()
          + "\" is expected at function MAP_VALUES, " + "but \""
          + arguments[0].getTypeName() + "\" is found");
    }
View Full Code Here


    }

    for (int i = 0; i < arguments.length; i++) {
      Category category = arguments[i].getCategory();
      if (category != Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(i, "The "
            + GenericUDFUtils.getOrdinal(i + 1)
            + " argument of function ELT is expected to a "
            + Category.PRIMITIVE.toString().toLowerCase() + " type, but "
            + category.toString().toLowerCase() + " is found");
      }
View Full Code Here

  static final Log LOG = LogFactory.getLog(GenericUDAFHistogramNumeric.class.getName());

  @Override
  public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException {
    if (parameters.length != 2) {
      throw new UDFArgumentTypeException(parameters.length - 1,
          "Please specify exactly two arguments.");
    }
   
    // validate the first parameter, which is the expression to compute over
    if (parameters[0].getCategory() != ObjectInspector.Category.PRIMITIVE) {
      throw new UDFArgumentTypeException(0,
          "Only primitive type arguments are accepted but "
          + parameters[0].getTypeName() + " was passed as parameter 1.");
    }
    switch (((PrimitiveTypeInfo) parameters[0]).getPrimitiveCategory()) {
    case BYTE:
    case SHORT:
    case INT:
    case LONG:
    case FLOAT:
    case DOUBLE:
    case TIMESTAMP:
      break;
    case STRING:
    case BOOLEAN:
    default:
      throw new UDFArgumentTypeException(0,
          "Only numeric type arguments are accepted but "
          + parameters[0].getTypeName() + " was passed as parameter 1.");
    }

    // validate the second parameter, which is the number of histogram bins
    if (parameters[1].getCategory() != ObjectInspector.Category.PRIMITIVE) {
      throw new UDFArgumentTypeException(1,
          "Only primitive type arguments are accepted but "
          + parameters[1].getTypeName() + " was passed as parameter 2.");
    }
    if( ((PrimitiveTypeInfo) parameters[1]).getPrimitiveCategory()
        != PrimitiveObjectInspector.PrimitiveCategory.INT) {
      throw new UDFArgumentTypeException(1,
          "Only an integer argument is accepted as parameter 2, but "
          + parameters[1].getTypeName() + " was passed instead.");
    }

    return new GenericUDAFHistogramNumericEvaluator();
View Full Code Here

    argumentOIs = arguments;
    returnOIResolver = new GenericUDFUtils.ReturnObjectInspectorResolver();

    for (int i = 0; i + 1 < arguments.length; i += 2) {
      if (!arguments[i].getTypeName().equals(Constants.BOOLEAN_TYPE_NAME)) {
        throw new UDFArgumentTypeException(i, "\""
            + Constants.BOOLEAN_TYPE_NAME + "\" is expected after WHEN, "
            + "but \"" + arguments[i].getTypeName() + "\" is found");
      }
      if (!returnOIResolver.update(arguments[i + 1])) {
        throw new UDFArgumentTypeException(i + 1,
            "The expressions after THEN should have the same type: \""
            + returnOIResolver.get().getTypeName()
            + "\" is expected but \"" + arguments[i + 1].getTypeName()
            + "\" is found");
      }
    }
    if (arguments.length % 2 == 1) {
      int i = arguments.length - 2;
      if (!returnOIResolver.update(arguments[i + 1])) {
        throw new UDFArgumentTypeException(i + 1,
            "The expression after ELSE should have the same type as those after THEN: \""
            + returnOIResolver.get().getTypeName()
            + "\" is expected but \"" + arguments[i + 1].getTypeName()
            + "\" is found");
      }
View Full Code Here

  static final Log LOG = LogFactory.getLog(GenericUDAFCorrelation.class.getName());

  @Override
  public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException {
    if (parameters.length != 2) {
      throw new UDFArgumentTypeException(parameters.length - 1,
          "Exactly two arguments are expected.");
    }

    if (parameters[0].getCategory() != ObjectInspector.Category.PRIMITIVE) {
      throw new UDFArgumentTypeException(0,
          "Only primitive type arguments are accepted but "
          + parameters[0].getTypeName() + " is passed.");
    }

    if (parameters[1].getCategory() != ObjectInspector.Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(1,
            "Only primitive type arguments are accepted but "
            + parameters[1].getTypeName() + " is passed.");
    }

    switch (((PrimitiveTypeInfo) parameters[0]).getPrimitiveCategory()) {
    case BYTE:
    case SHORT:
    case INT:
    case LONG:
    case FLOAT:
    case DOUBLE:
    case TIMESTAMP:
      switch (((PrimitiveTypeInfo) parameters[1]).getPrimitiveCategory()) {
      case BYTE:
      case SHORT:
      case INT:
      case LONG:
      case FLOAT:
      case DOUBLE:
      case TIMESTAMP:
        return new GenericUDAFCorrelationEvaluator();
      case STRING:
      case BOOLEAN:
      default:
        throw new UDFArgumentTypeException(1,
            "Only numeric type arguments are accepted but "
            + parameters[1].getTypeName() + " is passed.");
      }
    case STRING:
    case BOOLEAN:
    default:
      throw new UDFArgumentTypeException(0,
          "Only numeric type arguments are accepted but "
          + parameters[0].getTypeName() + " is passed.");
    }
  }
View Full Code Here

    }

    if (arguments[0].getCategory().equals(Category.LIST)) {
      b1OI = (ListObjectInspector) arguments[0];
    } else {
        throw new UDFArgumentTypeException(0, "\""
          + Category.LIST.toString().toLowerCase()
          + "\" is expected at function " + name + ", but \""
          + arguments[0].getTypeName() + "\" is found");
    }

    if (arguments[1].getCategory().equals(Category.LIST)) {
      b2OI = (ListObjectInspector) arguments[1];
    } else {
        throw new UDFArgumentTypeException(1, "\""
          + Category.LIST.toString().toLowerCase()
          + "\" is expected at function " + name + ", but \""
          + arguments[1].getTypeName() + "\" is found");
    }
View Full Code Here

      case LIST:
        if(((ListObjectInspector)(arguments[0])).getListElementObjectInspector()
          .getCategory().equals(Category.PRIMITIVE))
          break;
      default:
        throw new UDFArgumentTypeException(0, "Argument 1"
          + " of function SORT_ARRAY must be " + Constants.LIST_TYPE_NAME
          + "<" + Category.PRIMITIVE + ">, but " + arguments[0].getTypeName()
          + " was found.");
    }
View Full Code Here

          "The function PRINTF(String format, Obj... args) needs at least one arguments.");
    }

    if (arguments[0].getTypeName() != Constants.STRING_TYPE_NAME
      && arguments[0].getTypeName() != Constants.VOID_TYPE_NAME) {
        throw new UDFArgumentTypeException(0, "Argument 1"
        + " of function PRINTF must be \"" + Constants.STRING_TYPE_NAME
        + "\", but \"" + arguments[0].getTypeName() + "\" was found.");
      }

    for (int i = 1; i < arguments.length; i++) {
      if (!arguments[i].getCategory().equals(Category.PRIMITIVE)){
        throw new UDFArgumentTypeException(i, "Argument " + (i + 1)
        + " of function PRINTF must be \"" + Category.PRIMITIVE
        + "\", but \"" + arguments[i].getTypeName() + "\" was found.");
      }
    }
View Full Code Here

        case PRIMITIVE:
          if (arguments[i].getTypeName().equals(Constants.STRING_TYPE_NAME)
            || arguments[i].getTypeName().equals(Constants.VOID_TYPE_NAME))
          break;
        default:
          throw new UDFArgumentTypeException(i, "Argument " + (i + 1)
            + " of function CONCAT_WS must be \"" + Constants.STRING_TYPE_NAME
            + " or " + Constants.LIST_TYPE_NAME + "<" + Constants.STRING_TYPE_NAME
            + ">\", but \"" + arguments[i].getTypeName() + "\" was found.");
      }
    }
View Full Code Here

    }

    for (int i = 0; i < 3; i++) {
      if (arguments[i].getTypeName() != Constants.STRING_TYPE_NAME
          && arguments[i].getTypeName() != Constants.VOID_TYPE_NAME) {
        throw new UDFArgumentTypeException(i, "The " + getOrdinal(i + 1)
            + " argument of function TRANSLATE is expected to \""
            + Constants.STRING_TYPE_NAME + "\", but \""
            + arguments[i].getTypeName() + "\" is found");
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.