Search in sources :

Example 1 with LongArrayBlock

use of io.prestosql.spi.block.LongArrayBlock in project hetu-core by openlookeng.

the class AbstractLongSelectiveColumnReader method getLongArrayBlock.

private Block getLongArrayBlock(int[] positions, int positionCount, boolean includeNulls) {
    if (positionCount == outputPositionCount) {
        LongArrayBlock block;
        if (includeNulls) {
            block = new LongArrayBlock(positionCount, Optional.ofNullable(nulls), values);
            nulls = null;
        } else {
            block = new LongArrayBlock(positionCount, Optional.empty(), values);
        }
        values = null;
        return block;
    }
    long[] valuesCopy = new long[positionCount];
    boolean[] nullsCopy = null;
    if (includeNulls) {
        nullsCopy = new boolean[positionCount];
    }
    int positionIndex = 0;
    int nextPosition = positions[positionIndex];
    for (int i = 0; i < outputPositionCount; i++) {
        if (outputPositions[i] < nextPosition) {
            continue;
        }
        valuesCopy[positionIndex] = this.values[i];
        if (nullsCopy != null) {
            nullsCopy[positionIndex] = this.nulls[i];
        }
        positionIndex++;
        if (positionIndex >= positionCount) {
            break;
        }
        nextPosition = positions[positionIndex];
    }
    return new LongArrayBlock(positionCount, Optional.ofNullable(nullsCopy), valuesCopy);
}
Also used : LongArrayBlock(io.prestosql.spi.block.LongArrayBlock)

Example 2 with LongArrayBlock

use of io.prestosql.spi.block.LongArrayBlock in project hetu-core by openlookeng.

the class TestHBase method testPageSink.

/**
 * testPageSink
 */
@Test
public void testPageSink() {
    HBasePageSinkProvider hpsp = new HBasePageSinkProvider(hconn);
    HBaseTableHandle insertHandler = new HBaseTableHandle("hbase", "test_table", 0, hconn.getTable("hbase.test_table").getColumns(), hconn.getTable("hbase.test_table").getSerializerClassName(), Optional.of("test_table"), OptionalLong.empty());
    if (insertHandler instanceof ConnectorInsertTableHandle) {
        ConnectorPageSink cps = hpsp.createPageSink(new HBaseTransactionHandle(), session, (ConnectorInsertTableHandle) insertHandler);
        long completedBytes = cps.getCompletedBytes();
        long sysMemUsage = cps.getSystemMemoryUsage();
        long cpuNanos = cps.getValidationCpuNanos();
        assertTrue(cpuNanos >= 0);
        assertTrue(sysMemUsage >= 0);
        assertTrue(completedBytes >= 0);
        int[] offsets = { 0, 4 };
        Block rowkey = new VariableWidthBlock(1, TestSliceUtils.createSlice("0001"), offsets, Optional.empty());
        int[] offset2 = { 0, 5 };
        Block name = new VariableWidthBlock(1, TestSliceUtils.createSlice("name2"), offset2, Optional.empty());
        long[] longs = new long[1];
        longs[0] = 12;
        Block age = new LongArrayBlock(1, Optional.empty(), longs);
        int[] ints = new int[1];
        ints[0] = 17832;
        Block gender = new IntArrayBlock(1, Optional.empty(), ints);
        Block columnT = new LongArrayBlock(1, Optional.empty(), longs);
        Page page = new Page(rowkey, name, age, gender, columnT);
        assertEquals(NOT_BLOCKED, cps.appendPage(page));
        cps.abort();
    }
}
Also used : IntArrayBlock(io.prestosql.spi.block.IntArrayBlock) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) HBasePageSinkProvider(io.hetu.core.plugin.hbase.query.HBasePageSinkProvider) ConnectorInsertTableHandle(io.prestosql.spi.connector.ConnectorInsertTableHandle) HBaseTransactionHandle(io.hetu.core.plugin.hbase.connector.HBaseTransactionHandle) Page(io.prestosql.spi.Page) VariableWidthBlock(io.prestosql.spi.block.VariableWidthBlock) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) VariableWidthBlock(io.prestosql.spi.block.VariableWidthBlock) Block(io.prestosql.spi.block.Block) IntArrayBlock(io.prestosql.spi.block.IntArrayBlock) ConnectorPageSink(io.prestosql.spi.connector.ConnectorPageSink) HBaseTableHandle(io.hetu.core.plugin.hbase.connector.HBaseTableHandle) Test(org.testng.annotations.Test)

