Java Code Examples for org.apache.kylin.common.util.BytesUtil#writeVInt()

The following examples show how to use org.apache.kylin.common.util.BytesUtil#writeVInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TrimmedCubeCodeSystem.java    From kylin with Apache License 2.0 6 votes vote down vote up
public static void writeDimensionEncoding(DimensionEncoding encoding, ByteBuffer out) {
    try {
        if (encoding == null) {
            BytesUtil.writeVInt(1, out);
        } else {
            BytesUtil.writeVInt(0, out);

            if (encoding instanceof DictionaryDimEnc) {
                encoding = new TrimmedDimEnc(encoding.getLengthOfEncoding());
            }
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(encoding);
            BytesUtil.writeByteArray(baos.toByteArray(), out);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 2
Source File: BigDecimalSerializer.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(BigDecimal value, ByteBuffer out) {
    if (value == null) {
        BytesUtil.writeVInt(0, out);
        BytesUtil.writeVInt(-1, out);
        return;
    }

    if (value.scale() > type.getScale()) {
        if (avoidVerbose++ % 10000 == 0) {
            logger.warn("value's scale has exceeded the " + type.getScale() + ", cut it off, to ensure encoded value do not exceed maxLength " + maxLength + " times:" + (avoidVerbose));
        }
        value = value.setScale(type.getScale(), BigDecimal.ROUND_HALF_EVEN);
    }
    byte[] bytes = value.unscaledValue().toByteArray();
    if (bytes.length + 2 > maxLength) {
        throw new IllegalArgumentException("'" + value + "' exceeds the expected length for type " + type);
    }

    BytesUtil.writeVInt(value.scale(), out);
    BytesUtil.writeVInt(bytes.length, out);
    out.put(bytes);
}
 
Example 3
Source File: TrimmedCubeCodeSystem.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(IGTCodeSystem ivalue, ByteBuffer out) {
    TrimmedCubeCodeSystem value = (TrimmedCubeCodeSystem) ivalue;
    BytesUtil.writeVInt(value.dependentMetricsMap.size(), out);
    for (Map.Entry<Integer, Integer> x : value.dependentMetricsMap.entrySet()) {
        BytesUtil.writeVInt(x.getKey(), out);
        BytesUtil.writeVInt(x.getValue(), out);
    }

    BytesUtil.writeVInt(value.dimEncs.length, out);
    for (int i = 0; i < value.dimEncs.length; i++) {
        DimensionEncoding enc = value.dimEncs[i];

        writeDimensionEncoding(enc, out);
    }
}
 
Example 4
Source File: CaseTupleExpression.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(IFilterCodeSystem<?> cs, ByteBuffer buffer) {
    BytesUtil.writeVInt(whenList.size(), buffer);
    for (Pair<TupleFilter, TupleExpression> whenEntry : whenList) {
        byte[] whenBytes = TupleFilterSerializer.serialize(whenEntry.getFirst(), cs);
        BytesUtil.writeByteArray(whenBytes, buffer);

        byte[] thenBytes = TupleExpressionSerializer.serialize(whenEntry.getSecond(), cs);
        BytesUtil.writeByteArray(thenBytes, buffer);
    }
    if (elseExpr != null) {
        BytesUtil.writeVInt(1, buffer);
        byte[] elseBytes = TupleExpressionSerializer.serialize(elseExpr, cs);
        BytesUtil.writeByteArray(elseBytes, buffer);
    } else {
        BytesUtil.writeVInt(-1, buffer);
    }
}
 
Example 5
Source File: CubeHBaseEndpointRPC.java    From kylin with Apache License 2.0 6 votes vote down vote up
public static ByteString serializeRawScans(List<RawScan> rawScans) {
    ByteString rawScanByteString;
    int rawScanBufferSize = BytesSerializer.SERIALIZE_BUFFER_SIZE;
    while (true) {
        try {
            ByteBuffer rawScanBuffer = ByteBuffer.allocate(rawScanBufferSize);
            BytesUtil.writeVInt(rawScans.size(), rawScanBuffer);
            for (RawScan rs : rawScans) {
                RawScan.serializer.serialize(rs, rawScanBuffer);
            }
            rawScanBuffer.flip();
            rawScanByteString = HBaseZeroCopyByteString.wrap(rawScanBuffer.array(), rawScanBuffer.position(),
                    rawScanBuffer.limit());
            break;
        } catch (BufferOverflowException boe) {
            logger.info("Buffer size {} cannot hold the raw scans, resizing to 4 times", rawScanBufferSize);
            rawScanBufferSize *= 4;
        }
    }
    return rawScanByteString;
}
 
Example 6
Source File: TupleFilterSerializer.java    From kylin with Apache License 2.0 5 votes vote down vote up
private static void serializeFilter(int flag, TupleFilter filter, ByteBuffer buffer, IFilterCodeSystem<?> cs) {
    if (flag < 0) {
        BytesUtil.writeVInt(-1, buffer);
    } else {
        int opVal = filter.getOperator().getValue();
        BytesUtil.writeVInt(opVal, buffer);
        filter.serialize(cs, buffer);
        BytesUtil.writeVInt(flag, buffer);
    }
}
 
Example 7
Source File: ObserverAggregators.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ObserverAggregators value, ByteBuffer out) {
    BytesUtil.writeVInt(value.nHCols, out);
    for (int i = 0; i < value.nHCols; i++) {
        HCol col = value.hcols[i];
        BytesUtil.writeByteArray(col.family, out);
        BytesUtil.writeByteArray(col.qualifier, out);
        BytesUtil.writeAsciiStringArray(col.funcNames, out);
        BytesUtil.writeAsciiStringArray(col.dataTypes, out);
    }
}
 
Example 8
Source File: TupleFilterSerializer.java    From Kylin with Apache License 2.0 5 votes vote down vote up
private static void serializeFilter(int flag, TupleFilter filter, Decorator decorator, ByteBuffer buffer) {
    if (flag < 0) {
        BytesUtil.writeVInt(-1, buffer);
    } else {
        byte[] bytes = filter.serialize();
        int opVal = filter.getOperator().getValue();
        BytesUtil.writeVInt(opVal, buffer);
        BytesUtil.writeByteArray(bytes, buffer);
        BytesUtil.writeVInt(flag, buffer);
    }
}
 
Example 9
Source File: CoprocessorRowType.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(CoprocessorRowType o, ByteBuffer out) {
    int n = o.columns.length;
    BytesUtil.writeVInt(o.columns.length, out);
    BytesUtil.writeVInt(o.bodyOffset, out);
    for (int i = 0; i < n; i++) {
        BytesUtil.writeAsciiString(o.columns[i].getTable(), out);
        BytesUtil.writeAsciiString(o.columns[i].getName(), out);
        BytesUtil.writeAsciiString(o.columns[i].getDatatype(), out);
        BytesUtil.writeVInt(o.columnSizes[i], out);
    }
}
 
Example 10
Source File: DataType.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(DataType value, ByteBuffer out) {
    BytesUtil.writeUTFString(value.name, out);
    BytesUtil.writeVInt(value.precision, out);
    BytesUtil.writeVInt(value.scale, out);

}
 
Example 11
Source File: HyperLogLogPlusCounter.java    From Kylin with Apache License 2.0 5 votes vote down vote up
public void writeRegisters(final ByteBuffer out) throws IOException {

        final int indexLen = getRegisterIndexSize();
        int size = size();

        // decide output scheme -- map (3*size bytes) or array (2^p bytes)
        byte scheme;
        if ((indexLen + 1) * size < m)
            scheme = 0; // map
        else
            scheme = 1; // array
        out.put(scheme);

        if (scheme == 0) { // map scheme
            BytesUtil.writeVInt(size, out);
            for (int i = 0; i < m; i++) {
                if (registers[i] > 0) {
                    BytesUtil.writeUnsigned(i, indexLen, out);
                    out.put(registers[i]);
                }
            }
        } else { // array scheme
            for (int i = 0; i < m; i++) {
                out.put(registers[i]);
            }
        }
    }
 
Example 12
Source File: CoprocessorRowType.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(CoprocessorRowType o, ByteBuffer out) {
    int n = o.columns.length;
    BytesUtil.writeVInt(o.columns.length, out);
    for (int i = 0; i < n; i++) {
        BytesUtil.writeAsciiString(o.columns[i].getTable(), out);
        BytesUtil.writeAsciiString(o.columns[i].getName(), out);
        BytesUtil.writeVInt(o.columnSizes[i], out);
    }
}
 
Example 13
Source File: RawSerializer.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(List<ByteArray> values, ByteBuffer out) {
    if (values == null) {
        BytesUtil.writeVInt(0, out);
    } else {
        BytesUtil.writeVInt(values.size(), out);
        for (ByteArray array : values) {
            if (!out.hasRemaining() || out.remaining() < array.length()) {
                throw new RuntimeException("BufferOverflow! Please use one higher cardinality column for dimension column when build RAW cube!");
            }
            BytesUtil.writeByteArray(BytesUtil.subarray(array.array(), array.offset(), array.offset() + array.length()), out);
        }
    }
}
 
Example 14
Source File: BigDecimalSerializer.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(BigDecimal value, ByteBuffer out) {
    byte[] bytes = value.unscaledValue().toByteArray();

    BytesUtil.writeVInt(value.scale(), out);
    BytesUtil.writeVInt(bytes.length, out);
    out.put(bytes);
}
 
Example 15
Source File: TupleFilterSerializer.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private static void serializeFilter(int flag, TupleFilter filter, ByteBuffer buffer, IFilterCodeSystem<?> cs) {
    if (flag < 0) {
        BytesUtil.writeVInt(-1, buffer);
    } else {
        int opVal = filter.getOperator().getValue();
        BytesUtil.writeVInt(opVal, buffer);
        filter.serialize(cs, buffer);
        BytesUtil.writeVInt(flag, buffer);
    }
}
 
Example 16
Source File: EndpointAggregators.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(EndpointAggregators value, ByteBuffer out) {
    BytesUtil.writeAsciiStringArray(value.funcNames, out);
    BytesUtil.writeAsciiStringArray(value.dataTypes, out);

    BytesUtil.writeVInt(value.metricInfos.length, out);
    for (int i = 0; i < value.metricInfos.length; ++i) {
        MetricInfo metricInfo = value.metricInfos[i];
        BytesUtil.writeAsciiString(metricInfo.type.toString(), out);
        BytesUtil.writeVInt(metricInfo.refIndex, out);
        BytesUtil.writeVInt(metricInfo.precision, out);
    }

    BytesUtil.writeByteArray(TableRecordInfoDigest.serialize(value.tableRecordInfoDigest), out);
}
 
Example 17
Source File: GTTwoLayerAggregateParam.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(GTTwoLayerAggregateParam value, ByteBuffer out) {
    if (!value.ifEnabled()) {
        BytesUtil.writeVInt(0, out);
        return;
    }
    BytesUtil.writeVInt(1, out);
    ImmutableBitSet.serializer.serialize(value.vanishDimMask, out);
    ImmutableBitSet.serializer.serialize(value.outsideLayerMetrics, out);
    BytesUtil.writeAsciiStringArray(value.outsideLayerMetricsFuncs, out);
    BytesUtil.writeIntArray(value.insideLayerMetrics, out);
    BytesUtil.writeAsciiStringArray(value.insideLayerMetricsFuncs, out);
}
 
Example 18
Source File: ConstantTupleFilter.java    From kylin with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void serialize(IFilterCodeSystem cs, ByteBuffer buffer) {
    int size = this.constantValues.size();
    BytesUtil.writeVInt(size, buffer);
    for (Object val : this.constantValues) {
        cs.serialize(val, buffer);
    }
}
 
Example 19
Source File: RawSerializer.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(List<ByteArray> values, ByteBuffer out) {
    if (values == null) {
        BytesUtil.writeVInt(0, out);
    } else {
        BytesUtil.writeVInt(values.size(), out);
        for (ByteArray array : values) {
            if (!out.hasRemaining() || out.remaining() < array.length()) {
                throw new RuntimeException("BufferOverflow! Please use one higher cardinality column for dimension column when build RAW cube!");
            }
            BytesUtil.writeByteArray(BytesUtil.subarray(array.array(), array.offset(), array.offset() + array.length()), out);
        }
    }
}
 
Example 20
Source File: CompareTupleFilter.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] serialize() {
    ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
    int size = this.dynamicVariables.size();
    BytesUtil.writeVInt(size, buffer);
    for (Map.Entry<String, String> entry : this.dynamicVariables.entrySet()) {
        BytesUtil.writeUTFString(entry.getKey(), buffer);
        BytesUtil.writeUTFString(entry.getValue(), buffer);
    }
    BytesUtil.writeAsciiString(nullString, buffer);
    byte[] result = new byte[buffer.position()];
    System.arraycopy(buffer.array(), 0, result, 0, buffer.position());
    return result;
}