Search in sources :

Example 1 with ConnectorSplit

use of com.facebook.presto.spi.ConnectorSplit in project presto by prestodb.

the class AccumuloSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layout) {
    AccumuloTableLayoutHandle layoutHandle = (AccumuloTableLayoutHandle) layout;
    AccumuloTableHandle tableHandle = layoutHandle.getTable();
    String schemaName = tableHandle.getSchema();
    String tableName = tableHandle.getTable();
    String rowIdName = tableHandle.getRowId();
    // Get non-row ID column constraints
    List<AccumuloColumnConstraint> constraints = getColumnConstraints(rowIdName, layoutHandle.getConstraint());
    // Get the row domain column range
    Optional<Domain> rDom = getRangeDomain(rowIdName, layoutHandle.getConstraint());
    // Call out to our client to retrieve all tablet split metadata using the row ID domain and the secondary index
    List<TabletSplitMetadata> tabletSplits = client.getTabletSplits(session, schemaName, tableName, rDom, constraints, tableHandle.getSerializerInstance());
    // Pack the tablet split metadata into a connector split
    ImmutableList.Builder<ConnectorSplit> cSplits = ImmutableList.builder();
    for (TabletSplitMetadata splitMetadata : tabletSplits) {
        AccumuloSplit split = new AccumuloSplit(connectorId, schemaName, tableName, rowIdName, tableHandle.getSerializerClassName(), splitMetadata.getRanges().stream().map(WrappedRange::new).collect(Collectors.toList()), constraints, tableHandle.getScanAuthorizations(), splitMetadata.getHostPort());
        cSplits.add(split);
    }
    return new FixedSplitSource(cSplits.build());
}
Also used : AccumuloColumnConstraint(com.facebook.presto.accumulo.model.AccumuloColumnConstraint) ImmutableList(com.google.common.collect.ImmutableList) TabletSplitMetadata(com.facebook.presto.accumulo.model.TabletSplitMetadata) AccumuloSplit(com.facebook.presto.accumulo.model.AccumuloSplit) WrappedRange(com.facebook.presto.accumulo.model.WrappedRange) AccumuloTableLayoutHandle(com.facebook.presto.accumulo.model.AccumuloTableLayoutHandle) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) AccumuloTableHandle(com.facebook.presto.accumulo.model.AccumuloTableHandle) ColumnDomain(com.facebook.presto.spi.predicate.TupleDomain.ColumnDomain) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Example 2 with ConnectorSplit

use of com.facebook.presto.spi.ConnectorSplit in project presto by prestodb.

the class AtopSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layoutHandle) {
    AtopTableLayoutHandle handle = (AtopTableLayoutHandle) layoutHandle;
    AtopTableHandle table = handle.getTableHandle();
    List<ConnectorSplit> splits = new ArrayList<>();
    ZonedDateTime end = ZonedDateTime.now(timeZone);
    for (Node node : nodeManager.getWorkerNodes()) {
        ZonedDateTime start = end.minusDays(maxHistoryDays - 1).withHour(0).withMinute(0).withSecond(0).withNano(0);
        while (start.isBefore(end)) {
            ZonedDateTime splitEnd = start.withHour(23).withMinute(59).withSecond(59).withNano(0);
            Domain splitDomain = Domain.create(ValueSet.ofRanges(Range.range(TIMESTAMP_WITH_TIME_ZONE, 1000 * start.toEpochSecond(), true, 1000 * splitEnd.toEpochSecond(), true)), false);
            if (handle.getStartTimeConstraint().overlaps(splitDomain) && handle.getEndTimeConstraint().overlaps(splitDomain)) {
                splits.add(new AtopSplit(table.getTable(), node.getHostAndPort(), start.toEpochSecond(), start.getZone()));
            }
            start = start.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
        }
    }
    return new FixedSplitSource(splits);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) Node(com.facebook.presto.spi.Node) ArrayList(java.util.ArrayList) Domain(com.facebook.presto.spi.predicate.Domain) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Example 3 with ConnectorSplit

use of com.facebook.presto.spi.ConnectorSplit in project presto by prestodb.

