List of usage examples for org.apache.thrift TDeserializer deserialize
public void deserialize(TBase base, String data, String charset) throws TException
From source file:org.apache.hadoop.hive.metastore.messaging.json.JSONMessageFactory.java
License:Apache License
public static Table getTableObj(ObjectNode jsonTree) throws Exception { TDeserializer deSerializer = new TDeserializer(new TJSONProtocol.Factory()); Table tableObj = new Table(); String tableJson = jsonTree.get("tableObjJson").asText(); deSerializer.deserialize(tableObj, tableJson, "UTF-8"); return tableObj; }
From source file:org.apache.hadoop.hive.metastore.messaging.json.JSONMessageFactory.java
License:Apache License
public static List<Partition> getPartitionObjList(ObjectNode jsonTree) throws Exception { TDeserializer deSerializer = new TDeserializer(new TJSONProtocol.Factory()); List<Partition> partitionObjList = new ArrayList<Partition>(); Partition partitionObj = new Partition(); Iterator<JsonNode> jsonArrayIterator = jsonTree.get("partitionListJson").iterator(); while (jsonArrayIterator.hasNext()) { deSerializer.deserialize(partitionObj, jsonArrayIterator.next().asText(), "UTF-8"); partitionObjList.add(partitionObj); }// w ww. jav a 2s .co m return partitionObjList; }
From source file:org.apache.hadoop.hive.metastore.messaging.json.JSONMessageFactory.java
License:Apache License
public static Function getFunctionObj(ObjectNode jsonTree) throws Exception { TDeserializer deSerializer = new TDeserializer(new TJSONProtocol.Factory()); Function funcObj = new Function(); String tableJson = jsonTree.get("functionObjJson").asText(); deSerializer.deserialize(funcObj, tableJson, "UTF-8"); return funcObj; }
From source file:org.apache.hadoop.hive.metastore.messaging.json.JSONMessageFactory.java
License:Apache License
public static Index getIndexObj(ObjectNode jsonTree, String indexObjKey) throws Exception { TDeserializer deSerializer = new TDeserializer(new TJSONProtocol.Factory()); Index indexObj = new Index(); String tableJson = jsonTree.get(indexObjKey).asText(); deSerializer.deserialize(indexObj, tableJson, "UTF-8"); return indexObj; }
From source file:org.apache.hadoop.hive.metastore.messaging.MessageBuilder.java
License:Apache License
public static TBase getTObj(String tSerialized, Class<? extends TBase> objClass) throws Exception { TDeserializer thriftDeSerializer = new TDeserializer(new TJSONProtocol.Factory()); TBase obj = objClass.newInstance();// w w w.j a v a 2s.c om thriftDeSerializer.deserialize(obj, tSerialized, "UTF-8"); return obj; }
From source file:org.apache.hadoop.hive.ql.parse.EximUtil.java
License:Apache License
public static ReadMetaData readMetaData(FileSystem fs, Path metadataPath) throws IOException, SemanticException { FSDataInputStream mdstream = null;//from w w w. j a va 2s . c om try { mdstream = fs.open(metadataPath); byte[] buffer = new byte[1024]; ByteArrayOutputStream sb = new ByteArrayOutputStream(); int read = mdstream.read(buffer); while (read != -1) { sb.write(buffer, 0, read); read = mdstream.read(buffer); } String md = new String(sb.toByteArray(), "UTF-8"); JSONObject jsonContainer = new JSONObject(md); String version = jsonContainer.getString("version"); String fcversion = getJSONStringEntry(jsonContainer, "fcversion"); checkCompatibility(version, fcversion); String tableDesc = getJSONStringEntry(jsonContainer, "table"); Table table = null; List<Partition> partitionsList = null; if (tableDesc != null) { table = new Table(); TDeserializer deserializer = new TDeserializer(new TJSONProtocol.Factory()); deserializer.deserialize(table, tableDesc, "UTF-8"); // TODO : jackson-streaming-iterable-redo this JSONArray jsonPartitions = new JSONArray(jsonContainer.getString("partitions")); partitionsList = new ArrayList<Partition>(jsonPartitions.length()); for (int i = 0; i < jsonPartitions.length(); ++i) { String partDesc = jsonPartitions.getString(i); Partition partition = new Partition(); deserializer.deserialize(partition, partDesc, "UTF-8"); partitionsList.add(partition); } } return new ReadMetaData(table, partitionsList, readReplicationSpec(jsonContainer)); } catch (JSONException e) { throw new SemanticException(ErrorMsg.GENERIC_ERROR.getMsg("Error in serializing metadata"), e); } catch (TException e) { throw new SemanticException(ErrorMsg.GENERIC_ERROR.getMsg("Error in serializing metadata"), e); } finally { if (mdstream != null) { mdstream.close(); } } }
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 .jav a 2 s.c om*/ 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:tech.sirwellington.alchemy.thrift.ThriftObjects.java
License:Apache License
/** * Inflates the prototype object from the supplied JSON. * * @param <T> The type of the Thrift Object * @param prototype The prototype Object to deserialize into * @param json The Simple JSON generated from {@link #toJson(org.apache.thrift.TBase) } * * @return The Deserialized Prototype Object. * * @throws TException/*from w w w . ja v a2 s .c o m*/ */ public static <T extends TBase> T fromJson(@NonNull T prototype, @NonEmpty String json) throws TException { checkThat(prototype).usingMessage("missing prototype").is(notNull()); if (isNullOrEmpty(json)) { LOG.warn("JSON String is empty"); return prototype; } TProtocolFactory protocol = new TJSONProtocol.Factory(); TDeserializer deserializer = new TDeserializer(protocol); deserializer.deserialize(prototype, json, UTF_8.name()); LOG.debug("Prototype TObject inflated to {} from json {}", prototype, json); return prototype; }