TSerializer serializer = new TSerializer(new TJSONProtocol.Factory()); try { jgen.writeStringField("table", serializer.toString(tableHandle.getTTable(), "UTF-8"));
@Override public String serializeTable(HCatTable hcatTable) throws HCatException { try { return new TSerializer(new TJSONProtocol.Factory()) .toString(hcatTable.toHiveTable(), "UTF-8"); } catch (TException exception) { throw new HCatException("Could not serialize HCatTable: " + hcatTable, exception); } }
@Override public String serializeTable(HCatTable hcatTable) throws HCatException { try { return new TSerializer(new TJSONProtocol.Factory()) .toString(hcatTable.toHiveTable(), "UTF-8"); } catch (TException exception) { throw new HCatException("Could not serialize HCatTable: " + hcatTable, exception); } }
public class CalculatorServlet extends TServlet { public CalculatorServlet() { //'Calculator' is the generated class from thrift, //'CalculatorHandler' is the implement class for thrift rpc super(new Calculator.Processor( new CalculatorHandler()), new TJSONProtocol.Factory()); } }
/** Deserialize a JSON-encoded thrift object */ public static <T extends TBase> T deserializeJson(T dest, String thriftJson) throws TException { // Tried having a static final deserializer, but it doesn't seem to be thread safe new TDeserializer(new TJSONProtocol.Factory()).deserialize(dest, thriftJson, THRIFT_CHARSET); return dest; } }
@Override public String serializeTable(HCatTable hcatTable) throws HCatException { try { return new TSerializer(new TJSONProtocol.Factory()) .toString(hcatTable.toHiveTable(), "UTF-8"); } catch (TException exception) { throw new HCatException("Could not serialize HCatTable: " + hcatTable, exception); } }
/** Deserialize a JSON-encoded thrift object */ public static <T extends TBase> T deserializeJson(T dest, String thriftJson) throws TException { // Tried having a static final deserializer, but it doesn't seem to be thread safe new TDeserializer(new TJSONProtocol.Factory()).deserialize(dest, thriftJson, THRIFT_CHARSET); return dest; } }
@Test public void testOneOfEverythingField() throws Exception { OneOfEverything one = createOneOfEverything(); testRoundTripSerialize(one, new TCompactProtocol.Factory()); testRoundTripSerialize(one, new TJSONProtocol.Factory()); }
/** Serialize a JSON-encoded thrift object */ public static <T extends TBase> String serializeJson(T obj) throws TException { // Tried having a static final serializer, but it doesn't seem to be thread safe return new TSerializer(new TJSONProtocol.Factory()).toString(obj, THRIFT_CHARSET); }
@Override public String serializePartition(HCatPartition hcatPartition) throws HCatException { try { return new TSerializer(new TJSONProtocol.Factory()) .toString(hcatPartition.toHivePartition(), "UTF-8"); } catch (TException exception) { throw new HCatException("Could not serialize HCatPartition: " + hcatPartition, exception); } }
public static TBase getTObj(String tSerialized, Class<? extends TBase> objClass) throws Exception{ TDeserializer thriftDeSerializer = new TDeserializer(new TJSONProtocol.Factory()); TBase obj = objClass.newInstance(); thriftDeSerializer.deserialize(obj, tSerialized, "UTF-8"); return obj; }
@Test public void testOneOfEverythingFieldEmpty() throws Exception { OneOfEverything one = new OneOfEverything(); testRoundTripSerialize(one, new TCompactProtocol.Factory()); testRoundTripSerialize(one, new TJSONProtocol.Factory()); }
@Override public String serializePartition(HCatPartition hcatPartition) throws HCatException { try { return new TSerializer(new TJSONProtocol.Factory()) .toString(hcatPartition.toHivePartition(), "UTF-8"); } catch (TException exception) { throw new HCatException("Could not serialize HCatPartition: " + hcatPartition, exception); } }
return new TJSONProtocol.Factory();
TDeserializer deserializer = new TDeserializer(new TJSONProtocol.Factory());
@Override public void writeTo(JsonWriter writer, ReplicationSpec additionalPropertiesProvider) throws SemanticException, IOException { TSerializer serializer = new TSerializer(new TJSONProtocol.Factory()); List<ResourceUri> resourceUris = new ArrayList<>(); for (ResourceUri uri : function.getResourceUris()) {
public static void createDbExportDump( FileSystem fs, Path metadataPath, Database dbObj, ReplicationSpec replicationSpec) throws IOException, SemanticException { // WARNING NOTE : at this point, createDbExportDump lives only in a world where ReplicationSpec is in replication scope // If we later make this work for non-repl cases, analysis of this logic might become necessary. Also, this is using // Replv2 semantics, i.e. with listFiles laziness (no copy at export time) OutputStream out = fs.create(metadataPath); JsonGenerator jgen = (new JsonFactory()).createJsonGenerator(out); jgen.writeStartObject(); jgen.writeStringField("version",METADATA_FORMAT_VERSION); dbObj.putToParameters(ReplicationSpec.KEY.CURR_STATE_ID.toString(), replicationSpec.getCurrentReplicationState()); if (METADATA_FORMAT_FORWARD_COMPATIBLE_VERSION != null) { jgen.writeStringField("fcversion",METADATA_FORMAT_FORWARD_COMPATIBLE_VERSION); } TSerializer serializer = new TSerializer(new TJSONProtocol.Factory()); try { jgen.writeStringField("db", serializer.toString(dbObj, "UTF-8")); } catch (TException e) { throw new SemanticException( ErrorMsg.ERROR_SERIALIZE_METASTORE .getMsg(), e); } jgen.writeEndObject(); jgen.close(); // JsonGenerator owns the OutputStream, so it closes it when we call close. }
@Override public void writeTo(JsonWriter writer, ReplicationSpec additionalPropertiesProvider) throws SemanticException, IOException { TSerializer serializer = new TSerializer(new TJSONProtocol.Factory()); try { // Remove all the entries from the parameters which are added by repl tasks internally. Map<String, String> parameters = partition.getParameters(); if (parameters != null) { parameters.entrySet() .removeIf(e -> e.getKey().equals(ReplUtils.REPL_CHECKPOINT_KEY)); } if (additionalPropertiesProvider.isInReplicationScope()) { // Current replication state must be set on the Partition object only for bootstrap dump. // Event replication State will be null in case of bootstrap dump. if (additionalPropertiesProvider.getReplSpecType() != ReplicationSpec.Type.INCREMENTAL_DUMP) { partition.putToParameters( ReplicationSpec.KEY.CURR_STATE_ID.toString(), additionalPropertiesProvider.getCurrentReplicationState()); } } writer.jsonGenerator.writeString(serializer.toString(partition, UTF_8)); writer.jsonGenerator.flush(); } catch (TException e) { throw new SemanticException(ErrorMsg.ERROR_SERIALIZE_METASTORE.getMsg(), e); } }
@Override public void writeTo(JsonWriter writer, ReplicationSpec additionalPropertiesProvider) throws SemanticException, IOException { if (!Utils.shouldReplicate(additionalPropertiesProvider, tableHandle, hiveConf)) { return; } Table tTable = updatePropertiesInTable( tableHandle.getTTable(), additionalPropertiesProvider ); try { TSerializer serializer = new TSerializer(new TJSONProtocol.Factory()); writer.jsonGenerator .writeStringField(FIELD_NAME, serializer.toString(tTable, UTF_8)); writer.jsonGenerator.writeFieldName(PartitionSerializer.FIELD_NAME); writePartitions(writer, additionalPropertiesProvider); } catch (TException e) { throw new SemanticException(ErrorMsg.ERROR_SERIALIZE_METASTORE.getMsg(), e); } }
@Override public HCatPartitionSpec deserializePartitionSpec(List<String> hcatPartitionSpecStrings) throws HCatException { try { 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); } } }