use of org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector in project hive by apache.
the class GenericUDFFormatNumber method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length != 2) {
throw new UDFArgumentLengthException("The function FORMAT_NUMBER(X, D or F) needs two arguments.");
}
switch(arguments[0].getCategory()) {
case PRIMITIVE:
break;
default:
throw new UDFArgumentTypeException(0, "Argument 1" + " of function FORMAT_NUMBER must be \"" + serdeConstants.TINYINT_TYPE_NAME + "\"" + " or \"" + serdeConstants.SMALLINT_TYPE_NAME + "\"" + " or \"" + serdeConstants.INT_TYPE_NAME + "\"" + " or \"" + serdeConstants.BIGINT_TYPE_NAME + "\"" + " or \"" + serdeConstants.DOUBLE_TYPE_NAME + "\"" + " or \"" + serdeConstants.FLOAT_TYPE_NAME + "\"" + " or \"" + serdeConstants.DECIMAL_TYPE_NAME + "\", but \"" + arguments[0].getTypeName() + "\" was found.");
}
switch(arguments[1].getCategory()) {
case PRIMITIVE:
break;
default:
throw new UDFArgumentTypeException(1, "Argument 2" + " of function FORMAT_NUMBER must be \"" + serdeConstants.TINYINT_TYPE_NAME + "\"" + " or \"" + serdeConstants.SMALLINT_TYPE_NAME + "\"" + " or \"" + serdeConstants.INT_TYPE_NAME + "\"" + " or \"" + serdeConstants.BIGINT_TYPE_NAME + "\"" + " or \"" + serdeConstants.STRING_TYPE_NAME + "\", but \"" + arguments[1].getTypeName() + "\" was found.");
}
PrimitiveObjectInspector xObjectInspector = (PrimitiveObjectInspector) arguments[0];
PrimitiveObjectInspector dObjectInspector = (PrimitiveObjectInspector) arguments[1];
switch(xObjectInspector.getPrimitiveCategory()) {
case VOID:
case BYTE:
case SHORT:
case INT:
case LONG:
case DOUBLE:
case FLOAT:
case DECIMAL:
break;
default:
throw new UDFArgumentTypeException(0, "Argument 1" + " of function FORMAT_NUMBER must be \"" + serdeConstants.TINYINT_TYPE_NAME + "\"" + " or \"" + serdeConstants.SMALLINT_TYPE_NAME + "\"" + " or \"" + serdeConstants.INT_TYPE_NAME + "\"" + " or \"" + serdeConstants.BIGINT_TYPE_NAME + "\"" + " or \"" + serdeConstants.DOUBLE_TYPE_NAME + "\"" + " or \"" + serdeConstants.FLOAT_TYPE_NAME + "\"" + " or \"" + serdeConstants.DECIMAL_TYPE_NAME + "\", but \"" + arguments[0].getTypeName() + "\" was found.");
}
dType = dObjectInspector.getPrimitiveCategory();
switch(dType) {
case VOID:
case BYTE:
case SHORT:
case INT:
case LONG:
break;
case STRING:
if (!(arguments[1] instanceof ConstantObjectInspector)) {
throw new UDFArgumentTypeException(1, "Format string passed must be a constant STRING." + arguments[1].toString());
}
ConstantObjectInspector constantOI = (ConstantObjectInspector) arguments[1];
String fValue = constantOI.getWritableConstantValue().toString();
DecimalFormat dFormat = new DecimalFormat(fValue);
numberFormat.applyPattern(dFormat.toPattern());
break;
default:
throw new UDFArgumentTypeException(1, "Argument 2" + " of function FORMAT_NUMBER must be \"" + serdeConstants.TINYINT_TYPE_NAME + "\"" + " or \"" + serdeConstants.SMALLINT_TYPE_NAME + "\"" + " or \"" + serdeConstants.INT_TYPE_NAME + "\"" + " or \"" + serdeConstants.BIGINT_TYPE_NAME + "\"" + " or \"" + serdeConstants.STRING_TYPE_NAME + "\", but \"" + arguments[1].getTypeName() + "\" was found.");
}
argumentOIs = arguments;
return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
}
use of org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector in project hive by apache.
the class GenericUDFSubstringIndex method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
checkArgsSize(arguments, 3, 3);
checkArgPrimitive(arguments, 0);
checkArgPrimitive(arguments, 1);
checkArgPrimitive(arguments, 2);
checkArgGroups(arguments, 0, inputTypes, STRING_GROUP);
checkArgGroups(arguments, 1, inputTypes, STRING_GROUP);
checkArgGroups(arguments, 2, inputTypes, NUMERIC_GROUP);
obtainStringConverter(arguments, 0, inputTypes, converters);
obtainStringConverter(arguments, 1, inputTypes, converters);
obtainIntConverter(arguments, 2, inputTypes, converters);
if (arguments[1] instanceof ConstantObjectInspector) {
delimConst = getConstantStringValue(arguments, 1);
isDelimConst = true;
}
if (arguments[2] instanceof ConstantObjectInspector) {
countConst = getConstantIntValue(arguments, 2);
isCountConst = true;
}
ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
return outputOI;
}
use of org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector in project hive by apache.
the class TypeCheckProcFactory method toStructConstDesc.
private static ExprNodeConstantDesc toStructConstDesc(ColumnInfo colInfo, ObjectInspector inspector, List<? extends StructField> fields) {
List<?> values = (List<?>) ((ConstantObjectInspector) inspector).getWritableConstantValue();
List<Object> constant = new ArrayList<Object>();
for (int i = 0; i < values.size(); i++) {
Object value = values.get(i);
PrimitiveObjectInspector fieldPoi = (PrimitiveObjectInspector) fields.get(i).getFieldObjectInspector();
constant.add(fieldPoi.getPrimitiveJavaObject(value));
}
ExprNodeConstantDesc constantExpr = new ExprNodeConstantDesc(colInfo.getType(), constant);
constantExpr.setFoldedFromCol(colInfo.getInternalName());
return constantExpr;
}
use of org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector in project hive by apache.
the class TypeCheckProcFactory method toListConstDesc.
private static ExprNodeConstantDesc toListConstDesc(ColumnInfo colInfo, ObjectInspector inspector, ObjectInspector listElementOI) {
PrimitiveObjectInspector poi = (PrimitiveObjectInspector) listElementOI;
List<?> values = (List<?>) ((ConstantObjectInspector) inspector).getWritableConstantValue();
List<Object> constant = new ArrayList<Object>();
for (Object o : values) {
constant.add(poi.getPrimitiveJavaObject(o));
}
ExprNodeConstantDesc constantExpr = new ExprNodeConstantDesc(colInfo.getType(), constant);
constantExpr.setFoldedFromCol(colInfo.getInternalName());
return constantExpr;
}
use of org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector in project hive by apache.
the class TypeCheckProcFactory method toMapConstDesc.
private static ExprNodeConstantDesc toMapConstDesc(ColumnInfo colInfo, ObjectInspector inspector, ObjectInspector keyOI, ObjectInspector valueOI) {
PrimitiveObjectInspector keyPoi = (PrimitiveObjectInspector) keyOI;
PrimitiveObjectInspector valuePoi = (PrimitiveObjectInspector) valueOI;
Map<?, ?> values = (Map<?, ?>) ((ConstantObjectInspector) inspector).getWritableConstantValue();
Map<Object, Object> constant = new HashMap<Object, Object>();
for (Map.Entry<?, ?> e : values.entrySet()) {
constant.put(keyPoi.getPrimitiveJavaObject(e.getKey()), valuePoi.getPrimitiveJavaObject(e.getValue()));
}
ExprNodeConstantDesc constantExpr = new ExprNodeConstantDesc(colInfo.getType(), constant);
constantExpr.setFoldedFromCol(colInfo.getInternalName());
return constantExpr;
}
Aggregations