use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class MaterializedResult method appendToPage.
private static void appendToPage(PageBuilder pageBuilder, MaterializedRow row) {
for (int field = 0; field < row.getFieldCount(); field++) {
Type type = pageBuilder.getType(field);
Object value = row.getField(field);
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(field);
writeValue(type, blockBuilder, value);
}
pageBuilder.declarePosition();
}
use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class RowPageBuilder method append.
private void append(int channel, Object element) {
BlockBuilder blockBuilder = builders.get(channel);
Type type = types.get(channel);
appendToBlockBuilder(type, element, blockBuilder);
}
use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class SequencePageBuilder method createSequencePageWithDictionaryBlocks.
public static Page createSequencePageWithDictionaryBlocks(List<? extends Type> types, int length, int... initialValues) {
Block[] blocks = new Block[initialValues.length];
for (int i = 0; i < blocks.length; i++) {
Type type = types.get(i);
int initialValue = initialValues[i];
if (type.equals(VARCHAR)) {
blocks[i] = BlockAssertions.createStringDictionaryBlock(initialValue, initialValue + length);
} else if (type.equals(BIGINT)) {
blocks[i] = BlockAssertions.createLongDictionaryBlock(initialValue, initialValue + length);
} else {
throw new IllegalStateException("Unsupported type " + type);
}
}
return new Page(blocks);
}
use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class TestPagesIndexPageSorter method createOutputPages.
private static List<Page> createOutputPages(List<Type> types, List<Page> inputPages, long[] sortedAddresses) {
PageBuilder pageBuilder = new PageBuilder(types);
pageBuilder.reset();
for (long address : sortedAddresses) {
int index = sorter.decodePageIndex(address);
int position = sorter.decodePositionIndex(address);
Page page = inputPages.get(index);
for (int i = 0; i < types.size(); i++) {
Type type = types.get(i);
type.appendTo(page.getBlock(i), position, pageBuilder.getBlockBuilder(i));
}
pageBuilder.declarePosition();
}
return ImmutableList.of(pageBuilder.build());
}
use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class TestPageSplitterUtil method testSplitPage.
@Test
public void testSplitPage() throws Exception {
int positionCount = 10;
int maxPageSizeInBytes = 100;
List<Type> types = ImmutableList.of(BIGINT, BIGINT, BIGINT);
Page largePage = SequencePageBuilder.createSequencePage(types, positionCount, 0, 1, 1);
List<Page> pages = PageSplitterUtil.splitPage(largePage, maxPageSizeInBytes);
assertGreaterThan(pages.size(), 1);
assertPageSize(pages, maxPageSizeInBytes);
assertPositionCount(pages, positionCount);
MaterializedResult actual = toMaterializedResult(TEST_SESSION, types, pages);
MaterializedResult expected = toMaterializedResult(TEST_SESSION, types, ImmutableList.of(largePage));
assertEquals(actual, expected);
}
Aggregations