Search in sources :

Example 1 with PresentOutputStream

use of com.facebook.presto.orc.stream.PresentOutputStream in project presto by prestodb.

the class DictionaryColumnWriter method tryConvertToDirect.

@Override
public OptionalInt tryConvertToDirect(int maxDirectBytes) {
    checkState(!closed);
    checkState(!directEncoded);
    ColumnWriter directWriter = createDirectColumnWriter();
    checkState(directWriter.getBufferedBytes() == 0, "direct writer should have no data");
    for (DictionaryRowGroup rowGroup : rowGroups) {
        beginDataRowGroup();
        // todo we should be able to pass the stats down to avoid recalculating min and max
        boolean success = tryConvertRowGroupToDirect(rowGroup.getByteSegments(), rowGroup.getShortSegments(), rowGroup.getIntSegments(), maxDirectBytes);
        if (!success) {
            return resetDirectWriter(directWriter);
        }
        directWriter.finishRowGroup();
    }
    if (inRowGroup) {
        beginDataRowGroup();
        boolean success = tryConvertRowGroupToDirect(rowGroupBuilder.getByteSegments(), rowGroupBuilder.getShortSegments(), rowGroupBuilder.getIntegerSegments(), maxDirectBytes);
        if (!success) {
            return resetDirectWriter(directWriter);
        }
        if (!tryConvertRowGroupToDirect(rowGroupOffset, rowGroupIndexes, maxDirectBytes)) {
            return resetDirectWriter(directWriter);
        }
    } else {
        checkState(rowGroupOffset == 0);
    }
    // Conversion to DirectStream succeeded, Transfer the present stream to direct writer and assign
    // this a new PresentStream, so one writer is responsible for one present stream.
    movePresentStreamToDirectWriter(presentStream);
    presentStream = new PresentOutputStream(columnWriterOptions, dwrfEncryptor);
    // free the dictionary
    rawBytesEstimate = 0;
    totalValueCount = 0;
    totalNonNullValueCount = 0;
    resetRowGroups();
    closeDictionary();
    resetDictionary();
    directEncoded = true;
    return OptionalInt.of(toIntExact(directWriter.getBufferedBytes()));
}
Also used : PresentOutputStream(com.facebook.presto.orc.stream.PresentOutputStream)

Aggregations

PresentOutputStream (com.facebook.presto.orc.stream.PresentOutputStream)1