List of usage examples for org.apache.thrift TDeserializer TDeserializer
public TDeserializer(TProtocolFactory protocolFactory)
From source file:org.apache.hive.hcatalog.api.MetadataJSONSerializer.java
License:Apache License
@Override public HCatTable deserializeTable(String hcatTableStringRep) throws HCatException { try {/*from w ww .j a va 2 s. c o m*/ Table table = new Table(); new TDeserializer(new TJSONProtocol.Factory()).deserialize(table, hcatTableStringRep, "UTF-8"); return new HCatTable(table); } catch (TException exception) { if (LOG.isDebugEnabled()) LOG.debug("Could not de-serialize from: " + hcatTableStringRep); throw new HCatException("Could not de-serialize HCatTable.", exception); } }
From source file:org.apache.hive.hcatalog.api.MetadataJSONSerializer.java
License:Apache License
@Override public HCatPartition deserializePartition(String hcatPartitionStringRep) throws HCatException { try {//from w w w . j a va2s . c om Partition partition = new Partition(); new TDeserializer(new TJSONProtocol.Factory()).deserialize(partition, hcatPartitionStringRep, "UTF-8"); return new HCatPartition(null, partition); } catch (TException exception) { if (LOG.isDebugEnabled()) LOG.debug("Could not de-serialize partition from: " + hcatPartitionStringRep); throw new HCatException("Could not de-serialize HCatPartition.", exception); } }
From source file:org.apache.hive.hcatalog.api.MetadataJSONSerializer.java
License:Apache License
@Override public HCatPartitionSpec deserializePartitionSpec(List<String> hcatPartitionSpecStrings) throws HCatException { try {/*from w ww .ja v a 2 s.c o m*/ List<PartitionSpec> partitionSpecList = new ArrayList<PartitionSpec>(); TDeserializer deserializer = new TDeserializer(new TJSONProtocol.Factory()); for (String stringRep : hcatPartitionSpecStrings) { PartitionSpec partSpec = new PartitionSpec(); deserializer.deserialize(partSpec, stringRep, "UTF-8"); partitionSpecList.add(partSpec); } return new HCatPartitionSpec(null, PartitionSpecProxy.Factory.get(partitionSpecList)); } catch (TException deserializationException) { throw new HCatException("Failed to deserialize!", deserializationException); } }
From source file:org.apache.htrace.zipkin.ITZipkinReceiver.java
License:Apache License
@Test public void testKafkaTransport() throws Exception { String topic = "zipkin"; // Kafka setup EmbeddedZookeeper zkServer = new EmbeddedZookeeper(TestZKUtils.zookeeperConnect()); ZkClient zkClient = new ZkClient(zkServer.connectString(), 30000, 30000, ZKStringSerializer$.MODULE$); Properties props = TestUtils.createBrokerConfig(0, TestUtils.choosePort(), false); KafkaConfig config = new KafkaConfig(props); KafkaServer kafkaServer = TestUtils.createServer(config, new MockTime()); Buffer<KafkaServer> servers = JavaConversions.asScalaBuffer(Collections.singletonList(kafkaServer)); TestUtils.createTopic(zkClient, topic, 1, 1, servers, new Properties()); zkClient.close();/*from w ww. ja va 2s .c o m*/ TestUtils.waitUntilMetadataIsPropagated(servers, topic, 0, 5000); // HTrace HTraceConfiguration hTraceConfiguration = HTraceConfiguration.fromKeyValuePairs("sampler.classes", "AlwaysSampler", "span.receiver.classes", ZipkinSpanReceiver.class.getName(), "zipkin.kafka.metadata.broker.list", config.advertisedHostName() + ":" + config.advertisedPort(), "zipkin.kafka.topic", topic, ZipkinSpanReceiver.TRANSPORT_CLASS_KEY, KafkaTransport.class.getName()); final Tracer tracer = new Tracer.Builder("test-tracer").tracerPool(new TracerPool("test-tracer-pool")) .conf(hTraceConfiguration).build(); String scopeName = "test-kafka-transport-scope"; TraceScope traceScope = tracer.newScope(scopeName); traceScope.close(); tracer.close(); // Kafka consumer Properties consumerProps = new Properties(); consumerProps.put("zookeeper.connect", props.getProperty("zookeeper.connect")); consumerProps.put(ConsumerConfig.GROUP_ID_CONFIG, "testing.group"); consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "smallest"); ConsumerConnector connector = kafka.consumer.Consumer .createJavaConsumerConnector(new kafka.consumer.ConsumerConfig(consumerProps)); Map<String, Integer> topicCountMap = new HashMap<>(); topicCountMap.put(topic, 1); Map<String, List<KafkaStream<byte[], byte[]>>> streams = connector.createMessageStreams(topicCountMap); ConsumerIterator<byte[], byte[]> it = streams.get(topic).get(0).iterator(); // Test Assert.assertTrue("We should have one message in Kafka", it.hasNext()); Span span = new Span(); new TDeserializer(new TBinaryProtocol.Factory()).deserialize(span, it.next().message()); Assert.assertEquals("The span name should match our scope description", span.getName(), scopeName); kafkaServer.shutdown(); }
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. *//*from w ww . j a v a2 s . co 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. *//*from ww w . j av a 2 s . c om*/ 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 {/*www . j a v a 2s .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); } }
From source file:org.apache.impala.service.FeSupport.java
License:Apache License
public static TSymbolLookupResult LookupSymbol(TSymbolLookupParams params) throws InternalException { TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory()); try {// w w w . j ava 2s. c om byte[] resultBytes = LookupSymbol(serializer.serialize(params)); Preconditions.checkNotNull(resultBytes); TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory()); TSymbolLookupResult result = new TSymbolLookupResult(); deserializer.deserialize(result, resultBytes); return result; } catch (TException e) { // this should never happen throw new InternalException("couldn't perform symbol lookup.", e); } }
From source file:org.apache.impala.service.FeSupport.java
License:Apache License
/** * Evaluate a batch of predicates in the BE. The results are stored in a * TResultRow object, where each TColumnValue in it stores the result of * a predicate evaluation.//w w w . j av a2s . c om * * TODO: This function is currently used for improving the performance of * partition pruning (see IMPALA-887), hence it only supports boolean * exprs. In the future, we can extend it to support arbitrary exprs without * SlotRefs. */ public static TResultRow EvalPredicateBatch(ArrayList<Expr> exprs, TQueryCtx queryCtx) throws InternalException { TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory()); TExprBatch exprBatch = new TExprBatch(); for (Expr expr : exprs) { // Make sure we only process boolean exprs. Preconditions.checkState(expr.getType().isBoolean()); Preconditions.checkState(!expr.contains(SlotRef.class)); exprBatch.addToExprs(expr.treeToThrift()); } byte[] result; try { 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); return val; } catch (TException e) { // this should never happen throw new InternalException("couldn't execute a batch of exprs.", e); } }
From source file:org.apache.impala.service.FeSupport.java
License:Apache License
public static TStatus PrioritizeLoad(Set<TableName> tableNames) throws InternalException { Preconditions.checkNotNull(tableNames); List<TCatalogObject> objectDescs = new ArrayList<TCatalogObject>(tableNames.size()); for (TableName tableName : tableNames) { TCatalogObject catalogObject = new TCatalogObject(); catalogObject.setType(TCatalogObjectType.TABLE); catalogObject.setTable(new TTable(tableName.getDb(), tableName.getTbl())); objectDescs.add(catalogObject);// w ww .j a va 2 s .co m } TPrioritizeLoadRequest request = new TPrioritizeLoadRequest(); request.setHeader(new TCatalogServiceRequestHeader()); request.setObject_descs(objectDescs); TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory()); try { byte[] result = PrioritizeLoad(serializer.serialize(request)); Preconditions.checkNotNull(result); TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory()); TPrioritizeLoadResponse response = new TPrioritizeLoadResponse(); deserializer.deserialize(response, result); return response.getStatus(); } catch (TException e) { // this should never happen throw new InternalException("Error processing request: " + e.getMessage(), e); } }