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();
}
}
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);
}
}
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);
}
}
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();
}
}
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();
}
}
Aggregations