Search in sources :

Example 1 with LongArrayBlock

use of com.facebook.presto.common.block.LongArrayBlock in project presto by prestodb.

the class TimestampSelectiveStreamReader method getBlockView.

@Override
public BlockLease getBlockView(int[] positions, int positionCount) {
    checkArgument(outputPositionCount > 0, "outputPositionCount must be greater than zero");
    checkState(outputRequired, "This stream reader doesn't produce output");
    checkState(positionCount <= outputPositionCount, "Not enough values");
    checkState(!valuesInUse, "BlockLease hasn't been closed yet");
    if (allNulls) {
        return newLease(new RunLengthEncodedBlock(NULL_BLOCK, positionCount));
    }
    boolean includeNulls = nullsAllowed && presentStream != null;
    if (positionCount != outputPositionCount) {
        compactValues(positions, positionCount, includeNulls);
    }
    return newLease(new LongArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), values));
}
Also used : LongArrayBlock(com.facebook.presto.common.block.LongArrayBlock) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Example 2 with LongArrayBlock

use of com.facebook.presto.common.block.LongArrayBlock in project presto by prestodb.

the class DoubleSelectiveStreamReader method getBlockView.

@Override
public BlockLease getBlockView(int[] positions, int positionCount) {
    checkArgument(outputPositionCount > 0, "outputPositionCount must be greater than zero");
    checkState(outputRequired, "This stream reader doesn't produce output");
    checkState(positionCount <= outputPositionCount, "Not enough values");
    checkState(!valuesInUse, "BlockLease hasn't been closed yet");
    if (allNulls) {
        return newLease(new RunLengthEncodedBlock(NULL_BLOCK, positionCount));
    }
    boolean includeNulls = nullsAllowed && presentStream != null;
    if (positionCount != outputPositionCount) {
        compactValues(positions, positionCount, includeNulls);
    }
    return newLease(new LongArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), values));
}
Also used : LongArrayBlock(com.facebook.presto.common.block.LongArrayBlock) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Example 3 with LongArrayBlock

use of com.facebook.presto.common.block.LongArrayBlock in project presto by prestodb.

the class TestLongArrayBlock method testCompactBlock.

@Test
public void testCompactBlock() {
    long[] longArray = { 0L, 0L, 1L, 2L, 3L, 4L };
    boolean[] valueIsNull = { false, true, false, false, false, false };
    testCompactBlock(new LongArrayBlock(0, Optional.empty(), new long[0]));
    testCompactBlock(new LongArrayBlock(longArray.length, Optional.of(valueIsNull), longArray));
    testIncompactBlock(new LongArrayBlock(longArray.length - 1, Optional.of(valueIsNull), longArray));
}
Also used : LongArrayBlock(com.facebook.presto.common.block.LongArrayBlock) Test(org.testng.annotations.Test)

Example 4 with LongArrayBlock

use of com.facebook.presto.common.block.LongArrayBlock in project presto by prestodb.

the class TestObjectEncoders method testComplexObjectEncoders.

