public static PrestoThriftPageResult fromRecordSet(RecordSet recordSet) { List<Type> types = recordSet.getColumnTypes(); int numberOfColumns = types.size(); int positions = totalRecords(recordSet); if (numberOfColumns == 0) { return new PrestoThriftPageResult(ImmutableList.of(), positions, null); } List<PrestoThriftBlock> thriftBlocks = new ArrayList<>(numberOfColumns); for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) { thriftBlocks.add(fromRecordSetColumn(recordSet, columnIndex, positions)); } return new PrestoThriftPageResult(thriftBlocks, positions, null); }
private static PrestoThriftPageResult toThriftPage(Page page, List<Type> columnTypes, @Nullable PrestoThriftId nextToken) { if (page == null) { checkState(nextToken == null, "there must be no more data when page is null"); return new PrestoThriftPageResult(ImmutableList.of(), 0, null); } checkState(page.getChannelCount() == columnTypes.size(), "number of columns in a page doesn't match the one in requested types"); int numberOfColumns = columnTypes.size(); List<PrestoThriftBlock> columnBlocks = new ArrayList<>(numberOfColumns); for (int i = 0; i < numberOfColumns; i++) { columnBlocks.add(fromBlock(page.getBlock(i), columnTypes.get(i))); } return new PrestoThriftPageResult(columnBlocks, page.getPositionCount(), nextToken); }
private void testPageReadWrite(Random random, int records) { testReadWrite(random, records, blocks -> { List<PrestoThriftBlock> columnBlocks = new ArrayList<>(columns.size()); for (int i = 0; i < columns.size(); i++) { columnBlocks.add(fromBlock(blocks.get(i), columns.get(i).getType())); } return new PrestoThriftPageResult(columnBlocks, records, null); }); }
private static PrestoThriftPageResult pageResult(int value, PrestoThriftId nextToken) { return new PrestoThriftPageResult(ImmutableList.of(integerData(new PrestoThriftInteger(null, new int[] {value}))), 1, nextToken); } }
@Override public ListenableFuture<PrestoThriftPageResult> getRows(PrestoThriftId splitId, List<String> columns, long maxBytes, PrestoThriftNullableToken nextToken) { if (rowsPerSplit == 0) { return immediateFuture(new PrestoThriftPageResult(ImmutableList.of(), 0, null)); } int key = Ints.fromByteArray(splitId.getId()); int offset = nextToken.getToken() != null ? Ints.fromByteArray(nextToken.getToken().getId()) : 0; PrestoThriftId newNextToken = offset + 1 < rowsPerSplit ? new PrestoThriftId(Ints.toByteArray(offset + 1)) : null; return immediateFuture(pageResult(key * 10 + offset, newNextToken)); }
private static PrestoThriftPageResult toThriftPage(Page page, List<Type> columnTypes, @Nullable PrestoThriftId nextToken) { if (page == null) { checkState(nextToken == null, "there must be no more data when page is null"); return new PrestoThriftPageResult(ImmutableList.of(), 0, null); } checkState(page.getChannelCount() == columnTypes.size(), "number of columns in a page doesn't match the one in requested types"); int numberOfColumns = columnTypes.size(); List<PrestoThriftBlock> columnBlocks = new ArrayList<>(numberOfColumns); for (int i = 0; i < numberOfColumns; i++) { columnBlocks.add(fromBlock(page.getBlock(i), columnTypes.get(i))); } return new PrestoThriftPageResult(columnBlocks, page.getPositionCount(), nextToken); }
private void testPageReadWrite(Random random, int records) { testReadWrite(random, records, blocks -> { List<PrestoThriftBlock> columnBlocks = new ArrayList<>(columns.size()); for (int i = 0; i < columns.size(); i++) { columnBlocks.add(fromBlock(blocks.get(i), columns.get(i).getType())); } return new PrestoThriftPageResult(columnBlocks, records, null); }); }