Search in sources :

Example 1 with FieldDecoder

use of com.facebook.presto.decoder.FieldDecoder in project presto by prestodb.

the class KafkaRecordSetProvider method getRecordSet.

@Override
public RecordSet getRecordSet(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorSplit split, List<? extends ColumnHandle> columns) {
    KafkaSplit kafkaSplit = convertSplit(split);
    ImmutableList.Builder<DecoderColumnHandle> handleBuilder = ImmutableList.builder();
    ImmutableMap.Builder<DecoderColumnHandle, FieldDecoder<?>> keyFieldDecoderBuilder = ImmutableMap.builder();
    ImmutableMap.Builder<DecoderColumnHandle, FieldDecoder<?>> messageFieldDecoderBuilder = ImmutableMap.builder();
    RowDecoder keyDecoder = registry.getRowDecoder(kafkaSplit.getKeyDataFormat());
    RowDecoder messageDecoder = registry.getRowDecoder(kafkaSplit.getMessageDataFormat());
    for (ColumnHandle handle : columns) {
        KafkaColumnHandle columnHandle = convertColumnHandle(handle);
        handleBuilder.add(columnHandle);
        if (!columnHandle.isInternal()) {
            if (columnHandle.isKeyDecoder()) {
                FieldDecoder<?> fieldDecoder = registry.getFieldDecoder(kafkaSplit.getKeyDataFormat(), columnHandle.getType().getJavaType(), columnHandle.getDataFormat());
                keyFieldDecoderBuilder.put(columnHandle, fieldDecoder);
            } else {
                FieldDecoder<?> fieldDecoder = registry.getFieldDecoder(kafkaSplit.getMessageDataFormat(), columnHandle.getType().getJavaType(), columnHandle.getDataFormat());
                messageFieldDecoderBuilder.put(columnHandle, fieldDecoder);
            }
        }
    }
    ImmutableList<DecoderColumnHandle> handles = handleBuilder.build();
    ImmutableMap<DecoderColumnHandle, FieldDecoder<?>> keyFieldDecoders = keyFieldDecoderBuilder.build();
    ImmutableMap<DecoderColumnHandle, FieldDecoder<?>> messageFieldDecoders = messageFieldDecoderBuilder.build();
    return new KafkaRecordSet(kafkaSplit, consumerManager, handles, keyDecoder, messageDecoder, keyFieldDecoders, messageFieldDecoders);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) KafkaHandleResolver.convertColumnHandle(com.facebook.presto.kafka.KafkaHandleResolver.convertColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) RowDecoder(com.facebook.presto.decoder.RowDecoder) ImmutableMap(com.google.common.collect.ImmutableMap) FieldDecoder(com.facebook.presto.decoder.FieldDecoder)

Example 2 with FieldDecoder

use of com.facebook.presto.decoder.FieldDecoder in project presto by prestodb.

the class RedisRecordSetProvider method getRecordSet.

@Override
public RecordSet getRecordSet(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorSplit split, List<? extends ColumnHandle> columns) {
    RedisSplit redisSplit = convertSplit(split);
    ImmutableList.Builder<DecoderColumnHandle> handleBuilder = ImmutableList.builder();
    ImmutableMap.Builder<DecoderColumnHandle, FieldDecoder<?>> keyFieldDecoderBuilder = ImmutableMap.builder();
    ImmutableMap.Builder<DecoderColumnHandle, FieldDecoder<?>> valueFieldDecoderBuilder = ImmutableMap.builder();
    RowDecoder keyDecoder = registry.getRowDecoder(redisSplit.getKeyDataFormat());
    RowDecoder valueDecoder = registry.getRowDecoder(redisSplit.getValueDataFormat());
    for (ColumnHandle handle : columns) {
        RedisColumnHandle columnHandle = convertColumnHandle(handle);
        handleBuilder.add(columnHandle);
        if (!columnHandle.isInternal()) {
            if (columnHandle.isKeyDecoder()) {
                FieldDecoder<?> fieldDecoder = registry.getFieldDecoder(redisSplit.getKeyDataFormat(), columnHandle.getType().getJavaType(), columnHandle.getDataFormat());
                keyFieldDecoderBuilder.put(columnHandle, fieldDecoder);
            } else {
                FieldDecoder<?> fieldDecoder = registry.getFieldDecoder(redisSplit.getValueDataFormat(), columnHandle.getType().getJavaType(), columnHandle.getDataFormat());
                valueFieldDecoderBuilder.put(columnHandle, fieldDecoder);
            }
        }
    }
    ImmutableList<DecoderColumnHandle> handles = handleBuilder.build();
    ImmutableMap<DecoderColumnHandle, FieldDecoder<?>> keyFieldDecoders = keyFieldDecoderBuilder.build();
    ImmutableMap<DecoderColumnHandle, FieldDecoder<?>> valueFieldDecoders = valueFieldDecoderBuilder.build();
    return new RedisRecordSet(redisSplit, jedisManager, handles, keyDecoder, valueDecoder, keyFieldDecoders, valueFieldDecoders);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) RedisHandleResolver.convertColumnHandle(com.facebook.presto.redis.RedisHandleResolver.convertColumnHandle) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) RowDecoder(com.facebook.presto.decoder.RowDecoder) ImmutableMap(com.google.common.collect.ImmutableMap) FieldDecoder(com.facebook.presto.decoder.FieldDecoder)

