Search in sources :

Example 21 with ConnectorSplitSource

use of io.prestosql.spi.connector.ConnectorSplitSource in project incubator-pulsar by apache.

the class TestPulsarSplitManager method testGetSplitNonSchema.

@Test(dataProvider = "rewriteNamespaceDelimiter", singleThreaded = true)
public void testGetSplitNonSchema(String delimiter) throws Exception {
    updateRewriteNamespaceDelimiterIfNeeded(delimiter);
    TopicName topicName = NON_SCHEMA_TOPIC;
    setup();
    log.info("!----- topic: %s -----!", topicName);
    PulsarTableHandle pulsarTableHandle = new PulsarTableHandle(pulsarConnectorId.toString(), topicName.getNamespace(), topicName.getLocalName(), topicName.getLocalName());
    Map<ColumnHandle, Domain> domainMap = new HashMap<>();
    TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(domainMap);
    PulsarTableLayoutHandle pulsarTableLayoutHandle = new PulsarTableLayoutHandle(pulsarTableHandle, tupleDomain);
    ConnectorSplitSource connectorSplitSource = this.pulsarSplitManager.getSplits(mock(ConnectorTransactionHandle.class), mock(ConnectorSession.class), pulsarTableLayoutHandle, null);
    assertNotNull(connectorSplitSource);
}
Also used : ColumnHandle(io.prestosql.spi.connector.ColumnHandle) HashMap(java.util.HashMap) ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ConnectorSplitSource(io.prestosql.spi.connector.ConnectorSplitSource) TupleDomain(io.prestosql.spi.predicate.TupleDomain) Domain(io.prestosql.spi.predicate.Domain) TopicName(org.apache.pulsar.common.naming.TopicName) Test(org.testng.annotations.Test)

Example 22 with ConnectorSplitSource

use of io.prestosql.spi.connector.ConnectorSplitSource in project incubator-pulsar by apache.

the class TestPulsarSplitManager method testTopic.

@Test(dataProvider = "rewriteNamespaceDelimiter", singleThreaded = true)
public void testTopic(String delimiter) throws Exception {
    updateRewriteNamespaceDelimiterIfNeeded(delimiter);
    List<TopicName> topics = new LinkedList<>();
    topics.addAll(topicNames.stream().filter(topicName -> !topicName.equals(NON_SCHEMA_TOPIC)).collect(Collectors.toList()));
    for (TopicName topicName : topics) {
        setup();
        log.info("!----- topic: %s -----!", topicName);
        PulsarTableHandle pulsarTableHandle = new PulsarTableHandle(pulsarConnectorId.toString(), topicName.getNamespace(), topicName.getLocalName(), topicName.getLocalName());
        PulsarTableLayoutHandle pulsarTableLayoutHandle = new PulsarTableLayoutHandle(pulsarTableHandle, TupleDomain.all());
        final ResultCaptor<Collection<PulsarSplit>> resultCaptor = new ResultCaptor<>();
        doAnswer(resultCaptor).when(this.pulsarSplitManager).getSplitsNonPartitionedTopic(anyInt(), any(), any(), any(), any(), any());
        ConnectorSplitSource connectorSplitSource = this.pulsarSplitManager.getSplits(mock(ConnectorTransactionHandle.class), mock(ConnectorSession.class), pulsarTableLayoutHandle, null);
        verify(this.pulsarSplitManager, times(1)).getSplitsNonPartitionedTopic(anyInt(), any(), any(), any(), any(), any());
        int totalSize = 0;
        for (PulsarSplit pulsarSplit : resultCaptor.getResult()) {
            assertEquals(pulsarSplit.getConnectorId(), pulsarConnectorId.toString());
            assertEquals(pulsarSplit.getSchemaName(), topicName.getNamespace());
            assertEquals(pulsarSplit.getTableName(), topicName.getLocalName());
            assertEquals(pulsarSplit.getSchema(), new String(topicsToSchemas.get(topicName.getSchemaName()).getSchema()));
            assertEquals(pulsarSplit.getSchemaType(), topicsToSchemas.get(topicName.getSchemaName()).getType());
            assertEquals(pulsarSplit.getStartPositionEntryId(), totalSize);
            assertEquals(pulsarSplit.getStartPositionLedgerId(), 0);
            assertEquals(pulsarSplit.getStartPosition(), PositionImpl.get(0, totalSize));
            assertEquals(pulsarSplit.getEndPositionLedgerId(), 0);
            assertEquals(pulsarSplit.getEndPositionEntryId(), totalSize + pulsarSplit.getSplitSize());
            assertEquals(pulsarSplit.getEndPosition(), PositionImpl.get(0, totalSize + pulsarSplit.getSplitSize()));
            totalSize += pulsarSplit.getSplitSize();
        }
        assertEquals(totalSize, topicsToNumEntries.get(topicName.getSchemaName()).intValue());
        cleanup();
    }
}
Also used : ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle) ConnectorSplitSource(io.prestosql.spi.connector.ConnectorSplitSource) LinkedList(java.util.LinkedList) TopicName(org.apache.pulsar.common.naming.TopicName) Collection(java.util.Collection) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Test(org.testng.annotations.Test)

