/** * Gets the negative function of the current one. E.g., GenericUDFOPNotEqual for * GenericUDFOPEqual, or GenericUDFOPNull for GenericUDFOPNotNull. * @return Negative function * @throws UDFArgumentException */ public GenericUDF negative() { throw new UnsupportedOperationException("Negative function doesn't exist for " + getFuncName()); }
/** * Gets the negative function of the current one. E.g., GenericUDFOPNotEqual for * GenericUDFOPEqual, or GenericUDFOPNull for GenericUDFOPNotNull. * @return Negative function * @throws UDFArgumentException */ public GenericUDF negative() { throw new UnsupportedOperationException("Negative function doesn't exist for " + getFuncName()); }
protected void checkArgsSize(ObjectInspector[] arguments, int min, int max) throws UDFArgumentLengthException { if (arguments.length < min || arguments.length > max) { StringBuilder sb = new StringBuilder(); sb.append(getFuncName()); sb.append(" requires "); if (min == max) { sb.append(min); } else { sb.append(min).append("..").append(max); } sb.append(" argument(s), got "); sb.append(arguments.length); throw new UDFArgumentLengthException(sb.toString()); } }
protected void checkArgsSize(ObjectInspector[] arguments, int min, int max) throws UDFArgumentLengthException { if (arguments.length < min || arguments.length > max) { StringBuilder sb = new StringBuilder(); sb.append(getFuncName()); sb.append(" requires "); if (min == max) { sb.append(min); } else { sb.append(min).append("..").append(max); } sb.append(" argument(s), got "); sb.append(arguments.length); throw new UDFArgumentLengthException(sb.toString()); } }
protected void checkArgGroups(ObjectInspector[] arguments, int i, PrimitiveCategory[] inputTypes, PrimitiveGrouping... grps) throws UDFArgumentTypeException { PrimitiveCategory inputType = ((PrimitiveObjectInspector) arguments[i]).getPrimitiveCategory(); for (PrimitiveGrouping grp : grps) { if (PrimitiveObjectInspectorUtils.getPrimitiveGrouping(inputType) == grp) { inputTypes[i] = inputType; return; } } // build error message StringBuilder sb = new StringBuilder(); sb.append(getFuncName()); sb.append(" only takes "); sb.append(grps[0]); for (int j = 1; j < grps.length; j++) { sb.append(", "); sb.append(grps[j]); } sb.append(" types as "); sb.append(getArgOrder(i)); sb.append(" argument, got "); sb.append(inputType); throw new UDFArgumentTypeException(i, sb.toString()); }
protected void checkArgPrimitive(ObjectInspector[] arguments, int i) throws UDFArgumentTypeException { ObjectInspector.Category oiCat = arguments[i].getCategory(); if (oiCat != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, getFuncName() + " only takes primitive types as " + getArgOrder(i) + " argument, got " + oiCat); } }
protected Boolean getConstantBooleanValue(ObjectInspector[] arguments, int i) throws UDFArgumentTypeException { Object constValue = ((ConstantObjectInspector) arguments[i]).getWritableConstantValue(); if (constValue == null) { return false; } if (constValue instanceof BooleanWritable) { return ((BooleanWritable) constValue).get(); } else { throw new UDFArgumentTypeException(i, getFuncName() + " only takes BOOLEAN types as " + getArgOrder(i) + " argument, got " + constValue.getClass()); } }
protected void checkArgPrimitive(ObjectInspector[] arguments, int i) throws UDFArgumentTypeException { ObjectInspector.Category oiCat = arguments[i].getCategory(); if (oiCat != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, getFuncName() + " only takes primitive types as " + getArgOrder(i) + " argument, got " + oiCat); } }
protected Boolean getConstantBooleanValue(ObjectInspector[] arguments, int i) throws UDFArgumentTypeException { Object constValue = ((ConstantObjectInspector) arguments[i]).getWritableConstantValue(); if (constValue == null) { return false; } if (constValue instanceof BooleanWritable) { return ((BooleanWritable) constValue).get(); } else { throw new UDFArgumentTypeException(i, getFuncName() + " only takes BOOLEAN types as " + getArgOrder(i) + " argument, got " + constValue.getClass()); } }
protected Integer getConstantIntValue(ObjectInspector[] arguments, int i) throws UDFArgumentTypeException { Object constValue = ((ConstantObjectInspector) arguments[i]).getWritableConstantValue(); if (constValue == null) { return null; } int v; if (constValue instanceof IntWritable) { v = ((IntWritable) constValue).get(); } else if (constValue instanceof ShortWritable) { v = ((ShortWritable) constValue).get(); } else if (constValue instanceof ByteWritable) { v = ((ByteWritable) constValue).get(); } else { throw new UDFArgumentTypeException(i, getFuncName() + " only takes INT/SHORT/BYTE types as " + getArgOrder(i) + " argument, got " + constValue.getClass()); } return v; }
protected Integer getConstantIntValue(ObjectInspector[] arguments, int i) throws UDFArgumentTypeException { Object constValue = ((ConstantObjectInspector) arguments[i]).getWritableConstantValue(); if (constValue == null) { return null; } int v; if (constValue instanceof IntWritable) { v = ((IntWritable) constValue).get(); } else if (constValue instanceof ShortWritable) { v = ((ShortWritable) constValue).get(); } else if (constValue instanceof ByteWritable) { v = ((ByteWritable) constValue).get(); } else { throw new UDFArgumentTypeException(i, getFuncName() + " only takes INT/SHORT/BYTE types as " + getArgOrder(i) + " argument, got " + constValue.getClass()); } return v; }
protected void obtainIntConverter(ObjectInspector[] arguments, int i, PrimitiveCategory[] inputTypes, Converter[] converters) throws UDFArgumentTypeException { PrimitiveObjectInspector inOi = (PrimitiveObjectInspector) arguments[i]; PrimitiveCategory inputType = inOi.getPrimitiveCategory(); switch (inputType) { case BYTE: case SHORT: case INT: case VOID: break; default: throw new UDFArgumentTypeException(i, getFuncName() + " only takes INT/SHORT/BYTE types as " + getArgOrder(i) + " argument, got " + inputType); } Converter converter = ObjectInspectorConverters.getConverter( arguments[i], PrimitiveObjectInspectorFactory.writableIntObjectInspector); converters[i] = converter; inputTypes[i] = inputType; }
protected void obtainLongConverter(ObjectInspector[] arguments, int i, PrimitiveCategory[] inputTypes, Converter[] converters) throws UDFArgumentTypeException { PrimitiveObjectInspector inOi = (PrimitiveObjectInspector) arguments[i]; PrimitiveCategory inputType = inOi.getPrimitiveCategory(); switch (inputType) { case BYTE: case SHORT: case INT: case LONG: case VOID: break; default: throw new UDFArgumentTypeException(i, getFuncName() + " only takes LONG/INT/SHORT/BYTE types as " + getArgOrder(i) + " argument, got " + inputType); } Converter converter = ObjectInspectorConverters.getConverter( arguments[i], PrimitiveObjectInspectorFactory.writableLongObjectInspector); converters[i] = converter; inputTypes[i] = inputType; }
protected void obtainTimestampConverter(ObjectInspector[] arguments, int i, PrimitiveCategory[] inputTypes, Converter[] converters) throws UDFArgumentTypeException { PrimitiveObjectInspector inOi = (PrimitiveObjectInspector) arguments[i]; PrimitiveCategory inputType = inOi.getPrimitiveCategory(); ObjectInspector outOi; switch (inputType) { case STRING: case VARCHAR: case CHAR: case TIMESTAMP: case DATE: case TIMESTAMPLOCALTZ: break; default: throw new UDFArgumentTypeException(i, getFuncName() + " only takes STRING_GROUP or DATE_GROUP types as " + getArgOrder(i) + " argument, got " + inputType); } outOi = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector; converters[i] = ObjectInspectorConverters.getConverter(inOi, outOi); inputTypes[i] = inputType; }
protected void obtainDateConverter(ObjectInspector[] arguments, int i, PrimitiveCategory[] inputTypes, Converter[] converters) throws UDFArgumentTypeException { PrimitiveObjectInspector inOi = (PrimitiveObjectInspector) arguments[i]; PrimitiveCategory inputType = inOi.getPrimitiveCategory(); ObjectInspector outOi; switch (inputType) { case STRING: case VARCHAR: case CHAR: outOi = PrimitiveObjectInspectorFactory.writableStringObjectInspector; break; case TIMESTAMP: case DATE: case VOID: case TIMESTAMPLOCALTZ: outOi = PrimitiveObjectInspectorFactory.writableDateObjectInspector; break; default: throw new UDFArgumentTypeException(i, getFuncName() + " only takes STRING_GROUP or DATE_GROUP types as " + getArgOrder(i) + " argument, got " + inputType); } converters[i] = ObjectInspectorConverters.getConverter(inOi, outOi); inputTypes[i] = inputType; }
protected void obtainLongConverter(ObjectInspector[] arguments, int i, PrimitiveCategory[] inputTypes, Converter[] converters) throws UDFArgumentTypeException { PrimitiveObjectInspector inOi = (PrimitiveObjectInspector) arguments[i]; PrimitiveCategory inputType = inOi.getPrimitiveCategory(); switch (inputType) { case BYTE: case SHORT: case INT: case LONG: break; default: throw new UDFArgumentTypeException(i, getFuncName() + " only takes LONG/INT/SHORT/BYTE types as " + getArgOrder(i) + " argument, got " + inputType); } Converter converter = ObjectInspectorConverters.getConverter( arguments[i], PrimitiveObjectInspectorFactory.writableIntObjectInspector); converters[i] = converter; inputTypes[i] = inputType; }
protected void obtainIntConverter(ObjectInspector[] arguments, int i, PrimitiveCategory[] inputTypes, Converter[] converters) throws UDFArgumentTypeException { PrimitiveObjectInspector inOi = (PrimitiveObjectInspector) arguments[i]; PrimitiveCategory inputType = inOi.getPrimitiveCategory(); switch (inputType) { case BYTE: case SHORT: case INT: case VOID: break; default: throw new UDFArgumentTypeException(i, getFuncName() + " only takes INT/SHORT/BYTE types as " + getArgOrder(i) + " argument, got " + inputType); } Converter converter = ObjectInspectorConverters.getConverter( arguments[i], PrimitiveObjectInspectorFactory.writableIntObjectInspector); converters[i] = converter; inputTypes[i] = inputType; }
protected void obtainTimestampConverter(ObjectInspector[] arguments, int i, PrimitiveCategory[] inputTypes, Converter[] converters) throws UDFArgumentTypeException { PrimitiveObjectInspector inOi = (PrimitiveObjectInspector) arguments[i]; PrimitiveCategory inputType = inOi.getPrimitiveCategory(); ObjectInspector outOi; switch (inputType) { case STRING: case VARCHAR: case CHAR: case TIMESTAMP: case DATE: break; default: throw new UDFArgumentTypeException(i, getFuncName() + " only takes STRING_GROUP or DATE_GROUP types as " + getArgOrder(i) + " argument, got " + inputType); } outOi = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector; converters[i] = ObjectInspectorConverters.getConverter(inOi, outOi); inputTypes[i] = inputType; }
protected HiveIntervalYearMonth getIntervalYearMonthValue(DeferredObject[] arguments, int i, PrimitiveCategory[] inputTypes, Converter[] converters) throws HiveException { Object obj; if ((obj = arguments[i].get()) == null) { return null; } HiveIntervalYearMonth intervalYearMonth; switch (inputTypes[i]) { case STRING: case VARCHAR: case CHAR: String intervalYearMonthStr = converters[i].convert(obj).toString(); intervalYearMonth = HiveIntervalYearMonth.valueOf(intervalYearMonthStr); break; case INTERVAL_YEAR_MONTH: Object writableValue = converters[i].convert(obj); intervalYearMonth = ((HiveIntervalYearMonthWritable) writableValue).getHiveIntervalYearMonth(); break; default: throw new UDFArgumentTypeException(0, getFuncName() + " only takes INTERVAL_YEAR_MONTH and STRING_GROUP types, got " + inputTypes[i]); } return intervalYearMonth; }
protected HiveIntervalDayTime getIntervalDayTimeValue(DeferredObject[] arguments, int i, PrimitiveCategory[] inputTypes, Converter[] converters) throws HiveException { Object obj; if ((obj = arguments[i].get()) == null) { return null; } HiveIntervalDayTime intervalDayTime; switch (inputTypes[i]) { case STRING: case VARCHAR: case CHAR: String intervalDayTimeStr = converters[i].convert(obj).toString(); intervalDayTime = HiveIntervalDayTime.valueOf(intervalDayTimeStr); break; case INTERVAL_DAY_TIME: Object writableValue = converters[i].convert(obj); intervalDayTime = ((HiveIntervalDayTimeWritable) writableValue).getHiveIntervalDayTime(); break; default: throw new UDFArgumentTypeException(0, getFuncName() + " only takes INTERVAL_DAY_TIME and STRING_GROUP types, got " + inputTypes[i]); } return intervalDayTime; }