format = (InputFormat) Class.forName(inputFormatName).getConstructor().newInstance();
Class c = Class.forName(sLib);
serde = (SerDe) c.getConstructor().newInstance();
serde.initialize(job, properties);
} catch (ReflectiveOperationException | SerDeException e) {
throw new ExecutionSetupException("Unable to instantiate InputFormat", e);
}
job.setInputFormat(format.getClass());
List<FieldSchema> partitionKeys = table.getPartitionKeys();
List<String> partitionNames = Lists.newArrayList();
for (FieldSchema field : partitionKeys) {
partitionNames.add(field.getName());
}
try {
ObjectInspector oi = serde.getObjectInspector();
if (oi.getCategory() != ObjectInspector.Category.STRUCT) {
throw new UnsupportedOperationException(String.format("%s category not supported", oi.getCategory()));
}
sInspector = (StructObjectInspector) oi;
StructTypeInfo sTypeInfo = (StructTypeInfo) TypeInfoUtils.getTypeInfoFromObjectInspector(sInspector);
if (projectedColumns == null) {
selectedColumnNames = sTypeInfo.getAllStructFieldNames();
tableColumns = selectedColumnNames;
} else {
tableColumns = sTypeInfo.getAllStructFieldNames();
List<Integer> columnIds = Lists.newArrayList();
selectedColumnNames = Lists.newArrayList();
for (SchemaPath field : projectedColumns) {
String columnName = field.getRootSegment().getPath();
if (!tableColumns.contains(columnName)) {
if (partitionNames.contains(columnName)) {
selectedPartitionNames.add(columnName);
} else {
throw new ExecutionSetupException(String.format("Column %s does not exist", columnName));
}
} else {
columnIds.add(tableColumns.indexOf(columnName));
selectedColumnNames.add(columnName);
}
}
ColumnProjectionUtils.appendReadColumnIDs(job, columnIds);
ColumnProjectionUtils.appendReadColumnNames(job, selectedColumnNames);
}
for (String columnName : selectedColumnNames) {
ObjectInspector fieldOI = sInspector.getStructFieldRef(columnName).getFieldObjectInspector();
TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(fieldOI.getTypeName());
selectedColumnObjInspectors.add(fieldOI);
selectedColumnTypes.add(typeInfo);
selectedColumnFieldConverters.add(HiveFieldConverter.create(typeInfo));
}
if (projectedColumns == null) {
selectedPartitionNames = partitionNames;
}
for (int i = 0; i < table.getPartitionKeys().size(); i++) {
FieldSchema field = table.getPartitionKeys().get(i);
if (selectedPartitionNames.contains(field.getName())) {
TypeInfo pType = TypeInfoUtils.getTypeInfoFromTypeString(field.getType());
selectedPartitionTypes.add(pType);
if (partition != null) {
selectedPartitionValues.add(convertPartitionType(pType, partition.getValues().get(i)));
}
}
}
} catch (Exception e) {
throw new ExecutionSetupException("Failure while initializing HiveRecordReader: " + e.getMessage(), e);
}
if (!empty) {
try {
reader = format.getRecordReader(inputSplit, job, Reporter.NULL);
} catch (IOException e) {
throw new ExecutionSetupException("Failed to get o.a.hadoop.mapred.RecordReader from Hive InputFormat", e);
}
key = reader.createKey();
value = reader.createValue();
}
}