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

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


    for (int idx = 0; idx < Math.min(arguments.length, 3); ++idx) {
      if (arguments[idx].getCategory() != Category.PRIMITIVE
          || PrimitiveObjectInspectorUtils.getPrimitiveGrouping(
              ((PrimitiveObjectInspector) arguments[idx]).getPrimitiveCategory())
              != PrimitiveGrouping.STRING_GROUP) {
        throw new UDFArgumentException("All argument should be string/character type");
      }
    }
    soi_text = ObjectInspectorConverters.getConverter(arguments[0],
        PrimitiveObjectInspectorFactory.javaStringObjectInspector);
    if (arguments.length > 1) {
View Full Code Here


          "The macro " + macroName + " accepts exactly " + colTypes.size() + " arguments.");
    }
    try {
      body = ExprNodeEvaluatorFactory.get(bodyDesc);
    } catch (HiveException ex) {
      throw new UDFArgumentException(ex);
    }
    converters = new ObjectInspectorConverters.Converter[arguments.length];
    ArrayList<ObjectInspector> colObjectInspectors = new ArrayList<ObjectInspector>(colTypes.size());
    for (int index = 0; index < arguments.length; ++index) {
      ObjectInspector objectInspector = TypeInfoUtils.
          getStandardWritableObjectInspectorFromTypeInfo(colTypes.get(index));
      colObjectInspectors.add(objectInspector);
      converters[index] =
          ObjectInspectorConverters.getConverter(arguments[index], objectInspector);
    }
    evaluatedArguments = new ArrayList<Object>(arguments.length);
    ObjectInspector structOI = ObjectInspectorFactory
        .getStandardStructObjectInspector(colNames, colObjectInspectors);
    try {
      return body.initialize(structOI);
    } catch (HiveException ex) {
      throw new UDFArgumentException(ex);
    }
  }
View Full Code Here

      argumentOIs[0] = (PrimitiveObjectInspector) arguments[0];
      if (arguments.length > 1) {
        argumentOIs[1] = (PrimitiveObjectInspector) arguments[1];
      }
    } catch (ClassCastException e) {
      throw new UDFArgumentException(
          "The function " + getName() + " takes only primitive types");
    }

    timestampConverter = new TimestampConverter(argumentOIs[0],
        PrimitiveObjectInspectorFactory.writableTimestampObjectInspector);
View Full Code Here

    inputOIs = args;
    numCols = args.length - 1;

    if (numCols < 1) {
      throw new UDFArgumentException("json_tuple() takes at least two arguments: " +
          "the json string and a path expression");
    }

    for (int i = 0; i < args.length; ++i) {
      if (args[i].getCategory() != ObjectInspector.Category.PRIMITIVE ||
          !args[i].getTypeName().equals(serdeConstants.STRING_TYPE_NAME)) {
        throw new UDFArgumentException("json_tuple()'s arguments have to be string type");
      }
    }

    seenErrors = false;
    pathParsed = false;
View Full Code Here

      throw new UDFArgumentLengthException(
          "LOWER requires 1 argument, got " + arguments.length);
    }

    if (arguments[0].getCategory() != Category.PRIMITIVE) {
      throw new UDFArgumentException(
          "LOWER only takes primitive types, got " + argumentOI.getTypeName());
    }
    argumentOI = (PrimitiveObjectInspector) arguments[0];

    stringConverter = new PrimitiveObjectInspectorConverter.StringConverter(argumentOI);
View Full Code Here

          break;
        case VARCHAR:
          returnValue = new HiveVarcharWritable();
          break;
        default:
          throw new UDFArgumentException("Unexpected non-string type " + type);
      }
    }
View Full Code Here

          return returnValue;
        case VARCHAR:
          ((HiveVarcharWritable)returnValue).set(val);
          return returnValue;
        default:
          throw new UDFArgumentException("Bad return type " + type);
      }
    }
View Full Code Here

        case CHAR:
        case VARCHAR:
          BaseCharTypeInfo typeInfo = (BaseCharTypeInfo) poi.getTypeInfo();
          return typeInfo.getLength();
        default:
          throw new UDFArgumentException("No fixed size for type " + poi.getTypeName());
      }
    }
View Full Code Here

          "ROUND requires one or two argument, got " + arguments.length);
    }

    inputOI = (PrimitiveObjectInspector) arguments[0];
    if (inputOI.getCategory() != Category.PRIMITIVE) {
      throw new UDFArgumentException(
          "ROUND input only takes primitive types, got " + inputOI.getTypeName());
    }

    if (arguments.length == 2) {
      PrimitiveObjectInspector scaleOI = (PrimitiveObjectInspector) arguments[1];
      switch (scaleOI.getPrimitiveCategory()) {
      case VOID:
        break;
      case BYTE:
        if (!(scaleOI instanceof WritableConstantByteObjectInspector)) {
          throw new UDFArgumentException("ROUND second argument only takes constant");
        }
        scale = ((WritableConstantByteObjectInspector)scaleOI).getWritableConstantValue().get();
        break;
      case SHORT:
        if (!(scaleOI instanceof WritableConstantShortObjectInspector)) {
          throw new UDFArgumentException("ROUND second argument only takes constant");
        }
        scale = ((WritableConstantShortObjectInspector)scaleOI).getWritableConstantValue().get();
        break;
      case INT:
        if (!(scaleOI instanceof WritableConstantIntObjectInspector)) {
          throw new UDFArgumentException("ROUND second argument only takes constant");
        }
        scale = ((WritableConstantIntObjectInspector)scaleOI).getWritableConstantValue().get();
        break;
      case LONG:
        if (!(scaleOI instanceof WritableConstantLongObjectInspector)) {
          throw new UDFArgumentException("ROUND second argument only takes constant");
        }
        long l = ((WritableConstantLongObjectInspector)scaleOI).getWritableConstantValue().get();
        if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
          throw new UDFArgumentException("ROUND scale argument out of allowed range");
        }
        scale = (int)l;
        break;
      default:
        throw new UDFArgumentException("ROUND second argument only takes integer constant");
      }
    }

    inputType = inputOI.getPrimitiveCategory();
    ObjectInspector outputOI = null;
    switch (inputType) {
    case DECIMAL:
      DecimalTypeInfo inputTypeInfo = (DecimalTypeInfo) inputOI.getTypeInfo();
      DecimalTypeInfo typeInfo = getOutputTypeInfo(inputTypeInfo, scale);
      outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(typeInfo);
      break;
    case VOID:
    case BYTE:
    case SHORT:
    case INT:
    case LONG:
    case FLOAT:
    case DOUBLE:
      outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputType);
      break;
    case STRING:
    case VARCHAR:
    case CHAR:
      outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.DOUBLE);
      converterFromString = ObjectInspectorConverters.getConverter(inputOI, outputOI);
      break;
    default:
      throw new UDFArgumentException("Only numeric data types are allowed for ROUND function. Got " +
          inputType.name());
    }

    return outputOI;
  }
View Full Code Here

       if (doubleValue == null) {
         return null;
       }
       return round(doubleValue, scale);
     default:
       throw new UDFArgumentException("Only numeric data types are allowed for ROUND function. Got " +
           inputType.name());
    }
  }
View Full Code Here

TOP

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

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.