Example 23 with ConnectorSplitSource

use of io.prestosql.spi.connector.ConnectorSplitSource in project pulsar by yahoo.

the class TestPulsarSplitManager method testTopic.

@Test(dataProvider = "rewriteNamespaceDelimiter", singleThreaded = true)
public void testTopic(String delimiter) throws Exception {
    updateRewriteNamespaceDelimiterIfNeeded(delimiter);
    List<TopicName> topics = new LinkedList<>();
    topics.addAll(topicNames.stream().filter(topicName -> !topicName.equals(NON_SCHEMA_TOPIC)).collect(Collectors.toList()));
    for (TopicName topicName : topics) {
        setup();
        log.info("!----- topic: %s -----!", topicName);
        PulsarTableHandle pulsarTableHandle = new PulsarTableHandle(pulsarConnectorId.toString(), topicName.getNamespace(), topicName.getLocalName(), topicName.getLocalName());
        PulsarTableLayoutHandle pulsarTableLayoutHandle = new PulsarTableLayoutHandle(pulsarTableHandle, TupleDomain.all());
        final ResultCaptor<Collection<PulsarSplit>> resultCaptor = new ResultCaptor<>();
        doAnswer(resultCaptor).when(this.pulsarSplitManager).getSplitsNonPartitionedTopic(anyInt(), any(), any(), any(), any(), any());
        ConnectorSplitSource connectorSplitSource = this.pulsarSplitManager.getSplits(mock(ConnectorTransactionHandle.class), mock(ConnectorSession.class), pulsarTableLayoutHandle, null);
        verify(this.pulsarSplitManager, times(1)).getSplitsNonPartitionedTopic(anyInt(), any(), any(), any(), any(), any());
        int totalSize = 0;
        for (PulsarSplit pulsarSplit : resultCaptor.getResult()) {
            assertEquals(pulsarSplit.getConnectorId(), pulsarConnectorId.toString());
            assertEquals(pulsarSplit.getSchemaName(), topicName.getNamespace());
            assertEquals(pulsarSplit.getTableName(), topicName.getLocalName());
            assertEquals(pulsarSplit.getSchema(), new String(topicsToSchemas.get(topicName.getSchemaName()).getSchema()));
            assertEquals(pulsarSplit.getSchemaType(), topicsToSchemas.get(topicName.getSchemaName()).getType());
            assertEquals(pulsarSplit.getStartPositionEntryId(), totalSize);
            assertEquals(pulsarSplit.getStartPositionLedgerId(), 0);
            assertEquals(pulsarSplit.getStartPosition(), PositionImpl.get(0, totalSize));
            assertEquals(pulsarSplit.getEndPositionLedgerId(), 0);
            assertEquals(pulsarSplit.getEndPositionEntryId(), totalSize + pulsarSplit.getSplitSize());
            assertEquals(pulsarSplit.getEndPosition(), PositionImpl.get(0, totalSize + pulsarSplit.getSplitSize()));
            totalSize += pulsarSplit.getSplitSize();
        }
        assertEquals(totalSize, topicsToNumEntries.get(topicName.getSchemaName()).intValue());
        cleanup();
    }
}
Also used : ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle) ConnectorSplitSource(io.prestosql.spi.connector.ConnectorSplitSource) LinkedList(java.util.LinkedList) TopicName(org.apache.pulsar.common.naming.TopicName) Collection(java.util.Collection) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Test(org.testng.annotations.Test)

Example 24 with ConnectorSplitSource

use of io.prestosql.spi.connector.ConnectorSplitSource in project pulsar by yahoo.

the class TestPulsarSplitManager method testPublishTimePredicatePushdown.

