use of co.cask.cdap.hive.serde.ObjectSerializer in project cdap by caskdata.
the class DatasetSerDe method initialize.
@Override
public void initialize(Configuration conf, Properties properties) throws SerDeException {
// The column names are saved as the given inspector to #serialize doesn't preserves them
// - maybe because it's an external table
// The columns property comes from the Hive metastore, which has it from the create table statement
// It is then important that this schema be accurate and in the right order - the same order as
// object inspectors will reflect them.
String datasetName = properties.getProperty(Constants.Explore.DATASET_NAME);
String namespace = properties.getProperty(Constants.Explore.DATASET_NAMESPACE);
// to avoid a null pointer exception that prevents dropping a table, we handle the null namespace case here.
if (namespace == null) {
// we also still need an ObjectInspector as Hive uses it to check what columns the table has.
this.objectInspector = new ObjectDeserializer(properties, null).getInspector();
return;
}
if (datasetName == null || datasetName.isEmpty()) {
throw new SerDeException("Dataset name not found in serde properties.");
}
// a bunch of times.
if (schema == null) {
DatasetId datasetId = new DatasetId(namespace, datasetName);
getDatasetSchema(conf, datasetId);
}
this.deserializer = new ObjectDeserializer(properties, schema);
ArrayList<String> columnNames = Lists.newArrayList(StringUtils.split(properties.getProperty("columns"), ","));
this.serializer = new ObjectSerializer(columnNames);
this.objectInspector = deserializer.getInspector();
}
Aggregations