Search in sources :

Example 1 with Data

use of com.wplatform.ddal.util.Data in project jdbc-shards by wplatform.

the class ResultDiskBuffer method readRow.

private void readRow(ResultDiskTape tape) {
    int min = Constants.FILE_BLOCK_SIZE;
    Data buff = rowBuff;
    buff.reset();
    readFully(buff.getBytes(), 0, min);
    int len = buff.readInt();
    buff.checkCapacity(len);
    if (len - min > 0) {
        readFully(buff.getBytes(), min, len - min);
    }
    tape.pos += len;
    Value[] row = new Value[columnCount];
    for (int k = 0; k < columnCount; k++) {
        row[k] = buff.readValue();
    }
    tape.buffer.add(row);
}
Also used : Value(com.wplatform.ddal.value.Value) Data(com.wplatform.ddal.util.Data)

Example 2 with Data

use of com.wplatform.ddal.util.Data in project jdbc-shards by wplatform.

the class ResultDiskBuffer method addRows.

public int addRows(ArrayList<Value[]> rows) {
    if (sort != null) {
        sort.sort(rows);
    }
    Data buff = rowBuff;
    long start = getFilePointer();
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    int bufferLen = 0;
    for (Value[] row : rows) {
        buff.reset();
        buff.writeInt(0);
        for (int j = 0; j < columnCount; j++) {
            Value v = row[j];
            buff.checkCapacity(Data.getValueLen(v));
            buff.writeValue(v);
        }
        buff.fillAligned();
        int len = buff.length();
        buff.setInt(0, len);
        if (maxBufferSize > 0) {
            buffer.write(buff.getBytes(), 0, len);
            bufferLen += len;
            if (bufferLen > maxBufferSize) {
                byte[] data = buffer.toByteArray();
                buffer.reset();
                write(data, 0, data.length);
                bufferLen = 0;
            }
        } else {
            write(buff.getBytes(), 0, len);
        }
    }
    if (bufferLen > 0) {
        byte[] data = buffer.toByteArray();
        write(data, 0, data.length);
    }
    if (sort != null) {
        ResultDiskTape tape = new ResultDiskTape();
        tape.start = start;
        tape.end = getFilePointer();
        tapes.add(tape);
    } else {
        mainTape.end = getFilePointer();
    }
    rowCount += rows.size();
    return rowCount;
}
Also used : Value(com.wplatform.ddal.value.Value) Data(com.wplatform.ddal.util.Data) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

Data (com.wplatform.ddal.util.Data)2 Value (com.wplatform.ddal.value.Value)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1