Search in sources :

Example 76 with MapType

use of com.facebook.presto.common.type.MapType in project presto by prestodb.

the class TestSingleMapBlockWriter method testSizeInBytes.

@Test
public void testSizeInBytes() {
    MapType innerMapType = new MapType(BIGINT, VARCHAR, MethodHandleUtil.methodHandle(TestSingleMapBlockWriter.class, "throwUnsupportedOperation"), MethodHandleUtil.methodHandle(TestSingleMapBlockWriter.class, "throwUnsupportedOperation"));
    MapType mapType = new MapType(BIGINT, innerMapType, MethodHandleUtil.methodHandle(TestSingleMapBlockWriter.class, "throwUnsupportedOperation"), MethodHandleUtil.methodHandle(TestSingleMapBlockWriter.class, "throwUnsupportedOperation"));
    MapBlockBuilder mapBlockBuilder = (MapBlockBuilder) mapType.createBlockBuilder(null, MAP_POSITIONS);
    for (int i = 0; i < MAP_POSITIONS; i++) {
        SingleMapBlockWriter singleMapBlockWriter = mapBlockBuilder.beginBlockEntry();
        int expectedSize = 0;
        for (int j = 0; j < 10; j++) {
            assertEquals(singleMapBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
            // Write Map's Key (long + isNull)
            BIGINT.writeLong(singleMapBlockWriter, j);
            expectedSize += 9;
            assertEquals(singleMapBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
            // Write Map<Bigint, Varchar>
            BlockBuilder innerMapWriter = singleMapBlockWriter.beginBlockEntry();
            // Opening entry, does not account for size.
            assertEquals(singleMapBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
            // Each entry is of 28 bytes, with 6 byte value.
            BIGINT.writeLong(innerMapWriter, i * 2);
            VARCHAR.writeSlice(innerMapWriter, utf8Slice("Value1"));
            expectedSize += 28;
            assertEquals(singleMapBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
            // Another entry with 28 bytes.
            BIGINT.writeLong(innerMapWriter, i * 2 + 1);
            VARCHAR.writeSlice(innerMapWriter, utf8Slice("Value2"));
            expectedSize += 28;
            assertEquals(singleMapBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
            // closing the entry increases by 5 (offset + null)
            singleMapBlockWriter.closeEntry();
            expectedSize += 5;
            assertEquals(singleMapBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        }
        mapBlockBuilder.closeEntry();
        assertEquals(singleMapBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        // Introduce some null elements in Map and the size should still work.
        mapBlockBuilder.appendNull();
    }
}
Also used : MapType(com.facebook.presto.common.type.MapType) Test(org.testng.annotations.Test)

Example 77 with MapType

use of com.facebook.presto.common.type.MapType in project presto by prestodb.

the class TestSingleArrayBlockWriter method testSizeInBytesForNulls.

@Test
public void testSizeInBytesForNulls() {
    MapType mapType = new MapType(BIGINT, VARCHAR, MethodHandleUtil.methodHandle(TestSingleArrayBlockWriter.class, "throwUnsupportedOperation"), MethodHandleUtil.methodHandle(TestSingleArrayBlockWriter.class, "throwUnsupportedOperation"));
    ArrayBlockBuilder arrayBlockBuilder = new ArrayBlockBuilder(mapType, null, ARRAY_POSITIONS);
    for (int i = 0; i < ARRAY_POSITIONS; i++) {
        SingleArrayBlockWriter singleArrayBlockWriter = arrayBlockBuilder.beginBlockEntry();
        int expectedSize = 0;
        for (int j = 0; j < 10; j++) {
            assertEquals(singleArrayBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
            singleArrayBlockWriter.appendNull();
            expectedSize += 5;
            assertEquals(singleArrayBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        }
        arrayBlockBuilder.closeEntry();
        assertEquals(singleArrayBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
    }
}
Also used : MapType(com.facebook.presto.common.type.MapType) Test(org.testng.annotations.Test)

Example 78 with MapType

use of com.facebook.presto.common.type.MapType in project presto by prestodb.

the class TestSingleArrayBlockWriter method testSizeInBytes.

@Test
public void testSizeInBytes() {
    MapType mapType = new MapType(BIGINT, VARCHAR, MethodHandleUtil.methodHandle(TestSingleArrayBlockWriter.class, "throwUnsupportedOperation"), MethodHandleUtil.methodHandle(TestSingleArrayBlockWriter.class, "throwUnsupportedOperation"));
    ArrayBlockBuilder arrayBlockBuilder = new ArrayBlockBuilder(mapType, null, ARRAY_POSITIONS);
    for (int i = 0; i < ARRAY_POSITIONS; i++) {
        SingleArrayBlockWriter singleArrayBlockWriter = arrayBlockBuilder.beginBlockEntry();
        int expectedSize = 0;
        for (int j = 0; j < 10; j++) {
            assertEquals(singleArrayBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
            // Write Map<Bigint, Varchar>
            BlockBuilder innerMapWriter = singleArrayBlockWriter.beginBlockEntry();
            // Opening entry, does not account for size.
            assertEquals(singleArrayBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
            // Each entry is of 28 bytes, with 6 byte value.
            BIGINT.writeLong(innerMapWriter, i * 2);
            VARCHAR.writeSlice(innerMapWriter, utf8Slice("Value1"));
            expectedSize += 28;
            assertEquals(singleArrayBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
            // Another entry with 28 bytes.
            BIGINT.writeLong(innerMapWriter, i * 2 + 1);
            VARCHAR.writeSlice(innerMapWriter, utf8Slice("Value2"));
            expectedSize += 28;
            assertEquals(singleArrayBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
            // closing the entry increases by 5 (offset + null)
            singleArrayBlockWriter.closeEntry();
            expectedSize += 5;
            assertEquals(singleArrayBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        }
        singleArrayBlockWriter.appendNull();
        expectedSize += 5;
        assertEquals(singleArrayBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        arrayBlockBuilder.closeEntry();
        assertEquals(singleArrayBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
    }
}
Also used : MapType(com.facebook.presto.common.type.MapType) Test(org.testng.annotations.Test)

Example 79 with MapType

use of com.facebook.presto.common.type.MapType in project presto by prestodb.

the class TestSingleRowBlockWriter method testSizeInBytes.

@Test
public void testSizeInBytes() {
    MapType mapType = new MapType(BIGINT, VARCHAR, MethodHandleUtil.methodHandle(TestSingleRowBlockWriter.class, "throwUnsupportedOperation"), MethodHandleUtil.methodHandle(TestSingleRowBlockWriter.class, "throwUnsupportedOperation"));
    ArrayType arrayType = new ArrayType(DOUBLE);
    RowType.Field rowField = new RowType.Field(Optional.of("my_struct"), INTEGER);
    RowType rowType = RowType.from(ImmutableList.of(rowField));
    List<Type> fieldTypes = ImmutableList.of(REAL, mapType, arrayType, rowType);
    RowBlockBuilder rowBlockBuilder = new RowBlockBuilder(fieldTypes, null, 1);
    for (int i = 0; i < 100; i++) {
        SingleRowBlockWriter singleRowBlockWriter = rowBlockBuilder.beginBlockEntry();
        int expectedSize = 0;
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        // Write real (4byte value + 1 byte for null)
        REAL.writeLong(singleRowBlockWriter, i);
        expectedSize += 5;
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        // Write Map<Bigint, Varchar>
        BlockBuilder mapWriter = singleRowBlockWriter.beginBlockEntry();
        // Opening entry, does not account for size.
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        // Each entry is of 28 bytes, with 6 byte value.
        BIGINT.writeLong(mapWriter, i * 2);
        VARCHAR.writeSlice(mapWriter, utf8Slice("Value1"));
        expectedSize += 28;
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        // Another entry with 28 bytes.
        BIGINT.writeLong(mapWriter, i * 2 + 1);
        VARCHAR.writeSlice(mapWriter, utf8Slice("Value2"));
        expectedSize += 28;
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        // closing the entry increases by 5 (offset + null)
        singleRowBlockWriter.closeEntry();
        expectedSize += 5;
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        // Write array entry.
        BlockBuilder arrayWriter = singleRowBlockWriter.beginBlockEntry();
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        // Each entry is 9 bytes ( 8 bytes for double , 1 byte for null)
        DOUBLE.writeDouble(arrayWriter, i * 3);
        expectedSize += 9;
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        DOUBLE.writeDouble(arrayWriter, i * 3 + 1);
        expectedSize += 9;
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        singleRowBlockWriter.closeEntry();
        // closing the entry increases by 5 (offset + null)
        expectedSize += 5;
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        // Write row type.
        BlockBuilder rowWriter = singleRowBlockWriter.beginBlockEntry();
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        rowWriter.appendNull();
        expectedSize += 5;
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        singleRowBlockWriter.closeEntry();
        expectedSize += 5;
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        rowBlockBuilder.closeEntry();
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        rowBlockBuilder.appendNull();
    }
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) MapType(com.facebook.presto.common.type.MapType) ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) RowType(com.facebook.presto.common.type.RowType) RowType(com.facebook.presto.common.type.RowType) MapType(com.facebook.presto.common.type.MapType) Test(org.testng.annotations.Test)

Example 80 with MapType

use of com.facebook.presto.common.type.MapType in project presto by prestodb.

the class TestSingleRowBlockWriter method testSizeInBytesForNulls.

@Test
public void testSizeInBytesForNulls() {
    MapType mapType = new MapType(BIGINT, VARCHAR, MethodHandleUtil.methodHandle(TestSingleRowBlockWriter.class, "throwUnsupportedOperation"), MethodHandleUtil.methodHandle(TestSingleRowBlockWriter.class, "throwUnsupportedOperation"));
    ArrayType arrayType = new ArrayType(DOUBLE);
    RowType.Field rowField = new RowType.Field(Optional.of("my_struct"), INTEGER);
    RowType rowType = RowType.from(ImmutableList.of(rowField));
    List<Type> fieldTypes = ImmutableList.of(REAL, mapType, arrayType, rowType);
    RowBlockBuilder rowBlockBuilder = new RowBlockBuilder(fieldTypes, null, 1);
    for (int i = 0; i < 100; i++) {
        SingleRowBlockWriter singleRowBlockWriter = rowBlockBuilder.beginBlockEntry();
        int expectedSize = 0;
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize);
        // Write real (4byte value + 1 byte for null)
        singleRowBlockWriter.appendNull();
        expectedSize += 5;
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        // Write Map<Bigint, Varchar>
        singleRowBlockWriter.appendNull();
        expectedSize += 5;
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        // Write array entry.
        singleRowBlockWriter.appendNull();
        expectedSize += 5;
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        // Write row type.
        singleRowBlockWriter.appendNull();
        expectedSize += 5;
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        rowBlockBuilder.closeEntry();
        assertEquals(singleRowBlockWriter.getSizeInBytes(), expectedSize, "For Index: " + i);
        rowBlockBuilder.appendNull();
    }
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) MapType(com.facebook.presto.common.type.MapType) ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) RowType(com.facebook.presto.common.type.RowType) RowType(com.facebook.presto.common.type.RowType) MapType(com.facebook.presto.common.type.MapType) Test(org.testng.annotations.Test)

Aggregations

MapType (com.facebook.presto.common.type.MapType)92 Type (com.facebook.presto.common.type.Type)49 ArrayType (com.facebook.presto.common.type.ArrayType)40 Test (org.testng.annotations.Test)32 RowType (com.facebook.presto.common.type.RowType)30 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)24 Block (com.facebook.presto.common.block.Block)21 HashMap (java.util.HashMap)12 DecimalType (com.facebook.presto.common.type.DecimalType)11 ImmutableList (com.google.common.collect.ImmutableList)11 List (java.util.List)11 Map (java.util.Map)11 VarcharType (com.facebook.presto.common.type.VarcharType)9 MethodHandle (java.lang.invoke.MethodHandle)9 ArrayList (java.util.ArrayList)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 SingleMapBlock (com.facebook.presto.common.block.SingleMapBlock)7 PrestoException (com.facebook.presto.spi.PrestoException)7 OperatorType (com.facebook.presto.common.function.OperatorType)6 MapBlockBuilder (com.facebook.presto.common.block.MapBlockBuilder)5