Search in sources :

Example 1 with BooleanInputStream

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

the class MapFlatSelectiveStreamReader method openRowGroup.

private void openRowGroup() throws IOException {
    presentStream = presentStreamSource.openStream();
    for (int i = 0; i < keyCount; i++) {
        BooleanInputStream inMapStream = requireNonNull(inMapStreamSources.get(i).openStream(), "missing inMapStream at position " + i);
        inMapStreams.add(inMapStream);
    }
    rowGroupOpen = true;
}
Also used : BooleanInputStream(com.facebook.presto.orc.stream.BooleanInputStream)

Example 2 with BooleanInputStream

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

the class MapFlatBatchStreamReader method openRowGroup.

private void openRowGroup() throws IOException {
    presentStream = presentStreamSource.openStream();
    for (int i = 0; i < inMapStreamSources.size(); i++) {
        BooleanInputStream inMapStream = requireNonNull(inMapStreamSources.get(i).openStream(), "missing inMapStream at position " + i);
        inMapStreams.add(inMapStream);
    }
    rowGroupOpen = true;
}
Also used : BooleanInputStream(com.facebook.presto.orc.stream.BooleanInputStream)

Example 3 with BooleanInputStream

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

the class MapFlatSelectiveStreamReader method readNotAllNulls.

private void readNotAllNulls(int offset, int[] positions, int positionCount) throws IOException {
    int streamPosition = 0;
    int[] nonNullPositions = new int[positionCount];
    int[] nullPositions = new int[positionCount];
    int nonNullPositionCount = 0;
    int nullPositionCount = 0;
    int nonNullSkipped = 0;
    if (presentStream == null) {
        if (readOffset < offset) {
            for (int i = 0; i < keyCount; i++) {
                nestedReadOffsets[i] += inMapStreams.get(i).countBitsSet(offset - readOffset);
            }
        }
        for (int i = 0; i < positionCount; i++) {
            int position = positions[i];
            if (position > streamPosition) {
                nonNullSkipped += position - streamPosition;
                streamPosition = position;
            }
            nonNullPositions[i] = i + nonNullSkipped;
            streamPosition++;
        }
        nonNullPositionCount = positionCount;
    } else {
        if (readOffset < offset) {
            int skipped = presentStream.countBitsSet(offset - readOffset);
            if (skipped > 0) {
                for (int i = 0; i < keyCount; i++) {
                    nestedReadOffsets[i] += inMapStreams.get(i).countBitsSet(skipped);
                }
            }
        }
        for (int i = 0; i < positionCount; i++) {
            int position = positions[i];
            if (position > streamPosition) {
                nonNullSkipped += presentStream.countBitsSet(position - streamPosition);
                streamPosition = position;
            }
            streamPosition++;
            if (presentStream.nextBit()) {
                // not null
                if (nullsAllowed) {
                    nulls[i] = false;
                }
                nonNullPositions[nonNullPositionCount] = nonNullPositionCount + nonNullSkipped;
                nonNullPositionCount++;
            } else {
                if (nullsAllowed) {
                    nulls[i] = true;
                    nullPositions[nullPositionCount] = positions[i];
                    nullPositionCount++;
                }
            }
        }
    }
    readOffset = offset + streamPosition;
    if (!nonNullsAllowed) {
        checkState(nullPositionCount == (positionCount - nonNullPositionCount), "nullPositionCount should be equal to postitionCount - nonNullPositionCount");
        outputPositionCount = nullPositionCount;
        allNulls = true;
        System.arraycopy(nullPositions, 0, outputPositions, 0, nullPositionCount);
    } else {
        nestedLengths = ensureCapacity(nestedLengths, nonNullPositionCount);
        Arrays.fill(nestedLengths, 0);
        for (int keyIndex = 0; keyIndex < keyCount; keyIndex++) {
            BooleanInputStream inMapStream = inMapStreams.get(keyIndex);
            nestedPositions[keyIndex] = ensureCapacity(nestedPositions[keyIndex], nonNullPositionCount);
            inMap[keyIndex] = ensureCapacity(inMap[keyIndex], nonNullPositionCount);
            int nestedStreamPosition = 0;
            int nestedSkipped = 0;
            int nestedPositionCount = 0;
            for (int i = 0; i < nonNullPositionCount; i++) {
                int position = nonNullPositions[i];
                if (position > nestedStreamPosition) {
                    nestedSkipped += inMapStream.countBitsSet(position - nestedStreamPosition);
                    nestedStreamPosition = position;
                }
                nestedStreamPosition++;
                if (inMapStream.nextBit()) {
                    nestedPositions[keyIndex][nestedPositionCount] = nestedPositionCount + nestedSkipped;
                    nestedPositionCount++;
                    nestedLengths[i]++;
                    inMap[keyIndex][i] = true;
                } else {
                    inMap[keyIndex][i] = false;
                }
            }
            if (nonNullSkipped > nestedStreamPosition - nonNullPositionCount) {
                inMapStream.skip(nonNullSkipped - (nestedStreamPosition - nonNullPositionCount));
            }
            nestedPositionCounts[keyIndex] = nestedPositionCount;
            if (nestedPositionCount > 0) {
                int readCount = valueStreamReaders.get(keyIndex).read(nestedReadOffsets[keyIndex], nestedPositions[keyIndex], nestedPositionCount);
                verify(readCount == nestedPositionCount);
            }
            nestedReadOffsets[keyIndex] += nestedSkipped + nestedPositionCount;
        }
        if (nullsAllowed) {
            outputPositionCount = positionCount;
        } else {
            System.arraycopy(nonNullPositions, 0, outputPositions, 0, nonNullPositionCount);
            outputPositionCount = nonNullPositionCount;
        }
    }
    if (outputRequired) {
        nestedOutputPositions = ensureCapacity(nestedOutputPositions, keyCount);
        for (int i = 0; i < keyCount; i++) {
            int nestedPositionCount = nestedPositionCounts[i];
            if (nestedPositionCount > 0) {
                nestedOutputPositions[i] = ensureCapacity(nestedOutputPositions[i], nestedPositionCount);
                System.arraycopy(nestedPositions[i], 0, nestedOutputPositions[i], 0, nestedPositionCount);
            }
        }
    }
}
Also used : BooleanInputStream(com.facebook.presto.orc.stream.BooleanInputStream)

Aggregations

BooleanInputStream (com.facebook.presto.orc.stream.BooleanInputStream)3