use of org.apache.hadoop.hive.serde2.objectinspector.primitive.AbstractPrimitiveJavaObjectInspector in project hive by apache.
the class RegexSerDe method initialize.
@Override
public void initialize(Configuration configuration, Properties tableProperties, Properties partitionProperties) throws SerDeException {
super.initialize(configuration, tableProperties, partitionProperties);
numColumns = getColumnNames().size();
// Read the configuration parameters
inputRegex = properties.getProperty(INPUT_REGEX);
boolean inputRegexIgnoreCase = "true".equalsIgnoreCase(properties.getProperty(INPUT_REGEX_CASE_SENSITIVE));
// output format string is not supported anymore, warn user of deprecation
if (null != properties.getProperty("output.format.string")) {
log.warn("output.format.string has been deprecated");
}
// Parse the configuration parameters
if (inputRegex != null) {
inputPattern = Pattern.compile(inputRegex, Pattern.DOTALL + (inputRegexIgnoreCase ? Pattern.CASE_INSENSITIVE : 0));
} else {
inputPattern = null;
throw new SerDeException("This table does not have serde property \"input.regex\"!");
}
/* Constructing the row ObjectInspector:
* The row consists of some set of primitive columns, each column will
* be a java object of primitive type.
*/
List<ObjectInspector> columnOIs = new ArrayList<>(getColumnNames().size());
for (int c = 0; c < numColumns; c++) {
TypeInfo typeInfo = getColumnTypes().get(c);
if (typeInfo instanceof PrimitiveTypeInfo) {
PrimitiveTypeInfo pti = (PrimitiveTypeInfo) typeInfo;
AbstractPrimitiveJavaObjectInspector oi = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(pti);
columnOIs.add(oi);
} else {
throw new SerDeException(getClass().getName() + " doesn't allow column [" + c + "] named " + getColumnNames().get(c) + " with type " + typeInfo);
}
}
// StandardStruct uses ArrayList to store the row.
rowOI = ObjectInspectorFactory.getStandardStructObjectInspector(getColumnNames(), columnOIs, Lists.newArrayList(Splitter.on('\0').split(properties.getProperty("columns.comments"))));
// Constructing the row object, etc, which will be reused for all rows.
row = new ArrayList<>(Collections.nCopies(numColumns, null));
outputFields = new Object[numColumns];
outputRowText = new Text();
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.AbstractPrimitiveJavaObjectInspector in project hive by apache.
the class VectorUDFArgDesc method prepareConstant.
/* Prepare the constant for use when the function is called. To be used
* during initialization.
*/
public void prepareConstant() {
final Object writableValue;
if (constExpr != null) {
Object constantValue = constExpr.getValue();
TypeInfo typeInfo = constExpr.getTypeInfo();
ObjectInspector objectInspector = TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo(typeInfo);
Category category = typeInfo.getCategory();
switch(category) {
case PRIMITIVE:
{
PrimitiveCategory pc = ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory();
// Convert from Java to Writable
AbstractPrimitiveJavaObjectInspector primitiveJavaObjectInspector = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(pc);
writableValue = primitiveJavaObjectInspector.getPrimitiveWritableObject(constantValue);
}
break;
case STRUCT:
{
if (constantValue.getClass().isArray()) {
constantValue = java.util.Arrays.asList((Object[]) constantValue);
}
StructObjectInspector structObjectInspector = (StructObjectInspector) objectInspector;
List<? extends StructField> fields = structObjectInspector.getAllStructFieldRefs();
List<String> fieldNames = new ArrayList<String>(fields.size());
List<ObjectInspector> fieldObjectInspectors = new ArrayList<ObjectInspector>(fields.size());
for (StructField f : fields) {
fieldNames.add(f.getFieldName());
fieldObjectInspectors.add(ObjectInspectorUtils.getStandardObjectInspector(f.getFieldObjectInspector(), ObjectInspectorCopyOption.WRITABLE));
}
StandardConstantStructObjectInspector constantStructObjectInspector = ObjectInspectorFactory.getStandardConstantStructObjectInspector(fieldNames, fieldObjectInspectors, (List<?>) constantValue);
writableValue = constantStructObjectInspector.getWritableConstantValue();
}
break;
default:
throw new RuntimeException("Unexpected category " + category);
}
} else {
writableValue = null;
}
constObjVal = new GenericUDF.DeferredJavaObject(writableValue);
}
Aggregations