Example usage for com.google.common.io ByteArrayDataInput readDouble

List of usage examples for com.google.common.io ByteArrayDataInput readDouble

Introduction

In this page you can find the example usage for com.google.common.io ByteArrayDataInput readDouble.

Prototype

@Override
    double readDouble();

Source Link

Usage

From source file:org.apache.druid.indexer.InputRowSerde.java

public static final InputRow fromBytes(final Map<String, IndexSerdeTypeHelper> typeHelperMap, byte[] data,
        AggregatorFactory[] aggs) {/* w w  w  .j av a 2  s . com*/
    try {
        ByteArrayDataInput in = ByteStreams.newDataInput(data);

        //Read timestamp
        long timestamp = in.readLong();

        Map<String, Object> event = Maps.newHashMap();

        //Read dimensions
        List<String> dimensions = Lists.newArrayList();
        int dimNum = WritableUtils.readVInt(in);
        for (int i = 0; i < dimNum; i++) {
            String dimension = readString(in);
            dimensions.add(dimension);

            IndexSerdeTypeHelper typeHelper = typeHelperMap.get(dimension);
            if (typeHelper == null) {
                typeHelper = STRING_HELPER;
            }
            Object dimValues = typeHelper.deserialize(in);
            if (dimValues == null) {
                continue;
            }

            if (typeHelper.getType() == ValueType.STRING) {
                List<String> dimensionValues = (List<String>) dimValues;
                if (dimensionValues.size() == 1) {
                    event.put(dimension, dimensionValues.get(0));
                } else {
                    event.put(dimension, dimensionValues);
                }
            } else {
                event.put(dimension, dimValues);
            }
        }

        //Read metrics
        int metricSize = WritableUtils.readVInt(in);
        for (int i = 0; i < metricSize; i++) {
            String metric = readString(in);
            String type = getType(metric, aggs, i);
            byte metricNullability = in.readByte();
            if (metricNullability == NullHandling.IS_NULL_BYTE) {
                // metric value is null.
                continue;
            }
            if ("float".equals(type)) {
                event.put(metric, in.readFloat());
            } else if ("long".equals(type)) {
                event.put(metric, WritableUtils.readVLong(in));
            } else if ("double".equals(type)) {
                event.put(metric, in.readDouble());
            } else {
                ComplexMetricSerde serde = getComplexMetricSerde(type);
                byte[] value = readBytes(in);
                event.put(metric, serde.fromBytes(value, 0, value.length));
            }
        }

        return new MapBasedInputRow(timestamp, dimensions, event);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}