Example 3 with FieldDecoder

use of com.facebook.presto.decoder.FieldDecoder in project presto by prestodb.

the class HashRedisRowDecoder method decodeRow.

@Override
public boolean decodeRow(byte[] data, Map<String, String> dataMap, Set<FieldValueProvider> fieldValueProviders, List<DecoderColumnHandle> columnHandles, Map<DecoderColumnHandle, FieldDecoder<?>> fieldDecoders) {
    if (dataMap == null) {
        return false;
    }
    for (DecoderColumnHandle columnHandle : columnHandles) {
        if (columnHandle.isInternal()) {
            continue;
        }
        String mapping = columnHandle.getMapping();
        checkState(mapping != null, "No mapping for column handle %s!", columnHandle);
        String valueField = dataMap.get(mapping);
        @SuppressWarnings("unchecked") FieldDecoder<String> decoder = (FieldDecoder<String>) fieldDecoders.get(columnHandle);
        if (decoder != null) {
            fieldValueProviders.add(decoder.decode(valueField, columnHandle));
        }
    }
    return false;
}
Also used : DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) FieldDecoder(com.facebook.presto.decoder.FieldDecoder)

Example 4 with FieldDecoder

use of com.facebook.presto.decoder.FieldDecoder in project presto by prestodb.

the class CsvRowDecoder method decodeRow.

@Override
public boolean decodeRow(byte[] data, Map<String, String> dataMap, Set<FieldValueProvider> fieldValueProviders, List<DecoderColumnHandle> columnHandles, Map<DecoderColumnHandle, FieldDecoder<?>> fieldDecoders) {
    String[] fields;
    try {
        // TODO - There is no reason why the row can't have a formatHint and it could be used
        // to set the charset here.
        String line = new String(data, StandardCharsets.UTF_8);
        fields = parser.parseLine(line);
    } catch (Exception e) {
        return true;
    }
    for (DecoderColumnHandle columnHandle : columnHandles) {
        if (columnHandle.isInternal()) {
            continue;
        }
        String mapping = columnHandle.getMapping();
        checkState(mapping != null, "No mapping for column handle %s!", columnHandle);
        int columnIndex = Integer.parseInt(mapping);
        if (columnIndex >= fields.length) {
            continue;
        }
        @SuppressWarnings("unchecked") FieldDecoder<String> decoder = (FieldDecoder<String>) fieldDecoders.get(columnHandle);
        if (decoder != null) {
            fieldValueProviders.add(decoder.decode(fields[columnIndex], columnHandle));
        }
    }
    return false;
}
Also used : DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) FieldDecoder(com.facebook.presto.decoder.FieldDecoder)

Example 5 with FieldDecoder

use of com.facebook.presto.decoder.FieldDecoder in project presto by prestodb.

the class JsonRowDecoder method decodeRow.

@Override
public boolean decodeRow(byte[] data, Map<String, String> dataMap, Set<FieldValueProvider> fieldValueProviders, List<DecoderColumnHandle> columnHandles, Map<DecoderColumnHandle, FieldDecoder<?>> fieldDecoders) {
    JsonNode tree;
    try {
        tree = objectMapper.readTree(data);
    } catch (Exception e) {
        return true;
    }
    for (DecoderColumnHandle columnHandle : columnHandles) {
        if (columnHandle.isInternal()) {
            continue;
        }
        @SuppressWarnings("unchecked") FieldDecoder<JsonNode> decoder = (FieldDecoder<JsonNode>) fieldDecoders.get(columnHandle);
        if (decoder != null) {
            JsonNode node = locateNode(tree, columnHandle);
            fieldValueProviders.add(decoder.decode(node, columnHandle));
        }
    }
    return false;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) FieldDecoder(com.facebook.presto.decoder.FieldDecoder)

Aggregations

DecoderColumnHandle (com.facebook.presto.decoder.DecoderColumnHandle)5 FieldDecoder (com.facebook.presto.decoder.FieldDecoder)5 RowDecoder (com.facebook.presto.decoder.RowDecoder)2 ColumnHandle (com.facebook.presto.spi.ColumnHandle)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 KafkaHandleResolver.convertColumnHandle (com.facebook.presto.kafka.KafkaHandleResolver.convertColumnHandle)1 RedisHandleResolver.convertColumnHandle (com.facebook.presto.redis.RedisHandleResolver.convertColumnHandle)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1