Search in sources :

Example 26 with BlockBuilder

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

the class TestArrayOperators method assertArrayHashOperator.

private void assertArrayHashOperator(String inputArray, Type elementType, List<Object> elements) {
    ArrayType arrayType = new ArrayType(elementType);
    BlockBuilder arrayArrayBuilder = arrayType.createBlockBuilder(null, 1);
    BlockBuilder arrayBuilder = elementType.createBlockBuilder(null, elements.size());
    for (Object element : elements) {
        appendToBlockBuilder(elementType, element, arrayBuilder);
    }
    arrayType.writeObject(arrayArrayBuilder, arrayBuilder.build());
    assertOperator(HASH_CODE, inputArray, BIGINT, arrayType.hash(arrayArrayBuilder.build(), 0));
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) BlockBuilder(io.prestosql.spi.block.BlockBuilder) StructuralTestUtil.appendToBlockBuilder(io.prestosql.util.StructuralTestUtil.appendToBlockBuilder)

Example 27 with BlockBuilder

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

the class TestBigintArrayType method createTestBlock.

public static Block createTestBlock(Type arrayType) {
    BlockBuilder blockBuilder = arrayType.createBlockBuilder(null, 4);
    arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, 1, 2));
    arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, 1, 2, 3));
    arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, 1, 2, 3));
    arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, 100, 200, 300));
    return blockBuilder.build();
}
Also used : BlockBuilder(io.prestosql.spi.block.BlockBuilder)

Example 28 with BlockBuilder

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

the class TestCharType method testGetObjectValue.

@Test
public void testGetObjectValue() {
    CharType charType = createCharType(3);
    for (int codePoint : ImmutableList.of(0, 1, 10, 17, (int) ' ', 127, 1011, 11_000, 65_891, MIN_SUPPLEMENTARY_CODE_POINT, MAX_CODE_POINT)) {
        BlockBuilder blockBuilder = charType.createBlockBuilder(null, 1);
        Slice slice = (codePoint != ' ') ? codePointToUtf8(codePoint) : EMPTY_SLICE;
        blockBuilder.writeBytes(slice, 0, slice.length());
        blockBuilder.closeEntry();
        Block block = blockBuilder.build();
        int codePointLengthInUtf16 = isSupplementaryCodePoint(codePoint) ? 2 : 1;
        String objectValue = (String) charType.getObjectValue(SESSION, block, 0);
        assertNotNull(objectValue);
        assertEquals(objectValue.codePointAt(0), codePoint, "first code point");
        assertEquals(objectValue.length(), codePointLengthInUtf16 + 2, "size");
        for (int i = codePointLengthInUtf16; i < objectValue.length(); i++) {
            assertEquals(objectValue.codePointAt(i), ' ');
        }
    }
}
Also used : Slice(io.airlift.slice.Slice) Block(io.prestosql.spi.block.Block) CharType.createCharType(io.prestosql.spi.type.CharType.createCharType) CharType(io.prestosql.spi.type.CharType) Character.isSupplementaryCodePoint(java.lang.Character.isSupplementaryCodePoint) BlockBuilder(io.prestosql.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 29 with BlockBuilder

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

the class TestCharType method createTestBlock.

public static Block createTestBlock() {
    BlockBuilder blockBuilder = CHAR_TYPE.createBlockBuilder(null, 15);
    CHAR_TYPE.writeString(blockBuilder, "apple");
    CHAR_TYPE.writeString(blockBuilder, "apple");
    CHAR_TYPE.writeString(blockBuilder, "apple");
    CHAR_TYPE.writeString(blockBuilder, "banana");
    CHAR_TYPE.writeString(blockBuilder, "banana");
    CHAR_TYPE.writeString(blockBuilder, "banana");
    CHAR_TYPE.writeString(blockBuilder, "banana");
    CHAR_TYPE.writeString(blockBuilder, "banana");
    CHAR_TYPE.writeString(blockBuilder, "cherry");
    CHAR_TYPE.writeString(blockBuilder, "cherry");
    CHAR_TYPE.writeString(blockBuilder, "date");
    return blockBuilder.build();
}
Also used : BlockBuilder(io.prestosql.spi.block.BlockBuilder)

Example 30 with BlockBuilder

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

the class TestIntegerArrayType method createTestBlock.

public static Block createTestBlock(Type arrayType) {
    BlockBuilder blockBuilder = arrayType.createBlockBuilder(null, 4);
    arrayType.writeObject(blockBuilder, arrayBlockOf(INTEGER, 1, 2));
    arrayType.writeObject(blockBuilder, arrayBlockOf(INTEGER, 1, 2, 3));
    arrayType.writeObject(blockBuilder, arrayBlockOf(INTEGER, 1, 2, 3));
    arrayType.writeObject(blockBuilder, arrayBlockOf(INTEGER, 100, 200, 300));
    return blockBuilder.build();
}
Also used : BlockBuilder(io.prestosql.spi.block.BlockBuilder)

Aggregations

BlockBuilder (io.prestosql.spi.block.BlockBuilder)440 Block (io.prestosql.spi.block.Block)100 Test (org.testng.annotations.Test)84 Slice (io.airlift.slice.Slice)80 Type (io.prestosql.spi.type.Type)78 Page (io.prestosql.spi.Page)52 SqlType (io.prestosql.spi.function.SqlType)42 ArrayType (io.prestosql.spi.type.ArrayType)38 Map (java.util.Map)36 RowType (io.prestosql.spi.type.RowType)34 MapType (io.prestosql.spi.type.MapType)31 List (java.util.List)26 PageBuilder (io.prestosql.spi.PageBuilder)24 TimestampType (io.prestosql.spi.type.TimestampType)24 ImmutableList (com.google.common.collect.ImmutableList)23 PrestoException (io.prestosql.spi.PrestoException)23 BigintType (io.prestosql.spi.type.BigintType)23 BooleanType (io.prestosql.spi.type.BooleanType)21 DoubleType (io.prestosql.spi.type.DoubleType)21 UsedByGeneratedCode (io.prestosql.spi.annotation.UsedByGeneratedCode)20