use of com.metamx.common.IAE in project druid by druid-io.
the class ThriftInputRowParser method parse.
@Override
public InputRow parse(Object input) {
// Place it this initialization in constructor will get ClassNotFoundException
try {
if (thriftClass == null) {
thriftClass = getThriftClass();
}
} catch (IOException e) {
throw new IAE(e, "failed to load jar [%s]", jarPath);
} catch (ClassNotFoundException e) {
throw new IAE(e, "class [%s] not found in jar", thriftClassName);
} catch (InstantiationException | IllegalAccessException e) {
throw new IAE(e, "instantiation thrift instance failed");
}
final String json;
try {
if (input instanceof ByteBuffer) {
// realtime stream
final byte[] bytes = ((ByteBuffer) input).array();
TBase o = thriftClass.newInstance();
ThriftDeserialization.detectAndDeserialize(bytes, o);
json = ThriftDeserialization.SERIALIZER_SIMPLE_JSON.get().toString(o);
} else if (input instanceof BytesWritable) {
// sequence file
final byte[] bytes = ((BytesWritable) input).getBytes();
TBase o = thriftClass.newInstance();
ThriftDeserialization.detectAndDeserialize(bytes, o);
json = ThriftDeserialization.SERIALIZER_SIMPLE_JSON.get().toString(o);
} else if (input instanceof ThriftWritable) {
// LzoBlockThrift file
TBase o = (TBase) ((ThriftWritable) input).get();
json = ThriftDeserialization.SERIALIZER_SIMPLE_JSON.get().toString(o);
} else {
throw new IAE("unsupport input class of [%s]", input.getClass());
}
} catch (IllegalAccessException | InstantiationException | TException e) {
throw new IAE("some thing wrong with your thrift?");
}
Map<String, Object> record = parser.parse(json);
return new MapBasedInputRow(parseSpec.getTimestampSpec().extractTimestamp(record), parseSpec.getDimensionsSpec().getDimensionNames(), record);
}
Aggregations