Search in sources :

Example 1 with IAE

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);
}
Also used : TException(org.apache.thrift.TException) ThriftWritable(com.twitter.elephantbird.mapreduce.io.ThriftWritable) BytesWritable(org.apache.hadoop.io.BytesWritable) IOException(java.io.IOException) IAE(com.metamx.common.IAE) ByteBuffer(java.nio.ByteBuffer) TBase(org.apache.thrift.TBase) MapBasedInputRow(io.druid.data.input.MapBasedInputRow)

Aggregations

IAE (com.metamx.common.IAE)1 ThriftWritable (com.twitter.elephantbird.mapreduce.io.ThriftWritable)1 MapBasedInputRow (io.druid.data.input.MapBasedInputRow)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 BytesWritable (org.apache.hadoop.io.BytesWritable)1 TBase (org.apache.thrift.TBase)1 TException (org.apache.thrift.TException)1