Example 3 with LongArrayBlock

use of io.prestosql.spi.block.LongArrayBlock in project hetu-core by openlookeng.

the class TestPolymorphicScalarFunction method testSelectsMultipleChoiceWithBlockPosition.

@Test
public void testSelectsMultipleChoiceWithBlockPosition() throws Throwable {
    Signature signature = Signature.builder().kind(SCALAR).operatorType(IS_DISTINCT_FROM).argumentTypes(DECIMAL_SIGNATURE, DECIMAL_SIGNATURE).returnType(parseTypeSignature(BOOLEAN)).build();
    SqlScalarFunction function = SqlScalarFunction.builder(TestMethods.class).signature(signature).deterministic(true).calledOnNullInput(IS_DISTINCT_FROM.isCalledOnNullInput()).choice(choice -> choice.argumentProperties(valueTypeArgumentProperty(USE_NULL_FLAG), valueTypeArgumentProperty(USE_NULL_FLAG)).implementation(methodsGroup -> methodsGroup.methods("shortShort", "longLong"))).choice(choice -> choice.argumentProperties(valueTypeArgumentProperty(BLOCK_AND_POSITION), valueTypeArgumentProperty(BLOCK_AND_POSITION)).implementation(methodsGroup -> methodsGroup.methodWithExplicitJavaTypes("blockPositionLongLong", asList(Optional.of(Slice.class), Optional.of(Slice.class))).methodWithExplicitJavaTypes("blockPositionShortShort", asList(Optional.of(long.class), Optional.of(long.class))))).build();
    BuiltInScalarFunctionImplementation functionImplementation = function.specialize(SHORT_DECIMAL_BOUND_VARIABLES, 2, METADATA.getFunctionAndTypeManager());
    assertEquals(functionImplementation.getAllChoices().size(), 2);
    assertEquals(functionImplementation.getAllChoices().get(0).getArgumentProperties(), Collections.nCopies(2, valueTypeArgumentProperty(USE_NULL_FLAG)));
    assertEquals(functionImplementation.getAllChoices().get(1).getArgumentProperties(), Collections.nCopies(2, valueTypeArgumentProperty(BLOCK_AND_POSITION)));
    Block block1 = new LongArrayBlock(0, Optional.empty(), new long[0]);
    Block block2 = new LongArrayBlock(0, Optional.empty(), new long[0]);
    assertFalse((boolean) functionImplementation.getAllChoices().get(1).getMethodHandle().invoke(block1, 0, block2, 0));
    functionImplementation = function.specialize(LONG_DECIMAL_BOUND_VARIABLES, 2, METADATA.getFunctionAndTypeManager());
    assertTrue((boolean) functionImplementation.getAllChoices().get(1).getMethodHandle().invoke(block1, 0, block2, 0));
}
Also used : ADD(io.prestosql.spi.function.OperatorType.ADD) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) BLOCK_AND_POSITION(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.BLOCK_AND_POSITION) Slice(io.airlift.slice.Slice) StandardTypes(io.prestosql.spi.type.StandardTypes) SCALAR(io.prestosql.spi.function.FunctionKind.SCALAR) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) VARCHAR_TO_BIGINT_RETURN_VALUE(io.prestosql.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_BIGINT_RETURN_VALUE) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) ImmutableList(com.google.common.collect.ImmutableList) Arrays.asList(java.util.Arrays.asList) Slices(io.airlift.slice.Slices) USE_NULL_FLAG(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.USE_NULL_FLAG) Math.toIntExact(java.lang.Math.toIntExact) Signature(io.prestosql.spi.function.Signature) Signature.comparableWithVariadicBound(io.prestosql.spi.function.Signature.comparableWithVariadicBound) Assert.assertFalse(org.testng.Assert.assertFalse) Block(io.prestosql.spi.block.Block) VARCHAR(io.prestosql.spi.type.StandardTypes.VARCHAR) ImmutableSet(com.google.common.collect.ImmutableSet) BOOLEAN(io.prestosql.spi.type.StandardTypes.BOOLEAN) ImmutableMap(com.google.common.collect.ImmutableMap) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) IS_DISTINCT_FROM(io.prestosql.spi.function.OperatorType.IS_DISTINCT_FROM) MAX_SHORT_PRECISION(io.prestosql.spi.type.Decimals.MAX_SHORT_PRECISION) ArgumentProperty.valueTypeArgumentProperty(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ArgumentProperty.valueTypeArgumentProperty) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) VARCHAR_TO_VARCHAR_RETURN_VALUE(io.prestosql.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_VARCHAR_RETURN_VALUE) TypeSignature(io.prestosql.spi.type.TypeSignature) Collections(java.util.Collections) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) TypeSignature(io.prestosql.spi.type.TypeSignature) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) Block(io.prestosql.spi.block.Block) Test(org.testng.annotations.Test)

