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

The following examples show how to use org.apache.kylin.common.util.BytesUtil#writeUTFString() . 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: 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;
}
 
Example 2
Source File: CompareTupleFilter.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.dynamicVariables.size();
    BytesUtil.writeVInt(size, buffer);
    for (Map.Entry<String, Object> entry : this.dynamicVariables.entrySet()) {
        BytesUtil.writeUTFString(entry.getKey(), buffer);
        cs.serialize(entry.getValue(), buffer);
    }
}
 
Example 3
Source File: MassInTupleFilter.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) {
    BytesUtil.writeUTFString(filterTableName, buffer);
    BytesUtil.writeUTFString(filterTableResourceIdentifier, buffer);
    BytesUtil.writeUTFString(filterTableType.toString(), buffer);
    BytesUtil.writeUTFString(String.valueOf(reverse), buffer);
}
 
Example 4
Source File: ColumnTupleExpression.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(IFilterCodeSystem<?> cs, ByteBuffer buffer) {
    TableRef tableRef = columnRef.getTableRef();

    if (tableRef == null) {
        // un-qualified column
        String table = columnRef.getTable();
        BytesUtil.writeUTFString(table, buffer);

        String columnId = columnRef.getColumnDesc().getId();
        BytesUtil.writeUTFString(columnId, buffer);

        String columnName = columnRef.getName();
        BytesUtil.writeUTFString(columnName, buffer);

        String dataType = columnRef.getDatatype();
        BytesUtil.writeUTFString(dataType, buffer);
    } else {
        // qualified column (from model)
        BytesUtil.writeUTFString(_QUALIFIED_, buffer);

        String model = tableRef.getModel().getName();
        BytesUtil.writeUTFString(model, buffer);

        String alias = tableRef.getAlias();
        BytesUtil.writeUTFString(alias, buffer);

        String col = columnRef.getName();
        BytesUtil.writeUTFString(col, buffer);
    }
}
 
Example 5
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 6
Source File: StringSerializer.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(String value, ByteBuffer out) {
    int start = out.position();

    BytesUtil.writeUTFString(value, out);

    if (out.position() - start > maxLength)
        throw new IllegalArgumentException("'" + value + "' exceeds the expected length for type " + type);
}
 
Example 7
Source File: RecordsSerializer.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void serializeRecord(Record record, ByteBuffer out) {
    String[] dimValues = record.getDimensions();
    Object[] metricValues = record.getMetrics();
    for (int i = 0; i < dimValues.length; i++) {
        BytesUtil.writeUTFString(dimValues[i], out);
    }
    for (int i = 0; i < metricValues.length; i++) {
        metricsSerializers[i].serialize(metricValues[i], out);
    }
}
 
Example 8
Source File: ConstantTupleFilter.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.constantValues.size();
    BytesUtil.writeVInt(size, buffer);
    for (String val : this.constantValues) {
        BytesUtil.writeUTFString(val, buffer);
    }
    byte[] result = new byte[buffer.position()];
    System.arraycopy(buffer.array(), 0, result, 0, buffer.position());
    return result;
}
 
Example 9
Source File: CubeHBaseEndpointRPC.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private String getScanRequestString(GTScanRequest scanRequest) {
    int scanRequestBufferSize = BytesSerializer.SERIALIZE_BUFFER_SIZE;
    while (true) {
        try {
            ByteBuffer out = ByteBuffer.allocate(scanRequestBufferSize);
            GTInfo.serializer.serialize(scanRequest.getInfo(), out);
            BytesUtil.writeVInt(scanRequest.getGTScanRanges().size(), out);
            for (GTScanRange range : scanRequest.getGTScanRanges()) {
                serializeGTRecord(range.pkStart, out);
                serializeGTRecord(range.pkEnd, out);
                BytesUtil.writeVInt(range.fuzzyKeys.size(), out);
                for (GTRecord f : range.fuzzyKeys) {
                    serializeGTRecord(f, out);
                }
            }
            ImmutableBitSet.serializer.serialize(scanRequest.getColumns(), out);
            BytesUtil.writeByteArray(
                    GTUtil.serializeGTFilter(scanRequest.getFilterPushDown(), scanRequest.getInfo()), out);
            ImmutableBitSet.serializer.serialize(scanRequest.getAggrGroupBy(), out);
            ImmutableBitSet.serializer.serialize(scanRequest.getAggrMetrics(), out);
            BytesUtil.writeAsciiStringArray(scanRequest.getAggrMetricsFuncs(), out);
            BytesUtil.writeVInt(scanRequest.isAllowStorageAggregation() ? 1 : 0, out);
            BytesUtil.writeUTFString(scanRequest.getStorageLimitLevel().name(), out);
            BytesUtil.writeVInt(scanRequest.getStorageScanRowNumThreshold(), out);
            BytesUtil.writeVInt(scanRequest.getStoragePushDownLimit(), out);
            BytesUtil.writeUTFString(scanRequest.getStorageBehavior(), out);
            BytesUtil.writeBooleanArray(new boolean[]{storageContext.isExactAggregation()}, out);
            out.flip();
            return Bytes.toStringBinary(out.array(), out.position(), out.limit());
        } catch (BufferOverflowException boe) {
            logger.info("Buffer size {} cannot hold the scan request, resizing to 4 times", scanRequestBufferSize);
            scanRequestBufferSize *= 4;
        }
    }
}
 
Example 10
Source File: DynamicTupleFilter.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] serialize() {
    ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
    BytesUtil.writeUTFString(variableName, buffer);
    byte[] result = new byte[buffer.position()];
    System.arraycopy(buffer.array(), 0, result, 0, buffer.position());
    return result;
}
 