@Test
public void testComplexObjectEncoders() {
    ObjectInspector inspector;
    ObjectEncoder encoder;
    inspector = ObjectInspectors.create(new ArrayType(BIGINT), typeManager);
    encoder = createEncoder(new ArrayType(BIGINT), inspector);
    assertTrue(encoder instanceof ObjectEncoders.ListObjectEncoder);
    Object arrayObject = encoder.encode(new Long[] { 1L, 2L, 3L });
    assertTrue(arrayObject instanceof LongArrayBlock);
    assertEquals(((LongArrayBlock) arrayObject).getLong(0), 1L);
    assertEquals(((LongArrayBlock) arrayObject).getLong(1), 2L);
    assertEquals(((LongArrayBlock) arrayObject).getLong(2), 3L);
    inspector = ObjectInspectors.create(new MapType(VARCHAR, BIGINT, methodHandle(TestRowType.class, "throwUnsupportedOperation"), methodHandle(TestRowType.class, "throwUnsupportedOperation")), typeManager);
    encoder = createEncoder(new MapType(VARCHAR, BIGINT, methodHandle(TestRowType.class, "throwUnsupportedOperation"), methodHandle(TestRowType.class, "throwUnsupportedOperation")), inspector);
    assertTrue(encoder instanceof ObjectEncoders.MapObjectEncoder);
    assertTrue(encoder.encode(new HashMap<String, Long>() {
    }) instanceof SingleMapBlock);
}
Also used : LongArrayBlock(com.facebook.presto.common.block.LongArrayBlock) PrimitiveObjectInspectorFactory.writableByteObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableByteObjectInspector) PrimitiveObjectInspectorFactory.writableDateObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) PrimitiveObjectInspectorFactory.writableShortObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableShortObjectInspector) PrimitiveObjectInspectorFactory.writableStringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector) PrimitiveObjectInspectorFactory.writableBooleanObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableBooleanObjectInspector) PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector) PrimitiveObjectInspectorFactory.writableBinaryObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableBinaryObjectInspector) PrimitiveObjectInspectorFactory.writableIntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableIntObjectInspector) PrimitiveObjectInspectorFactory.writableDoubleObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDoubleObjectInspector) PrimitiveObjectInspectorFactory.writableLongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableLongObjectInspector) TestRowType(com.facebook.presto.common.type.TestRowType) MapType(com.facebook.presto.common.type.MapType) ArrayType(com.facebook.presto.common.type.ArrayType) SingleMapBlock(com.facebook.presto.common.block.SingleMapBlock) Test(org.testng.annotations.Test)

Example 5 with LongArrayBlock

use of com.facebook.presto.common.block.LongArrayBlock in project presto by prestodb.

the class BenchmarkGroupByHash method benchmarkHashPosition.

@Benchmark
@OperationsPerInvocation(POSITIONS)
public List<Page> benchmarkHashPosition(BenchmarkData data) {
    InterpretedHashGenerator hashGenerator = new InterpretedHashGenerator(data.getTypes(), data.getChannels());
    ImmutableList.Builder<Page> results = ImmutableList.builderWithExpectedSize(data.getPages().size());
    for (Page page : data.getPages()) {
        long[] hashes = new long[page.getPositionCount()];
        for (int position = 0; position < page.getPositionCount(); position++) {
            hashes[position] = hashGenerator.hashPosition(position, page);
        }
        results.add(page.appendColumn(new LongArrayBlock(page.getPositionCount(), Optional.empty(), hashes)));
    }
    return results.build();
}
Also used : LongArrayBlock(com.facebook.presto.common.block.LongArrayBlock) ImmutableList(com.google.common.collect.ImmutableList) Page(com.facebook.presto.common.Page) Benchmark(org.openjdk.jmh.annotations.Benchmark) OperationsPerInvocation(org.openjdk.jmh.annotations.OperationsPerInvocation)

Aggregations

LongArrayBlock (com.facebook.presto.common.block.LongArrayBlock)10 Block (com.facebook.presto.common.block.Block)4 RunLengthEncodedBlock (com.facebook.presto.common.block.RunLengthEncodedBlock)4 Test (org.testng.annotations.Test)3 ImmutableList (com.google.common.collect.ImmutableList)2 Benchmark (org.openjdk.jmh.annotations.Benchmark)2 Page (com.facebook.presto.common.Page)1 SingleMapBlock (com.facebook.presto.common.block.SingleMapBlock)1 ADD (com.facebook.presto.common.function.OperatorType.ADD)1 IS_DISTINCT_FROM (com.facebook.presto.common.function.OperatorType.IS_DISTINCT_FROM)1 ArrayType (com.facebook.presto.common.type.ArrayType)1 MAX_SHORT_PRECISION (com.facebook.presto.common.type.Decimals.MAX_SHORT_PRECISION)1 MapType (com.facebook.presto.common.type.MapType)1 StandardTypes (com.facebook.presto.common.type.StandardTypes)1 BOOLEAN (com.facebook.presto.common.type.StandardTypes.BOOLEAN)1 VARCHAR (com.facebook.presto.common.type.StandardTypes.VARCHAR)1 TestRowType (com.facebook.presto.common.type.TestRowType)1 TypeSignature (com.facebook.presto.common.type.TypeSignature)1 TypeSignature.parseTypeSignature (com.facebook.presto.common.type.TypeSignature.parseTypeSignature)1 FunctionAndTypeManager.createTestFunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager)1