Search in sources :

Example 1 with IntArrayBlock

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

the class TestExpressionOptimizer method testCastWithJsonParseOptimization.

@Test
public void testCastWithJsonParseOptimization() {
    FunctionHandle jsonParseFunctionHandle = functionAndTypeManager.lookupFunction("json_parse", fromTypes(VARCHAR));
    // constant
    FunctionHandle jsonCastFunctionHandle = functionAndTypeManager.lookupCast(CAST, JSON.getTypeSignature(), parseTypeSignature("array(integer)"));
    RowExpression jsonCastExpression = new CallExpression(CAST.name(), jsonCastFunctionHandle, new ArrayType(INTEGER), ImmutableList.of(call("json_parse", jsonParseFunctionHandle, JSON, constant(utf8Slice("[1, 2]"), VARCHAR))), Optional.empty());
    RowExpression resultExpression = optimizer.optimize(jsonCastExpression);
    assertInstanceOf(resultExpression, ConstantExpression.class);
    Object resultValue = ((ConstantExpression) resultExpression).getValue();
    assertInstanceOf(resultValue, IntArrayBlock.class);
    assertEquals(toValues(INTEGER, (IntArrayBlock) resultValue), ImmutableList.of(1, 2));
    // varchar to array
    jsonCastFunctionHandle = functionAndTypeManager.lookupCast(CAST, JSON.getTypeSignature(), parseTypeSignature("array(varchar)"));
    jsonCastExpression = call(CAST.name(), jsonCastFunctionHandle, new ArrayType(VARCHAR), ImmutableList.of(call("json_parse", jsonParseFunctionHandle, JSON, field(1, VARCHAR))));
    resultExpression = optimizer.optimize(jsonCastExpression);
    assertEquals(resultExpression, call(JSON_TO_ARRAY_CAST.name(), functionAndTypeManager.lookupCast(JSON_TO_ARRAY_CAST, VARCHAR.getTypeSignature(), parseTypeSignature("array(varchar)")), new ArrayType(VARCHAR), field(1, VARCHAR)));
    // varchar to row
    jsonCastFunctionHandle = functionAndTypeManager.lookupCast(CAST, JSON.getTypeSignature(), parseTypeSignature("row(varchar,bigint)"));
    jsonCastExpression = call(CAST.name(), jsonCastFunctionHandle, RowType.anonymous(ImmutableList.of(VARCHAR, BIGINT)), ImmutableList.of(call("json_parse", jsonParseFunctionHandle, JSON, field(1, VARCHAR))));
    resultExpression = optimizer.optimize(jsonCastExpression);
    assertEquals(resultExpression, call(JSON_TO_ROW_CAST.name(), functionAndTypeManager.lookupCast(JSON_TO_ROW_CAST, VARCHAR.getTypeSignature(), parseTypeSignature("row(varchar,bigint)")), RowType.anonymous(ImmutableList.of(VARCHAR, BIGINT)), field(1, VARCHAR)));
    // varchar to map
    jsonCastFunctionHandle = functionAndTypeManager.lookupCast(CAST, JSON.getTypeSignature(), parseTypeSignature("map(integer,varchar)"));
    jsonCastExpression = call(CAST.name(), jsonCastFunctionHandle, mapType(INTEGER, VARCHAR), ImmutableList.of(call("json_parse", jsonParseFunctionHandle, JSON, field(1, VARCHAR))));
    resultExpression = optimizer.optimize(jsonCastExpression);
    assertEquals(resultExpression, call(JSON_TO_MAP_CAST.name(), functionAndTypeManager.lookupCast(JSON_TO_MAP_CAST, VARCHAR.getTypeSignature(), parseTypeSignature("map(integer, varchar)")), mapType(INTEGER, VARCHAR), field(1, VARCHAR)));
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) IntArrayBlock(io.prestosql.spi.block.IntArrayBlock) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) RowExpression(io.prestosql.spi.relation.RowExpression) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) FunctionHandle(io.prestosql.spi.function.FunctionHandle) CallExpression(io.prestosql.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Example 2 with IntArrayBlock

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

the class FloatSelectiveColumnReader 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");
    if (allNulls) {
        return new RunLengthEncodedBlock(NULL_BLOCK, positionCount);
    }
    boolean includeNulls = nullsAllowed && presentStream != null;
    if (positionCount == outputPositionCount) {
        Block block = new IntArrayBlock(positionCount, Optional.ofNullable(includeNulls ? nulls : null), values);
        nulls = null;
        values = null;
        return block;
    }
    int[] valuesCopy = new int[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 IntArrayBlock(positionCount, Optional.ofNullable(nullsCopy), valuesCopy);
}
Also used : IntArrayBlock(io.prestosql.spi.block.IntArrayBlock) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) Block(io.prestosql.spi.block.Block) IntArrayBlock(io.prestosql.spi.block.IntArrayBlock) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock)