@Test(dataProvider = "rewriteNamespaceDelimiter", singleThreaded = true)
public void testPublishTimePredicatePushdown(String delimiter) throws Exception {
    updateRewriteNamespaceDelimiterIfNeeded(delimiter);
    TopicName topicName = TOPIC_1;
    setup();
    log.info("!----- topic: %s -----!", topicName);
    PulsarTableHandle pulsarTableHandle = new PulsarTableHandle(pulsarConnectorId.toString(), topicName.getNamespace(), topicName.getLocalName(), topicName.getLocalName());
    Map<ColumnHandle, Domain> domainMap = new HashMap<>();
    Domain domain = Domain.create(ValueSet.ofRanges(Range.range(TIMESTAMP, currentTimeMs + 1L, true, currentTimeMs + 50L, true)), false);
    domainMap.put(PulsarInternalColumn.PUBLISH_TIME.getColumnHandle(pulsarConnectorId.toString(), false), domain);
    TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(domainMap);
    PulsarTableLayoutHandle pulsarTableLayoutHandle = new PulsarTableLayoutHandle(pulsarTableHandle, tupleDomain);
    final ResultCaptor<Collection<PulsarSplit>> resultCaptor = new ResultCaptor<>();
    doAnswer(resultCaptor).when(this.pulsarSplitManager).getSplitsNonPartitionedTopic(anyInt(), any(), any(), any(), any(), any());
    ConnectorSplitSource connectorSplitSource = this.pulsarSplitManager.getSplits(mock(ConnectorTransactionHandle.class), mock(ConnectorSession.class), pulsarTableLayoutHandle, null);
    verify(this.pulsarSplitManager, times(1)).getSplitsNonPartitionedTopic(anyInt(), any(), any(), any(), any(), any());
    int totalSize = 0;
    int initalStart = 1;
    for (PulsarSplit pulsarSplit : resultCaptor.getResult()) {
        assertEquals(pulsarSplit.getConnectorId(), pulsarConnectorId.toString());
        assertEquals(pulsarSplit.getSchemaName(), topicName.getNamespace());
        assertEquals(pulsarSplit.getTableName(), topicName.getLocalName());
        assertEquals(pulsarSplit.getSchema(), new String(topicsToSchemas.get(topicName.getSchemaName()).getSchema()));
        assertEquals(pulsarSplit.getSchemaType(), topicsToSchemas.get(topicName.getSchemaName()).getType());
        assertEquals(pulsarSplit.getStartPositionEntryId(), initalStart);
        assertEquals(pulsarSplit.getStartPositionLedgerId(), 0);
        assertEquals(pulsarSplit.getStartPosition(), PositionImpl.get(0, initalStart));
        assertEquals(pulsarSplit.getEndPositionLedgerId(), 0);
        assertEquals(pulsarSplit.getEndPositionEntryId(), initalStart + pulsarSplit.getSplitSize());
        assertEquals(pulsarSplit.getEndPosition(), PositionImpl.get(0, initalStart + pulsarSplit.getSplitSize()));
        initalStart += pulsarSplit.getSplitSize();
        totalSize += pulsarSplit.getSplitSize();
    }
    assertEquals(totalSize, 49);
}
Also used : ColumnHandle(io.prestosql.spi.connector.ColumnHandle) HashMap(java.util.HashMap) ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle) ConnectorSplitSource(io.prestosql.spi.connector.ConnectorSplitSource) TopicName(org.apache.pulsar.common.naming.TopicName) Collection(java.util.Collection) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) TupleDomain(io.prestosql.spi.predicate.TupleDomain) Domain(io.prestosql.spi.predicate.Domain) Test(org.testng.annotations.Test)

Example 25 with ConnectorSplitSource

use of io.prestosql.spi.connector.ConnectorSplitSource in project pulsar by apache.

the class TestPulsarSplitManager method testGetSplitNonSchema.

@Test(dataProvider = "rewriteNamespaceDelimiter", singleThreaded = true)
public void testGetSplitNonSchema(String delimiter) throws Exception {
    updateRewriteNamespaceDelimiterIfNeeded(delimiter);
    TopicName topicName = NON_SCHEMA_TOPIC;
    setup();
    log.info("!----- topic: %s -----!", topicName);
    PulsarTableHandle pulsarTableHandle = new PulsarTableHandle(pulsarConnectorId.toString(), topicName.getNamespace(), topicName.getLocalName(), topicName.getLocalName());
    Map<ColumnHandle, Domain> domainMap = new HashMap<>();
    TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(domainMap);
    PulsarTableLayoutHandle pulsarTableLayoutHandle = new PulsarTableLayoutHandle(pulsarTableHandle, tupleDomain);
    ConnectorSplitSource connectorSplitSource = this.pulsarSplitManager.getSplits(mock(ConnectorTransactionHandle.class), mock(ConnectorSession.class), pulsarTableLayoutHandle, null);
    assertNotNull(connectorSplitSource);
}
Also used : ColumnHandle(io.prestosql.spi.connector.ColumnHandle) HashMap(java.util.HashMap) ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ConnectorSplitSource(io.prestosql.spi.connector.ConnectorSplitSource) TupleDomain(io.prestosql.spi.predicate.TupleDomain) Domain(io.prestosql.spi.predicate.Domain) TopicName(org.apache.pulsar.common.naming.TopicName) Test(org.testng.annotations.Test)

Aggregations

ConnectorSplitSource (io.prestosql.spi.connector.ConnectorSplitSource)45 Test (org.testng.annotations.Test)36 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)27 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)19 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)18 ConnectorSplit (io.prestosql.spi.connector.ConnectorSplit)17 ConnectorTransactionHandle (io.prestosql.spi.connector.ConnectorTransactionHandle)17 BaseJdbcConfig (io.prestosql.plugin.jdbc.BaseJdbcConfig)14 ConnectorTableHandle (io.prestosql.spi.connector.ConnectorTableHandle)14 TupleDomain (io.prestosql.spi.predicate.TupleDomain)13 TopicName (org.apache.pulsar.common.naming.TopicName)12 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)10 TestingConnectorSession (io.prestosql.testing.TestingConnectorSession)10 HashMap (java.util.HashMap)10 Collection (java.util.Collection)9 Domain (io.prestosql.spi.predicate.Domain)7 JdbcSplit (io.prestosql.plugin.jdbc.JdbcSplit)6 ConnectorPageSource (io.prestosql.spi.connector.ConnectorPageSource)6 PrestoException (io.prestosql.spi.PrestoException)5 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)5