Search in sources :

Example 1 with JsonFieldDecoder

use of io.prestosql.decoder.json.JsonFieldDecoder in project pulsar by yahoo.

the class PulsarJsonRowDecoder method decodeRow.

/**
 * decode ByteBuf by {@link org.apache.pulsar.client.api.schema.GenericSchema}.
 * @param byteBuf
 * @return
 */
@Override
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(ByteBuf byteBuf) {
    GenericJsonRecord record = (GenericJsonRecord) genericJsonSchema.decode(byteBuf);
    JsonNode tree = record.getJsonNode();
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = new HashMap<>();
    for (Map.Entry<DecoderColumnHandle, JsonFieldDecoder> entry : fieldDecoders.entrySet()) {
        DecoderColumnHandle columnHandle = entry.getKey();
        JsonFieldDecoder decoder = entry.getValue();
        JsonNode node = locateNode(tree, columnHandle);
        decodedRow.put(columnHandle, decoder.decode(node));
    }
    return Optional.of(decodedRow);
}
Also used : HashMap(java.util.HashMap) FieldValueProvider(io.prestosql.decoder.FieldValueProvider) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonFieldDecoder(io.prestosql.decoder.json.JsonFieldDecoder) GenericJsonRecord(org.apache.pulsar.client.impl.schema.generic.GenericJsonRecord) DecoderColumnHandle(io.prestosql.decoder.DecoderColumnHandle) HashMap(java.util.HashMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Map(java.util.Map)

Example 2 with JsonFieldDecoder

use of io.prestosql.decoder.json.JsonFieldDecoder in project pulsar by apache.

the class PulsarJsonRowDecoder method decodeRow.

/**
 * decode ByteBuf by {@link org.apache.pulsar.client.api.schema.GenericSchema}.
 * @param byteBuf
 * @return
 */
@Override
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(ByteBuf byteBuf) {
    GenericJsonRecord record = (GenericJsonRecord) genericJsonSchema.decode(byteBuf);
    JsonNode tree = record.getJsonNode();
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = new HashMap<>();
    for (Map.Entry<DecoderColumnHandle, JsonFieldDecoder> entry : fieldDecoders.entrySet()) {
        DecoderColumnHandle columnHandle = entry.getKey();
        JsonFieldDecoder decoder = entry.getValue();
        JsonNode node = locateNode(tree, columnHandle);
        decodedRow.put(columnHandle, decoder.decode(node));
    }
    return Optional.of(decodedRow);
}
Also used : HashMap(java.util.HashMap) FieldValueProvider(io.prestosql.decoder.FieldValueProvider) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonFieldDecoder(io.prestosql.decoder.json.JsonFieldDecoder) GenericJsonRecord(org.apache.pulsar.client.impl.schema.generic.GenericJsonRecord) DecoderColumnHandle(io.prestosql.decoder.DecoderColumnHandle) HashMap(java.util.HashMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Map(java.util.Map)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)2 DecoderColumnHandle (io.prestosql.decoder.DecoderColumnHandle)2 FieldValueProvider (io.prestosql.decoder.FieldValueProvider)2 JsonFieldDecoder (io.prestosql.decoder.json.JsonFieldDecoder)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GenericJsonRecord (org.apache.pulsar.client.impl.schema.generic.GenericJsonRecord)2