the class HiveSplitSource method addToQueue.

CompletableFuture<?> addToQueue(Iterator<? extends ConnectorSplit> splits) {
    CompletableFuture<?> lastResult = CompletableFuture.completedFuture(null);
    while (splits.hasNext()) {
        ConnectorSplit split = splits.next();
        lastResult = addToQueue(split);
    }
    return lastResult;
}
Also used : ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Example 4 with ConnectorSplit

use of com.facebook.presto.spi.ConnectorSplit in project presto by prestodb.

the class ExampleSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle handle, ConnectorSession session, ConnectorTableLayoutHandle layout) {
    ExampleTableLayoutHandle layoutHandle = (ExampleTableLayoutHandle) layout;
    ExampleTableHandle tableHandle = layoutHandle.getTable();
    ExampleTable table = exampleClient.getTable(tableHandle.getSchemaName(), tableHandle.getTableName());
    // this can happen if table is removed during a query
    checkState(table != null, "Table %s.%s no longer exists", tableHandle.getSchemaName(), tableHandle.getTableName());
    List<ConnectorSplit> splits = new ArrayList<>();
    for (URI uri : table.getSources()) {
        splits.add(new ExampleSplit(connectorId, tableHandle.getSchemaName(), tableHandle.getTableName(), uri));
    }
    Collections.shuffle(splits);
    return new FixedSplitSource(splits);
}
Also used : FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) ArrayList(java.util.ArrayList) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) URI(java.net.URI)

Example 5 with ConnectorSplit

use of com.facebook.presto.spi.ConnectorSplit in project presto by prestodb.

the class TestHiveSplitSource method testReaderWaitsForSplits.

@Test
public void testReaderWaitsForSplits() throws Exception {
    final HiveSplitSource hiveSplitSource = new HiveSplitSource(10, new TestingHiveSplitLoader(), Executors.newFixedThreadPool(5));
    final SettableFuture<ConnectorSplit> splits = SettableFuture.create();
    // create a thread that will get a split
    final CountDownLatch started = new CountDownLatch(1);
    Thread getterThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                started.countDown();
                List<ConnectorSplit> batch = getFutureValue(hiveSplitSource.getNextBatch(1));
                assertEquals(batch.size(), 1);
                splits.set(batch.get(0));
            } catch (Throwable e) {
                splits.setException(e);
            }
        }
    });
    getterThread.start();
    try {
        // wait for the thread to be started
        assertTrue(started.await(1, TimeUnit.SECONDS));
        // sleep for a bit, and assure the thread is blocked
        TimeUnit.MILLISECONDS.sleep(200);
        assertTrue(!splits.isDone());
        // add a split
        hiveSplitSource.addToQueue(new TestSplit(33));
        // wait for thread to get the split
        ConnectorSplit split = splits.get(200, TimeUnit.MILLISECONDS);
        assertSame(split.getInfo(), 33);
    } finally {
        // make sure the thread exits
        getterThread.interrupt();
    }
}
Also used : List(java.util.List) CountDownLatch(java.util.concurrent.CountDownLatch) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) Test(org.testng.annotations.Test)

Aggregations

ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)31 ColumnHandle (com.facebook.presto.spi.ColumnHandle)15 ImmutableList (com.google.common.collect.ImmutableList)15 Test (org.testng.annotations.Test)13 ConnectorSession (com.facebook.presto.spi.ConnectorSession)11 ConnectorSplitSource (com.facebook.presto.spi.ConnectorSplitSource)11 FixedSplitSource (com.facebook.presto.spi.FixedSplitSource)10 List (java.util.List)10 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)9 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)9 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)9 Constraint (com.facebook.presto.spi.Constraint)9 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)8 TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)8 MaterializedResult (com.facebook.presto.testing.MaterializedResult)8 MaterializedRow (com.facebook.presto.testing.MaterializedRow)8 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)8 ConnectorTableLayoutResult (com.facebook.presto.spi.ConnectorTableLayoutResult)7 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)7 ConnectorSplitManager (com.facebook.presto.spi.connector.ConnectorSplitManager)7