Search in sources :

Example 1 with ColumnData

use of com.facebook.presto.rcfile.ColumnData in project presto by prestodb.

the class StringEncoding method unescape.

@SuppressWarnings("AssignmentToForLoopParameter")
private static ColumnData unescape(ColumnData columnData, byte escapeByte) {
    Slice slice = columnData.getSlice();
    // does slice contain escape byte
    if (slice.indexOfByte(escapeByte) < 0) {
        return columnData;
    }
    Slice newSlice = Slices.allocate(slice.length());
    SliceOutput output = newSlice.getOutput();
    int[] newOffsets = new int[columnData.rowCount() + 1];
    for (int row = 0; row < columnData.rowCount(); row++) {
        int offset = columnData.getOffset(row);
        int length = columnData.getLength(row);
        for (int i = 0; i < length; i++) {
            byte value = slice.getByte(offset + i);
            if (value == escapeByte && i + 1 < length) {
                // read byte after escape
                i++;
                value = slice.getByte(offset + i);
            }
            output.write(value);
        }
        newOffsets[row + 1] = output.size();
    }
    return new ColumnData(newOffsets, output.slice());
}
Also used : SliceOutput(io.airlift.slice.SliceOutput) Slice(io.airlift.slice.Slice) ColumnData(com.facebook.presto.rcfile.ColumnData)

Aggregations

ColumnData (com.facebook.presto.rcfile.ColumnData)1 Slice (io.airlift.slice.Slice)1 SliceOutput (io.airlift.slice.SliceOutput)1