use of com.facebook.presto.thrift.api.connector.PrestoThriftId in project presto by prestodb.
the class ThriftTpchService method getRowsInternal.
private static PrestoThriftPageResult getRowsInternal(ConnectorPageSource pageSource, String tableName, List<String> columnNames, @Nullable PrestoThriftId nextToken) {
// very inefficient implementation as it needs to re-generate all previous results to get the next page
int skipPages = nextToken != null ? Ints.fromByteArray(nextToken.getId()) : 0;
skipPages(pageSource, skipPages);
Page page = null;
while (!pageSource.isFinished() && page == null) {
page = pageSource.getNextPage();
skipPages++;
}
PrestoThriftId newNextToken = pageSource.isFinished() ? null : new PrestoThriftId(Ints.toByteArray(skipPages));
return toThriftPage(page, types(tableName, columnNames), newNextToken);
}
use of com.facebook.presto.thrift.api.connector.PrestoThriftId in project presto by prestodb.
the class ThriftTpchService method getSplitsSync.
private static PrestoThriftSplitBatch getSplitsSync(PrestoThriftSchemaTableName schemaTableName, int maxSplitCount, PrestoThriftNullableToken nextToken) {
int totalParts = DEFAULT_NUMBER_OF_SPLITS;
// last sent part
int partNumber = nextToken.getToken() == null ? 0 : Ints.fromByteArray(nextToken.getToken().getId());
int numberOfSplits = min(maxSplitCount, totalParts - partNumber);
List<PrestoThriftSplit> splits = new ArrayList<>(numberOfSplits);
for (int i = 0; i < numberOfSplits; i++) {
SplitInfo splitInfo = normalSplit(schemaTableName.getSchemaName(), schemaTableName.getTableName(), partNumber + 1, totalParts);
splits.add(new PrestoThriftSplit(new PrestoThriftId(SPLIT_INFO_CODEC.toJsonBytes(splitInfo)), ImmutableList.of()));
partNumber++;
}
PrestoThriftId newNextToken = partNumber < totalParts ? new PrestoThriftId(Ints.toByteArray(partNumber)) : null;
return new PrestoThriftSplitBatch(splits, newNextToken);
}
use of com.facebook.presto.thrift.api.connector.PrestoThriftId in project presto by prestodb.
the class TestThriftIndexPageSource method testGetNextPageTwoConcurrentRequests.
@Test
public void testGetNextPageTwoConcurrentRequests() throws Exception {
final int splits = 3;
final int lookupRequestsConcurrency = 2;
final int rowsPerSplit = 1;
List<SettableFuture<PrestoThriftPageResult>> futures = IntStream.range(0, splits).mapToObj(i -> SettableFuture.<PrestoThriftPageResult>create()).collect(toImmutableList());
List<CountDownLatch> signals = IntStream.range(0, splits).mapToObj(i -> new CountDownLatch(1)).collect(toImmutableList());
TestingThriftService client = new TestingThriftService(rowsPerSplit, false, false) {
@Override
public ListenableFuture<PrestoThriftPageResult> getRows(PrestoThriftId splitId, List<String> columns, long maxBytes, PrestoThriftNullableToken nextToken) {
int key = Ints.fromByteArray(splitId.getId());
signals.get(key).countDown();
return futures.get(key);
}
};
ThriftConnectorStats stats = new ThriftConnectorStats();
long pageSizeReceived = 0;
ThriftIndexPageSource pageSource = new ThriftIndexPageSource((context, headers) -> client, ImmutableMap.of(), stats, new ThriftIndexHandle(new SchemaTableName("default", "table1"), TupleDomain.all()), ImmutableList.of(column("a", INTEGER)), ImmutableList.of(column("b", INTEGER)), new InMemoryRecordSet(ImmutableList.of(INTEGER), generateKeys(0, splits)), MAX_BYTES_PER_RESPONSE, lookupRequestsConcurrency);
assertNull(pageSource.getNextPage());
assertEquals((long) stats.getIndexPageSize().getAllTime().getTotal(), 0);
signals.get(0).await(1, SECONDS);
signals.get(1).await(1, SECONDS);
signals.get(2).await(1, SECONDS);
assertEquals(signals.get(0).getCount(), 0, "first request wasn't sent");
assertEquals(signals.get(1).getCount(), 0, "second request wasn't sent");
assertEquals(signals.get(2).getCount(), 1, "third request shouldn't be sent");
// at this point first two requests were sent
assertFalse(pageSource.isFinished());
assertNull(pageSource.getNextPage());
assertEquals((long) stats.getIndexPageSize().getAllTime().getTotal(), 0);
// completing the second request
futures.get(1).set(pageResult(20, null));
Page page = pageSource.getNextPage();
pageSizeReceived += page.getSizeInBytes();
assertEquals((long) stats.getIndexPageSize().getAllTime().getTotal(), pageSizeReceived);
assertNotNull(page);
assertEquals(page.getPositionCount(), 1);
assertEquals(page.getBlock(0).getInt(0), 20);
// not complete yet
assertFalse(pageSource.isFinished());
// once one of the requests completes the next one should be sent
signals.get(2).await(1, SECONDS);
assertEquals(signals.get(2).getCount(), 0, "third request wasn't sent");
// completing the first request
futures.get(0).set(pageResult(10, null));
page = pageSource.getNextPage();
assertNotNull(page);
pageSizeReceived += page.getSizeInBytes();
assertEquals((long) stats.getIndexPageSize().getAllTime().getTotal(), pageSizeReceived);
assertEquals(page.getPositionCount(), 1);
assertEquals(page.getBlock(0).getInt(0), 10);
// still not complete
assertFalse(pageSource.isFinished());
// completing the third request
futures.get(2).set(pageResult(30, null));
page = pageSource.getNextPage();
assertNotNull(page);
pageSizeReceived += page.getSizeInBytes();
assertEquals((long) stats.getIndexPageSize().getAllTime().getTotal(), pageSizeReceived);
assertEquals(page.getPositionCount(), 1);
assertEquals(page.getBlock(0).getInt(0), 30);
// finished now
assertTrue(pageSource.isFinished());
// after completion
assertNull(pageSource.getNextPage());
pageSource.close();
}
use of com.facebook.presto.thrift.api.connector.PrestoThriftId in project presto by prestodb.
the class ThriftIndexedTpchService method getIndexSplitsSync.
@Override
protected PrestoThriftSplitBatch getIndexSplitsSync(PrestoThriftSchemaTableName schemaTableName, List<String> indexColumnNames, PrestoThriftPageResult keys, int maxSplitCount, PrestoThriftNullableToken nextToken) throws PrestoThriftServiceException {
checkArgument(NUMBER_OF_INDEX_SPLITS <= maxSplitCount, "maxSplitCount for lookup splits is too low");
checkArgument(nextToken.getToken() == null, "no continuation is supported for lookup splits");
int totalKeys = keys.getRowCount();
int partSize = totalKeys / NUMBER_OF_INDEX_SPLITS;
List<PrestoThriftSplit> splits = new ArrayList<>(NUMBER_OF_INDEX_SPLITS);
for (int splitIndex = 0; splitIndex < NUMBER_OF_INDEX_SPLITS; splitIndex++) {
int begin = partSize * splitIndex;
int end = partSize * (splitIndex + 1);
if (splitIndex + 1 == NUMBER_OF_INDEX_SPLITS) {
// add remainder to the last split
end = totalKeys;
}
if (begin == end) {
// split is empty, skip it
continue;
}
SplitInfo splitInfo = indexSplit(schemaTableName.getSchemaName(), schemaTableName.getTableName(), indexColumnNames, thriftPageToList(keys, begin, end));
splits.add(new PrestoThriftSplit(new PrestoThriftId(SPLIT_INFO_CODEC.toJsonBytes(splitInfo)), ImmutableList.of()));
}
return new PrestoThriftSplitBatch(splits, null);
}
Aggregations