use of org.apache.hadoop.hive.serde2.thrift.ConfigurableTProtocol in project hive by apache.
the class DynamicSerDe method initialize.
@Override
public void initialize(Configuration job, Properties tbl) throws SerDeException {
try {
String ddl = tbl.getProperty(serdeConstants.SERIALIZATION_DDL);
// type_name used to be tbl.getProperty(META_TABLE_NAME).
// However, now the value is DBName.TableName. To make it backward compatible,
// we take the TableName part as type_name.
//
String tableName = tbl.getProperty(META_TABLE_NAME);
int index = tableName.indexOf('.');
if (index != -1) {
type_name = tableName.substring(index + 1, tableName.length());
} else {
type_name = tableName;
}
String protoName = tbl.getProperty(serdeConstants.SERIALIZATION_FORMAT);
if (protoName == null) {
protoName = "org.apache.thrift.protocol.TBinaryProtocol";
}
// For backward compatibility
protoName = protoName.replace("com.facebook.thrift.protocol", "org.apache.thrift.protocol");
TProtocolFactory protFactory = TReflectionUtils.getProtocolFactoryByName(protoName);
bos_ = new ByteStream.Output();
bis_ = new ByteStream.Input();
tios = new TIOStreamTransport(bis_, bos_);
oprot_ = protFactory.getProtocol(tios);
iprot_ = protFactory.getProtocol(tios);
if (oprot_ instanceof org.apache.hadoop.hive.serde2.thrift.ConfigurableTProtocol) {
((ConfigurableTProtocol) oprot_).initialize(job, tbl);
}
if (iprot_ instanceof org.apache.hadoop.hive.serde2.thrift.ConfigurableTProtocol) {
((ConfigurableTProtocol) iprot_).initialize(job, tbl);
}
// in theory the include path should come from the configuration
List<String> include_path = new ArrayList<String>();
include_path.add(".");
LOG.debug("ddl=" + ddl);
parse_tree = new thrift_grammar(new ByteArrayInputStream(ddl.getBytes()), include_path, false);
parse_tree.Start();
bt = (DynamicSerDeStructBase) parse_tree.types.get(type_name);
if (bt == null) {
bt = (DynamicSerDeStructBase) parse_tree.tables.get(type_name);
}
if (bt == null) {
throw new SerDeException("Could not lookup table type " + type_name + " in this ddl: " + ddl);
}
bt.initialize();
} catch (Exception e) {
System.err.println(StringUtils.stringifyException(e));
throw new SerDeException(e);
}
}
Aggregations