use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardStructObjectInspector 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 = this.getColumnNames().size();
// Read the configuration parameters
inputRegex = properties.getProperty(INPUT_REGEX);
outputFormatString = properties.getProperty(OUTPUT_FORMAT_STRING);
boolean inputRegexIgnoreCase = "true".equalsIgnoreCase(properties.getProperty(INPUT_REGEX_CASE_SENSITIVE));
// Parse the configuration parameters
if (inputRegex != null) {
inputPattern = Pattern.compile(inputRegex, Pattern.DOTALL + (inputRegexIgnoreCase ? Pattern.CASE_INSENSITIVE : 0));
} else {
inputPattern = null;
}
// All columns have to be of type STRING
int i = 0;
for (TypeInfo type : getColumnTypes()) {
if (!type.equals(TypeInfoFactory.stringTypeInfo)) {
throw new SerDeException(getClass().getName() + " only accepts string columns, but column[" + i + "] named " + getColumnNames().get(i) + " has type " + type);
}
i++;
}
// Constructing the row ObjectInspector:
// The row consists of some string columns, each column will be a java
// String object.
List<ObjectInspector> columnOIs = Collections.nCopies(numColumns, PrimitiveObjectInspectorFactory.javaStringObjectInspector);
// StandardStruct uses ArrayList to store the row.
rowOI = ObjectInspectorFactory.getStandardStructObjectInspector(getColumnNames(), columnOIs);
// 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.ObjectInspectorFactory.getStandardStructObjectInspector in project hive by apache.
the class TypedBytesSerDe method initialize.
@Override
public void initialize(Configuration configuration, Properties tableProperties, Properties partitionProperties) throws SerDeException {
super.initialize(configuration, tableProperties, partitionProperties);
// We can get the table definition from tbl.
serializeBytesWritable = new BytesWritable();
barrStr = new NonSyncDataOutputBuffer();
tbOut = new TypedBytesWritableOutput(barrStr);
inBarrStr = new NonSyncDataInputBuffer();
tbIn = new TypedBytesWritableInput(inBarrStr);
// Read the configuration parameters
numColumns = getColumnNames().size();
// All columns have to be primitive.
for (int c = 0; c < numColumns; c++) {
if (getColumnTypes().get(c).getCategory() != Category.PRIMITIVE) {
throw new SerDeException(getClass().getName() + " only accepts primitive columns, but column[" + c + "] named " + getColumnNames().get(c) + " has category " + getColumnTypes().get(c).getCategory());
}
}
// Constructing the row ObjectInspector:
// The row consists of some string columns, each column will be a java
// String object.
List<ObjectInspector> columnOIs = new ArrayList<>(getColumnNames().size());
for (TypeInfo colType : getColumnTypes()) {
columnOIs.add(TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo(colType));
}
// StandardStruct uses ArrayList to store the row.
rowOI = ObjectInspectorFactory.getStandardStructObjectInspector(getColumnNames(), columnOIs);
// Constructing the row object, etc, which will be reused for all rows.
row = new ArrayList<>(Collections.nCopies(numColumns, null));
}
use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardStructObjectInspector in project hive by apache.
the class TestDruidSerDe method serializeObject.
private static void serializeObject(Properties properties, DruidSerDe serDe, Object[] rowObject, DruidWritable druidWritable) throws SerDeException {
// Build OI with timestamp granularity column
final List<String> columnNames = new ArrayList<>(Utilities.getColumnNames(properties));
columnNames.add(Constants.DRUID_TIMESTAMP_GRANULARITY_COL_NAME);
final List<PrimitiveTypeInfo> columnTypes = Utilities.getColumnTypes(properties).stream().map(TypeInfoFactory::getPrimitiveTypeInfo).collect(Collectors.toList());
columnTypes.add(TypeInfoFactory.getPrimitiveTypeInfo("timestamp"));
List<ObjectInspector> inspectors = columnTypes.stream().map(PrimitiveObjectInspectorFactory::getPrimitiveWritableObjectInspector).collect(Collectors.toList());
ObjectInspector inspector = ObjectInspectorFactory.getStandardStructObjectInspector(columnNames, inspectors);
// Serialize
DruidWritable writable = (DruidWritable) serDe.serialize(rowObject, inspector);
// Check result
assertEquals(druidWritable.getValue().size(), writable.getValue().size());
for (Entry<String, Object> e : druidWritable.getValue().entrySet()) {
assertEquals(e.getValue(), writable.getValue().get(e.getKey()));
}
}
use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardStructObjectInspector in project hive by apache.
the class InternalUtil method createStructObjectInspector.
static StructObjectInspector createStructObjectInspector(HCatSchema outputSchema) throws IOException {
if (outputSchema == null) {
throw new IOException("Invalid output schema specified");
}
List<ObjectInspector> fieldInspectors = new ArrayList<ObjectInspector>();
List<String> fieldNames = new ArrayList<String>();
for (HCatFieldSchema hcatFieldSchema : outputSchema.getFields()) {
TypeInfo type = TypeInfoUtils.getTypeInfoFromTypeString(hcatFieldSchema.getTypeString());
fieldNames.add(hcatFieldSchema.getName());
fieldInspectors.add(getObjectInspector(type));
}
StructObjectInspector structInspector = ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldInspectors);
return structInspector;
}
use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardStructObjectInspector in project hive by apache.
the class TestDeserializer method testListDeserialize.
@Test
public void testListDeserialize() {
Schema schema = new Schema(optional(1, "list_type", Types.ListType.ofOptional(2, Types.LongType.get())));
StructObjectInspector inspector = ObjectInspectorFactory.getStandardStructObjectInspector(Arrays.asList("list_type"), Arrays.asList(ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableLongObjectInspector)));
Deserializer deserializer = new Deserializer.Builder().schema(schema).writerInspector((StructObjectInspector) IcebergObjectInspector.create(schema)).sourceInspector(inspector).build();
Record expected = GenericRecord.create(schema);
expected.set(0, Collections.singletonList(1L));
Object[] data = new Object[] { new Object[] { new LongWritable(1L) } };
Record actual = deserializer.deserialize(data);
Assert.assertEquals(expected, actual);
}
Aggregations