Example 4 with LongArrayBlock

use of io.prestosql.spi.block.LongArrayBlock in project hetu-core by openlookeng.

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(io.prestosql.spi.block.LongArrayBlock) Test(org.testng.annotations.Test)

Example 5 with LongArrayBlock

use of io.prestosql.spi.block.LongArrayBlock in project hetu-core by openlookeng.

the class TimestampSelectiveColumnReader method getBlock.

@Override
public Block getBlock(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 new RunLengthEncodedBlock(NULL_BLOCK, outputPositionCount);
    }
    boolean includeNulls = nullsAllowed && presentStream != null;
    if (positionCount == outputPositionCount) {
        Block block = new LongArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), values);
        nulls = null;
        values = null;
        return block;
    }
    long[] valuesCopy = new long[positionCount];
    boolean[] nullsCopy = null;
    if (includeNulls) {
        nullsCopy = new boolean[positionCount];
    }
    int positionIndex = 0;
    int nextPosition = positions[positionIndex];
    for (int i = 0; i < outputPositionCount; i++) {
        if (outputPositions[i] < nextPosition) {
            continue;
        }
        valuesCopy[positionIndex] = this.values[i];
        if (nullsCopy != null) {
            nullsCopy[positionIndex] = this.nulls[i];
        }
        positionIndex++;
        if (positionIndex >= positionCount) {
            break;
        }
        nextPosition = positions[positionIndex];
    }
    return new LongArrayBlock(positionCount, Optional.ofNullable(nullsCopy), valuesCopy);
}
Also used : LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) Block(io.prestosql.spi.block.Block) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock)

Aggregations

LongArrayBlock (io.prestosql.spi.block.LongArrayBlock)6 Block (io.prestosql.spi.block.Block)4 Test (org.testng.annotations.Test)3 RunLengthEncodedBlock (io.prestosql.spi.block.RunLengthEncodedBlock)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Slice (io.airlift.slice.Slice)1 Slices (io.airlift.slice.Slices)1 HBaseTableHandle (io.hetu.core.plugin.hbase.connector.HBaseTableHandle)1 HBaseTransactionHandle (io.hetu.core.plugin.hbase.connector.HBaseTransactionHandle)1 HBasePageSinkProvider (io.hetu.core.plugin.hbase.query.HBasePageSinkProvider)1 MetadataManager.createTestMetadataManager (io.prestosql.metadata.MetadataManager.createTestMetadataManager)1 VARCHAR_TO_BIGINT_RETURN_VALUE (io.prestosql.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_BIGINT_RETURN_VALUE)1 VARCHAR_TO_VARCHAR_RETURN_VALUE (io.prestosql.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_VARCHAR_RETURN_VALUE)1 Page (io.prestosql.spi.Page)1 IntArrayBlock (io.prestosql.spi.block.IntArrayBlock)1 VariableWidthBlock (io.prestosql.spi.block.VariableWidthBlock)1 ConnectorInsertTableHandle (io.prestosql.spi.connector.ConnectorInsertTableHandle)1 ConnectorPageSink (io.prestosql.spi.connector.ConnectorPageSink)1