Example 11
Source File: ColumnTupleExpression.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(IFilterCodeSystem<?> cs, ByteBuffer buffer) {
    TableRef tableRef = columnRef.getTableRef();

    if (tableRef == null) {
        // un-qualified column
        String table = columnRef.getTable();
        BytesUtil.writeUTFString(table, buffer);

        String columnId = columnRef.getColumnDesc().getId();
        BytesUtil.writeUTFString(columnId, buffer);

        String columnName = columnRef.getName();
        BytesUtil.writeUTFString(columnName, buffer);

        String dataType = columnRef.getDatatype();
        BytesUtil.writeUTFString(dataType, buffer);
    } else {
        // qualified column (from model)
        BytesUtil.writeUTFString(_QUALIFIED_, buffer);

        String model = tableRef.getModel().getName();
        BytesUtil.writeUTFString(model, buffer);

        String alias = tableRef.getAlias();
        BytesUtil.writeUTFString(alias, buffer);

        String col = columnRef.getName();
        BytesUtil.writeUTFString(col, buffer);
    }
}
 
Example 12
Source File: StringSerializer.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(String value, ByteBuffer out) {
    int start = out.position();

    BytesUtil.writeUTFString(value, out);

    if (out.position() - start > maxLength)
        throw new IllegalArgumentException("'" + value + "' exceeds the expected length for type " + type);
}
 
Example 13
Source File: BuiltInFunctionTupleFilter.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(IFilterCodeSystem<?> cs, ByteBuffer buffer) {
    BytesUtil.writeUTFString(name, buffer);
    buffer.put((byte) (isReversed ? 1 : 0));
}
 
Example 14
Source File: GTScanRequest.java    From kylin with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(GTScanRequest value, ByteBuffer out) {
    final int serialLevel = KylinConfig.getInstanceFromEnv().getGTScanRequestSerializationLevel();

    GTInfo.serializer.serialize(value.info, out);

    BytesUtil.writeVInt(value.ranges.size(), out);
    for (GTScanRange range : value.ranges) {
        serializeGTRecord(range.pkStart, out);
        serializeGTRecord(range.pkEnd, out);
        BytesUtil.writeVInt(range.fuzzyKeys.size(), out);
        for (GTRecord f : range.fuzzyKeys) {
            serializeGTRecord(f, out);
        }
    }

    ImmutableBitSet.serializer.serialize(value.columns, out);
    BytesUtil.writeByteArray(GTUtil.serializeGTFilter(value.filterPushDown, value.info), out);

    if (serialLevel >= SERIAL_1_HAVING_FILTER) {
        BytesUtil.writeByteArray(
                TupleFilterSerializer.serialize(value.havingFilterPushDown, StringCodeSystem.INSTANCE), out);
    }

    ImmutableBitSet.serializer.serialize(value.aggrGroupBy, out);
    ImmutableBitSet.serializer.serialize(value.aggrMetrics, out);
    BytesUtil.writeAsciiStringArray(value.aggrMetricsFuncs, out);
    BytesUtil.writeVInt(value.allowStorageAggregation ? 1 : 0, out);
    out.putDouble(value.aggCacheMemThreshold);
    BytesUtil.writeUTFString(value.getStorageLimitLevel().name(), out);
    BytesUtil.writeVInt(value.storageScanRowNumThreshold, out);
    BytesUtil.writeVInt(value.storagePushDownLimit, out);
    BytesUtil.writeVLong(value.startTime, out);
    BytesUtil.writeVLong(value.timeout, out);
    BytesUtil.writeUTFString(value.storageBehavior, out);

    // for dynamic related info
    ImmutableBitSet.serializer.serialize(value.dynamicCols, out);

    BytesUtil.writeVInt(value.tupleExpressionMap.size(), out);
    for (int c : value.tupleExpressionMap.keySet()) {
        TupleExpression tupleExpr = value.tupleExpressionMap.get(c);
        BytesUtil.writeVInt(c, out);
        BytesUtil.writeByteArray(TupleExpressionSerializer.serialize(tupleExpr,
                GTUtil.wrap(value.info.codeSystem.getComparator())), out);
    }
    ImmutableBitSet.serializer.serialize(value.rtAggrMetrics, out);

    GTTwoLayerAggregateParam.serializer.serialize(value.twoLayerAggParam, out);
}
 
Example 15
Source File: DictCodeSystem.java    From kylin with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(String value, ByteBuffer buffer) {
    BytesUtil.writeUTFString(value, buffer);
}
 
Example 16
Source File: DynamicTupleFilter.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(IFilterCodeSystem<?> cs, ByteBuffer buffer) {
    BytesUtil.writeUTFString(variableName, buffer);
}
 
Example 17
Source File: DynamicTupleFilter.java    From kylin with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(IFilterCodeSystem<?> cs, ByteBuffer buffer) {
    BytesUtil.writeUTFString(variableName, buffer);
}
 
Example 18
Source File: BuiltInFunctionTupleFilter.java    From kylin with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(IFilterCodeSystem<?> cs, ByteBuffer buffer) {
    BytesUtil.writeUTFString(name, buffer);
    buffer.put((byte) (isReversed ? 1 : 0));
}
 
Example 19
Source File: StringCodeSystem.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(String value, ByteBuffer buffer) {
    BytesUtil.writeUTFString(value, buffer);
}
 
Example 20
Source File: StringCodeSystem.java    From kylin with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(String value, ByteBuffer buffer) {
    BytesUtil.writeUTFString(value, buffer);
}