use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class LongDictionaryBatchStreamReader method readBlock.
@Override
public Block readBlock() throws IOException {
if (!rowGroupOpen) {
openRowGroup();
}
if (readOffset > 0) {
if (presentStream != null) {
// skip ahead the present bit reader, but count the set bits
// and use this as the skip size for the length reader
readOffset = presentStream.countBitsSet(readOffset);
}
if (inDictionaryStream != null) {
inDictionaryStream.skip(readOffset);
}
if (readOffset > 0) {
if (dataStream == null) {
throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), "Value is not null but data stream is not present");
}
dataStream.skip(readOffset);
}
}
BlockBuilder builder = type.createBlockBuilder(null, nextBatchSize);
if (presentStream == null) {
// Data doesn't have nulls
if (dataStream == null) {
throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), "Value is not null but data stream is not present");
}
if (inDictionaryStream == null) {
for (int i = 0; i < nextBatchSize; i++) {
type.writeLong(builder, dictionary[((int) dataStream.next())]);
}
} else {
for (int i = 0; i < nextBatchSize; i++) {
long id = dataStream.next();
if (inDictionaryStream.nextBit()) {
type.writeLong(builder, dictionary[(int) id]);
} else {
type.writeLong(builder, id);
}
}
}
} else {
// Data has nulls
if (dataStream == null) {
// The only valid case for dataStream is null when data has nulls is that all values are nulls.
int nullValues = presentStream.getUnsetBits(nextBatchSize);
if (nullValues != nextBatchSize) {
throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), "Value is not null but data stream is not present");
}
for (int i = 0; i < nextBatchSize; i++) {
builder.appendNull();
}
} else {
for (int i = 0; i < nextBatchSize; i++) {
if (!presentStream.nextBit()) {
builder.appendNull();
} else {
long id = dataStream.next();
if (inDictionaryStream == null || inDictionaryStream.nextBit()) {
type.writeLong(builder, dictionary[(int) id]);
} else {
type.writeLong(builder, id);
}
}
}
}
}
readOffset = 0;
nextBatchSize = 0;
return builder.build();
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class MapFlatSelectiveStreamReader method getIntegerKeysBlock.
private Block getIntegerKeysBlock(List<DwrfSequenceEncoding> sequenceEncodings) {
Type keyType;
switch(keyOrcTypeKind) {
case BYTE:
keyType = TinyintType.TINYINT;
break;
case SHORT:
keyType = SmallintType.SMALLINT;
break;
case INT:
keyType = IntegerType.INTEGER;
break;
case LONG:
keyType = BigintType.BIGINT;
break;
default:
throw new IllegalArgumentException("Unsupported flat map key type: " + keyOrcTypeKind);
}
BlockBuilder blockBuilder = keyType.createBlockBuilder(null, sequenceEncodings.size());
for (int i = 0; i < keyCount; i++) {
keyType.writeLong(blockBuilder, sequenceEncodings.get(keyIndices[i]).getKey().getIntKey());
}
return blockBuilder.build();
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class TestTemporalFunction method testTimestampBlock.
@Test
void testTimestampBlock() {
BlockBuilder blockBuilder = TIMESTAMP.createBlockBuilder(null, 4);
// start and end of UTC day
TIMESTAMP.writeLong(blockBuilder, UTC_TIME.getMillis());
TIMESTAMP.writeLong(blockBuilder, UTC_TIME.getMillis() + Duration.ofHours(23).toMillis());
// start and end of PST day
TIMESTAMP.writeLong(blockBuilder, PST_TIME.getMillis());
TIMESTAMP.writeLong(blockBuilder, PST_TIME.getMillis() + Duration.ofHours(23).toMillis());
Block block = blockBuilder.build();
TemporalFunction temporalFunction = new TemporalFunction(UTC);
assertEquals(temporalFunction.getDay(TIMESTAMP, block, 0), 1);
assertEquals(temporalFunction.getDay(TIMESTAMP, block, 1), 1);
assertEquals(temporalFunction.getDay(TIMESTAMP, block, 2), 1);
assertEquals(temporalFunction.getDay(TIMESTAMP, block, 3), 2);
temporalFunction = new TemporalFunction(PST);
assertEquals(temporalFunction.getDay(TIMESTAMP, block, 0), 0);
assertEquals(temporalFunction.getDay(TIMESTAMP, block, 1), 1);
assertEquals(temporalFunction.getDay(TIMESTAMP, block, 2), 1);
assertEquals(temporalFunction.getDay(TIMESTAMP, block, 3), 1);
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class BlockEncoding method decodeColumn.
@Override
public final Block decodeColumn(ColumnData columnData) throws RcFileCorruptionException {
int size = columnData.rowCount();
Slice slice = columnData.getSlice();
BlockBuilder builder = type.createBlockBuilder(null, size);
for (int i = 0; i < size; i++) {
int length = columnData.getLength(i);
int offset = columnData.getOffset(i);
if (!isNullSequence(slice, offset, length)) {
decodeValueInto(1, builder, slice, offset, length);
} else {
builder.appendNull();
}
}
return builder.build();
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class DateEncoding method decodeColumn.
@Override
public Block decodeColumn(ColumnData columnData) {
int size = columnData.rowCount();
BlockBuilder builder = type.createBlockBuilder(null, size);
Slice slice = columnData.getSlice();
for (int i = 0; i < size; i++) {
int offset = columnData.getOffset(i);
int length = columnData.getLength(i);
if (length == 0 || nullSequence.equals(0, nullSequence.length(), slice, offset, length)) {
builder.appendNull();
} else {
// noinspection deprecation
type.writeLong(builder, parseDate(slice, offset, length));
}
}
return builder.build();
}
Aggregations