Search in sources :

Example 6 with TSerializer

use of org.apache.thrift.TSerializer in project tsfile by thulab.

the class ReadWriteThriftFormatUtils method write.

/**
 * @param tbase
 *            input class in thrift format
 * @param to
 *            OutputStream
 * @throws IOException
 *             exception in IO
 */
public static void write(TBase<?, ?> tbase, OutputStream to) throws IOException {
    try {
        TSerializer serializer = new TSerializer(new TCompactProtocol.Factory());
        to.write(serializer.serialize(tbase));
    } catch (TException e) {
        LOGGER.error("tsfile-file Utils: can not write {}", tbase, e);
        throw new IOException(e);
    }
}
Also used : TException(org.apache.thrift.TException) TSerializer(org.apache.thrift.TSerializer) IOException(java.io.IOException) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol)

Example 7 with TSerializer

use of org.apache.thrift.TSerializer in project SpinalTap by airbnb.

the class ColumnSerializationUtilTest method testDeserializeColumn.

@Test
public void testDeserializeColumn() throws Exception {
    Mutation mutation = new Mutation(MutationType.DELETE, TIMESTAMP, SOURCE_ID, DATA_SOURCE, BINLOG_HEADER, TABLE, getEntity());
    TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());
    TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
    byte[] serialized = serializer.serialize(mutation);
    Mutation deserialized = new Mutation();
    deserializer.deserialize(deserialized, serialized);
    assertEquals(mutation, deserialized);
}
Also used : TSerializer(org.apache.thrift.TSerializer) TDeserializer(org.apache.thrift.TDeserializer) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) Mutation(com.airbnb.jitney.event.spinaltap.v1.Mutation) Test(org.junit.Test)

Example 8 with TSerializer

use of org.apache.thrift.TSerializer in project beam by apache.

the class BeamKafkaTableThriftTest method generateEncodedPayload.

@Override
protected byte[] generateEncodedPayload(int i) {
    final TestThriftMessage message = new TestThriftMessage().setFLong(i).setFInt(i).setFDouble(i).setFString("thrift_value" + i);
    message.addToFDoubleArray(i);
    try {
        return new TSerializer(protocolFactory).serialize(message);
    } catch (TException e) {
        throw new RuntimeException(e);
    }
}
Also used : TException(org.apache.thrift.TException) TSerializer(org.apache.thrift.TSerializer) TestThriftMessage(org.apache.beam.sdk.io.thrift.payloads.TestThriftMessage)

Example 9 with TSerializer

use of org.apache.thrift.TSerializer in project beam by apache.

the class ThriftPayloadSerializerProviderTest method deserialize.

@Test
public void deserialize() throws Exception {
    Row row = provider.getSerializer(SHUFFLED_SCHEMA, ImmutableMap.of("thriftClass", TestThriftMessage.class.getName(), "thriftProtocolFactoryClass", TCompactProtocol.Factory.class.getName())).deserialize(new TSerializer(new TCompactProtocol.Factory()).serialize(MESSAGE));
    assertEquals(ROW, row);
}
Also used : TSerializer(org.apache.thrift.TSerializer) TestThriftMessage(org.apache.beam.sdk.io.thrift.payloads.TestThriftMessage) Row(org.apache.beam.sdk.values.Row) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) Test(org.junit.Test)

Example 10 with TSerializer

use of org.apache.thrift.TSerializer in project druid by druid-io.

the class ThriftInputRowParserTest method testParse.

@Test
public void testParse() throws Exception {
    ThriftInputRowParser parser = new ThriftInputRowParser(parseSpec, "example/book.jar", "org.apache.druid.data.input.thrift.Book");
    Book book = new Book().setDate("2016-08-29").setPrice(19.9).setTitle("title").setAuthor(new Author().setFirstName("first").setLastName("last"));
    TSerializer serializer;
    byte[] bytes;
    // 1. compact
    serializer = new TSerializer(new TCompactProtocol.Factory());
    bytes = serializer.serialize(book);
    serializationAndTest(parser, bytes);
    // 2. binary + base64
    serializer = new TSerializer(new TBinaryProtocol.Factory());
    serializationAndTest(parser, StringUtils.encodeBase64(serializer.serialize(book)));
    // 3. json
    serializer = new TSerializer(new TJSONProtocol.Factory());
    bytes = serializer.serialize(book);
    serializationAndTest(parser, bytes);
}
Also used : TSerializer(org.apache.thrift.TSerializer) Test(org.junit.Test)

Aggregations

TSerializer (org.apache.thrift.TSerializer)35 TException (org.apache.thrift.TException)19 TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)14 IOException (java.io.IOException)12 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)8 Test (org.junit.Test)6 TDeserializer (org.apache.thrift.TDeserializer)5 ArrayList (java.util.ArrayList)4 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)4 OptRun (org.vcell.optimization.thrift.OptRun)4 Table (org.apache.hadoop.hive.metastore.api.Table)3 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)3 VCellApiClient (org.vcell.api.client.VCellApiClient)3 OptProblem (org.vcell.optimization.thrift.OptProblem)3 OptRunStatus (org.vcell.optimization.thrift.OptRunStatus)3 MathException (cbit.vcell.math.MathException)2 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)2 OptSolverResultSet (cbit.vcell.opt.OptSolverResultSet)2 OptRunResultSet (cbit.vcell.opt.OptSolverResultSet.OptRunResultSet)2 OptimizationException (cbit.vcell.opt.OptimizationException)2