private Operator createTableWriterOperator(BlockingPageSink blockingPageSink) {
    PageSinkManager pageSinkProvider = new PageSinkManager();
    pageSinkProvider.addConnectorPageSinkProvider(
        CONNECTOR_ID, new ConstantPageSinkProvider(blockingPageSink));

    TableWriterOperator.TableWriterOperatorFactory factory =
        new TableWriterOperator.TableWriterOperatorFactory(
            0,
            new PlanNodeId("test"),
            pageSinkProvider,
            new TableWriterNode.CreateHandle(
                new OutputTableHandle(
                    CONNECTOR_ID,
                    new ConnectorTransactionHandle() {},
                    new ConnectorOutputTableHandle() {})),
            ImmutableList.of(0),
            Optional.empty(),
            TEST_SESSION);

    return factory.createOperator(
        createTaskContext(executor, TEST_SESSION)
            .addPipelineContext(true, true)
            .addDriverContext());
  }
Beispiel #2
0
  private void addConnector(String catalogName, String connectorId, Connector connector) {
    ConnectorMetadata connectorMetadata = connector.getMetadata();
    checkState(connectorMetadata != null, "Connector %s can not provide metadata", connectorId);

    ConnectorSplitManager connectorSplitManager = connector.getSplitManager();
    checkState(
        connectorSplitManager != null, "Connector %s does not have a split manager", connectorId);

    ConnectorPageSourceProvider connectorPageSourceProvider = null;
    try {
      connectorPageSourceProvider = connector.getPageSourceProvider();
      checkNotNull(
          connectorPageSourceProvider,
          "Connector %s returned a null page source provider",
          connectorId);
    } catch (UnsupportedOperationException ignored) {
    }

    if (connectorPageSourceProvider == null) {
      ConnectorRecordSetProvider connectorRecordSetProvider = null;
      try {
        connectorRecordSetProvider = connector.getRecordSetProvider();
        checkNotNull(
            connectorRecordSetProvider,
            "Connector %s returned a null record set provider",
            connectorId);
      } catch (UnsupportedOperationException ignored) {
      }
      checkState(
          connectorRecordSetProvider != null,
          "Connector %s has neither a PageSource or RecordSet provider",
          connectorId);
      connectorPageSourceProvider = new RecordPageSourceProvider(connectorRecordSetProvider);
    }

    ConnectorHandleResolver connectorHandleResolver = connector.getHandleResolver();
    checkNotNull(
        connectorHandleResolver, "Connector %s does not have a handle resolver", connectorId);

    ConnectorPageSinkProvider connectorPageSinkProvider = null;
    try {
      connectorPageSinkProvider = connector.getPageSinkProvider();
      checkNotNull(
          connectorPageSinkProvider,
          "Connector %s returned a null page sink provider",
          connectorId);
    } catch (UnsupportedOperationException ignored) {
    }

    if (connectorPageSinkProvider == null) {
      ConnectorRecordSinkProvider connectorRecordSinkProvider = null;
      try {
        connectorRecordSinkProvider = connector.getRecordSinkProvider();
        checkNotNull(
            connectorRecordSinkProvider,
            "Connector %s returned a null record sink provider",
            connectorId);
        connectorPageSinkProvider = new RecordPageSinkProvider(connectorRecordSinkProvider);
      } catch (UnsupportedOperationException ignored) {
      }
    }

    ConnectorIndexResolver indexResolver = null;
    try {
      indexResolver = connector.getIndexResolver();
      checkNotNull(indexResolver, "Connector %s returned a null index resolver", connectorId);
    } catch (UnsupportedOperationException ignored) {
    }

    // IMPORTANT: all the instances need to be fetched from the connector *before* we add them to
    // the corresponding managers.
    // Otherwise, a broken connector would leave the managers in an inconsistent state with respect
    // to each other

    metadataManager.addConnectorMetadata(connectorId, catalogName, connectorMetadata);

    metadataManager.addInformationSchemaMetadata(
        makeInformationSchemaConnectorId(connectorId),
        catalogName,
        new InformationSchemaMetadata(catalogName));
    splitManager.addConnectorSplitManager(
        makeInformationSchemaConnectorId(connectorId),
        new InformationSchemaSplitManager(nodeManager));
    pageSourceManager.addConnectorPageSourceProvider(
        makeInformationSchemaConnectorId(connectorId),
        new InformationSchemaPageSourceProvider(metadataManager, splitManager));

    splitManager.addConnectorSplitManager(connectorId, connectorSplitManager);
    handleResolver.addHandleResolver(connectorId, connectorHandleResolver);
    pageSourceManager.addConnectorPageSourceProvider(connectorId, connectorPageSourceProvider);

    if (connectorPageSinkProvider != null) {
      pageSinkManager.addConnectorPageSinkProvider(connectorId, connectorPageSinkProvider);
    }

    if (indexResolver != null) {
      indexManager.addIndexResolver(connectorId, indexResolver);
    }
  }