Example usage for org.apache.thrift TDeserializer deserialize

List of usage examples for org.apache.thrift TDeserializer deserialize

Introduction

In this page you can find the example usage for org.apache.thrift TDeserializer deserialize.

Prototype

public void deserialize(TBase base, byte[] bytes) throws TException 

Source Link

Document

Deserialize the Thrift object from a byte array.

Usage

From source file:org.apache.accumulo.core.security.CredentialHelper.java

License:Apache License

public static TCredentials fromByteArray(byte[] serializedCredential) throws AccumuloSecurityException {
    if (serializedCredential == null)
        return null;
    TDeserializer td = new TDeserializer();
    try {// w  w w.  jav a  2s  .  c o  m
        TCredentials toRet = new TCredentials();
        td.deserialize(toRet, serializedCredential);
        return toRet;
    } catch (TException e) {
        // This really shouldn't happen
        log.error(e, e);
        throw new AccumuloSecurityException("unknown", SecurityErrorCode.SERIALIZATION_ERROR);
    }
}

From source file:org.apache.cassandra.hadoop.ConfigHelper.java

License:Apache License

private static SlicePredicate predicateFromString(String st) {
    assert st != null;
    TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
    SlicePredicate predicate = new SlicePredicate();
    try {/*from  w w  w  .j  a  va 2  s.  c  om*/
        deserializer.deserialize(predicate, FBUtilities.hexToBytes(st));
    } catch (TException e) {
        throw new RuntimeException(e);
    }
    return predicate;
}

From source file:org.apache.cassandra.hadoop.pig.CassandraStorage.java

License:Apache License

/** convert string to a list of index expression */
private static List<IndexExpression> indexExpressionsFromString(String ie) throws IOException {
    assert ie != null;
    TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
    IndexClause indexClause = new IndexClause();
    try {// w  ww .j a  va 2 s. co m
        deserializer.deserialize(indexClause, Hex.hexToBytes(ie));
    } catch (TException e) {
        throw new IOException(e);
    }
    return indexClause.getExpressions();
}

From source file:org.apache.cassandra.hadoop2.pig.AbstractCassandraStorage.java

License:Apache License

/** convert string back to CfDef */
protected static CfDef cfdefFromString(String st) {
    assert st != null;
    TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
    CfDef cfDef = new CfDef();
    try {//from  ww w . j  av  a  2  s.c  o m
        deserializer.deserialize(cfDef, Hex.hexToBytes(st));
    } catch (TException e) {
        throw new RuntimeException(e);
    }
    return cfDef;
}

From source file:org.apache.cassandra.hadoop2.pig.CassandraStorage.java

License:Apache License

/** convert string to a list of index expression */
private static List<IndexExpression> indexExpressionsFromString(String ie) {
    assert ie != null;
    TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
    IndexClause indexClause = new IndexClause();
    try {//from   ww w . j  av  a 2s .c  o m
        deserializer.deserialize(indexClause, Hex.hexToBytes(ie));
    } catch (TException e) {
        throw new RuntimeException(e);
    }
    return indexClause.getExpressions();
}

From source file:org.apache.hadoop.hive.cassandra.CassandraPushdownPredicate.java

License:Apache License

/**
 * Serialize a set of ColumnDefs for indexed columns, read
 * from Job configuration/*from w w w.j av a2 s.com*/
 *
 * @param serialized column metadata
 * @return list of column metadata objects which may be empty, but not null
 */
public static Set<ColumnDef> deserializeIndexedColumns(String serialized) {
    Set<ColumnDef> columns = new HashSet<ColumnDef>();
    if (null == serialized) {
        return columns;
    }

    Iterable<String> strings = Splitter.on(AbstractCassandraSerDe.DELIMITER).omitEmptyStrings().trimResults()
            .split(serialized);
    TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
    for (String encoded : strings) {
        ColumnDef column = new ColumnDef();
        try {
            logger.info("Encoded column def: " + encoded);
            deserializer.deserialize(column, Hex.hexToBytes(encoded));
        } catch (TException e) {
            logger.warn("Error deserializing indexed column definition", e);
        }
        if (null == column.getName() || null == column.validation_class) {
            continue;
        }
        columns.add(column);
    }
    return columns;
}

From source file:org.apache.hcatalog.hbase.snapshot.ZKUtil.java

License:Apache License

/**
 * This method deserializes the given byte array into the TBase object.
 *
 * @param obj An instance of TBase//from w  ww .jav a2 s.  co m
 * @param data Output of deserialization.
 * @throws IOException
 */
static void deserialize(TBase obj, byte[] data) throws IOException {
    if (data == null || data.length == 0)
        return;
    try {
        TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
        deserializer.deserialize(obj, data);
    } catch (Exception e) {
        throw new IOException("Deserialization error: " + e.getMessage(), e);
    }
}

From source file:org.apache.impala.common.JniUtil.java

License:Apache License

/**
 * Deserialize a serialized form of a Thrift data structure to its object form.
 */// w  w  w  . ja v a2 s . c  o m
public static <T extends TBase<?, ?>, F extends TProtocolFactory> void deserializeThrift(F protocolFactory,
        T result, byte[] thriftData) throws ImpalaException {
    // TODO: avoid creating deserializer for each query?
    TDeserializer deserializer = new TDeserializer(protocolFactory);
    try {
        deserializer.deserialize(result, thriftData);
    } catch (TException e) {
        throw new InternalException(e.getMessage());
    }
}

From source file:org.apache.impala.service.FeSupport.java

License:Apache License

/**
 * Locally caches the jar at the specified HDFS location.
 *
 * @param hdfsLocation The path to the jar in HDFS
 * @return The result of the call to cache the jar, includes a status and the local
 *         path of the cached jar if the operation was successful.
 *//*w  w w. j  a va2s  .  co m*/
public static TCacheJarResult CacheJar(String hdfsLocation) throws InternalException {
    Preconditions.checkNotNull(hdfsLocation);
    TCacheJarParams params = new TCacheJarParams(hdfsLocation);
    TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());
    byte[] result;
    try {
        result = CacheJar(serializer.serialize(params));
        Preconditions.checkNotNull(result);
        TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
        TCacheJarResult thriftResult = new TCacheJarResult();
        deserializer.deserialize(thriftResult, result);
        return thriftResult;
    } catch (TException e) {
        // this should never happen
        throw new InternalException("Couldn't cache jar at HDFS location " + hdfsLocation, e);
    }
}

From source file:org.apache.impala.service.FeSupport.java

License:Apache License

public static TColumnValue EvalExprWithoutRow(Expr expr, TQueryCtx queryCtx) throws InternalException {
    Preconditions.checkState(!expr.contains(SlotRef.class));
    TExprBatch exprBatch = new TExprBatch();
    exprBatch.addToExprs(expr.treeToThrift());
    TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());
    byte[] result;
    try {/*from   w ww.j  a  v  a  2  s.com*/
        result = EvalExprsWithoutRow(serializer.serialize(exprBatch), serializer.serialize(queryCtx));
        Preconditions.checkNotNull(result);
        TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
        TResultRow val = new TResultRow();
        deserializer.deserialize(val, result);
        Preconditions.checkState(val.getColValsSize() == 1);
        return val.getColVals().get(0);
    } catch (TException e) {
        // this should never happen
        throw new InternalException("couldn't execute expr " + expr.toSql(), e);
    }
}