Example 3 with IntArrayBlock

use of io.prestosql.spi.block.IntArrayBlock 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 4 with IntArrayBlock

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

the class TestHetuObjectTranslator method testTranslateFromHiveObjectWithListObject.

@Test
public void testTranslateFromHiveObjectWithListObject() {
    Object res = new IntArrayBlock(2, Optional.ofNullable(new boolean[] { true, true }), new int[] { 1, 2 });
    assertEquals(translateFromHiveObject(new ArrayParametricType().createType(Arrays.asList("integer")), Arrays.asList(1, 2)).toString(), res.toString());
}
Also used : IntArrayBlock(io.prestosql.spi.block.IntArrayBlock) HiveObjectTranslator.translateToHiveObject(io.hetu.core.hive.dynamicfunctions.utils.HiveObjectTranslator.translateToHiveObject) HiveObjectTranslator.translateFromHiveObject(io.hetu.core.hive.dynamicfunctions.utils.HiveObjectTranslator.translateFromHiveObject) ArrayParametricType(io.hetu.core.hive.dynamicfunctions.type.ArrayParametricType) Test(org.testng.annotations.Test)

Example 5 with IntArrayBlock

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

the class TestHetuObjectTranslator method testTranslateToHiveObjectWithListObject.

@Test
public void testTranslateToHiveObjectWithListObject() {
    ParameterizedType listType = new ParameterizedType() {

        @Override
        public Type[] getActualTypeArguments() {
            return new Type[] { Integer.class };
        }

        @Override
        public Type getRawType() {
            return List.class;
        }

        @Override
        public Type getOwnerType() {
            return null;
        }
    };
    Object obj = new IntArrayBlock(2, Optional.ofNullable(new boolean[] { true, true }), new int[] { 1, 2 });
    assertEquals(translateToHiveObject(new ArrayParametricType().createType(Arrays.asList("integer")), obj, listType), Arrays.asList(1, 2));
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) IntArrayBlock(io.prestosql.spi.block.IntArrayBlock) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ArrayParametricType(io.hetu.core.hive.dynamicfunctions.type.ArrayParametricType) List(java.util.List) HiveObjectTranslator.translateToHiveObject(io.hetu.core.hive.dynamicfunctions.utils.HiveObjectTranslator.translateToHiveObject) HiveObjectTranslator.translateFromHiveObject(io.hetu.core.hive.dynamicfunctions.utils.HiveObjectTranslator.translateFromHiveObject) ArrayParametricType(io.hetu.core.hive.dynamicfunctions.type.ArrayParametricType) Test(org.testng.annotations.Test)

Aggregations

IntArrayBlock (io.prestosql.spi.block.IntArrayBlock)8 Test (org.testng.annotations.Test)7 Page (io.prestosql.spi.Page)3 ArrayParametricType (io.hetu.core.hive.dynamicfunctions.type.ArrayParametricType)2 HiveObjectTranslator.translateFromHiveObject (io.hetu.core.hive.dynamicfunctions.utils.HiveObjectTranslator.translateFromHiveObject)2 HiveObjectTranslator.translateToHiveObject (io.hetu.core.hive.dynamicfunctions.utils.HiveObjectTranslator.translateToHiveObject)2 Block (io.prestosql.spi.block.Block)2 Matchers.anyObject (org.mockito.Matchers.anyObject)2 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 LongArrayBlock (io.prestosql.spi.block.LongArrayBlock)1 RunLengthEncodedBlock (io.prestosql.spi.block.RunLengthEncodedBlock)1 VariableWidthBlock (io.prestosql.spi.block.VariableWidthBlock)1 ConnectorInsertTableHandle (io.prestosql.spi.connector.ConnectorInsertTableHandle)1 ConnectorPageSink (io.prestosql.spi.connector.ConnectorPageSink)1 BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)1 FunctionHandle (io.prestosql.spi.function.FunctionHandle)1 CallExpression (io.prestosql.spi.relation.CallExpression)1 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)1