in gobblin-compaction/src/main/java/org/apache/gobblin/compaction/mapreduce/orc/OrcUtils.java [420:481]
public static WritableComparable createValueRecursively(TypeDescription schema, int elemNum) {
switch (schema.getCategory()) {
case BOOLEAN:
return new BooleanWritable();
case BYTE:
return new ByteWritable();
case SHORT:
return new ShortWritable();
case INT:
return new IntWritable();
case LONG:
return new LongWritable();
case FLOAT:
return new FloatWritable();
case DOUBLE:
return new DoubleWritable();
case BINARY:
return new BytesWritable();
case CHAR:
case VARCHAR:
case STRING:
return new Text();
case DATE:
return new DateWritable();
case TIMESTAMP:
case TIMESTAMP_INSTANT:
return new OrcTimestamp();
case DECIMAL:
return new HiveDecimalWritable();
case STRUCT: {
OrcStruct result = new OrcStruct(schema);
int c = 0;
for (TypeDescription child : schema.getChildren()) {
result.setFieldValue(c++, createValueRecursively(child, elemNum));
}
return result;
}
case UNION: {
// For union, there's no way to determine which tag's object type to create with only schema.
// It can be determined in the cases when a OrcUnion's value needs to be copied to another object recursively,
// and the source OrcUnion can provide this information.
return new OrcUnion(schema);
}
case LIST: {
OrcList result = new OrcList(schema);
for (int i = 0; i < elemNum; i++) {
result.add(createValueRecursively(schema.getChildren().get(0), elemNum));
}
return result;
}
case MAP: {
OrcMap result = new OrcMap(schema);
for (int i = 0; i < elemNum; i++) {
result.put(createValueRecursively(schema.getChildren().get(0), elemNum),
createValueRecursively(schema.getChildren().get(1), elemNum));
}
return result;
}
default:
throw new IllegalArgumentException("Unknown type " + schema);
}
}