教程:连接器 Java 模板的本机 SDK

简介

欢迎来到我们的教程,了解如何借助 Snowflake Native SDK for Connectors 使用连接器模板。本指南将帮助您设置一个简单的连接器本机应用程序。

在本教程中,您将学习如何执行以下操作:

  • 部署连接器本机应用程序

  • 配置模板连接器以引入数据

  • 根据自己的需要自定义模板连接器

模板包含各种有用的代码内注释,以便您更轻松地找到需要修改的特定文件。查找带有以下关键字的评论,它们将指导并帮助您实施自己的连接器:

  • TODO

  • TODO: HINT

  • TODO: IMPLEMENT ME

在开始本教程之前,您应该通过查看以下推荐内容做好准备:

  • Snowflake Native SDK for Connectors

  • Snowflake Labs 快速入门,用于在 Snowflake 和本机连接器中使用 Native Apps 框架构建和部署连接器 SDK Java (https://quickstarts.snowflake.com/guide/connectors_native_sdk_java_example)。

先决条件

在开始之前,请确保您满足以下要求:

  • 已安装 Java 11

  • 使用 ACCOUNTADMIN 角色访问 Snowflake 账户

  • 附带 variable_substitutionexit_on_errorSnowSQL(CLI 客户端) 工具,在本地机器上配置

  • 查看此文档页面:Snowflake Native SDK for Connectors 并保持在线打开或通过浏览器打印 查看此快速入门:` 连接器本机 Java SDK <https://quickstarts.snowflake.com/guide/connectors_native_sdk_java_example (https://quickstarts.snowflake.com/guide/connectors_native_sdk_java_example)>`_(可选,但推荐)快速入门使用基于模板的示例连接器,可以参考它来查看各种组件的示例实施。

初始化和部署

要初始化项目,请从 GitHub 克隆本机 SDK 连接器存储库 (https://github.com/snowflakedb/connectors-native-sdk) 并复制 /templates/native-sdk-connectors-java-template 目录到所需的项目位置。该模板包含部署可运行的连接器本机应用程序所需的所有代码。完成后,模板即可部署。

部署

该模板已准备好立即部署,并提供了一个方便的脚本来处理整个过程。在部署连接器之前,必须指定 snowsql 连接。为此,请打开 Makefile 并将连接名称放入 CONNECTION 环境变量。

要快速部署应用程序,请进入模板的主目录并执行以下命令:

make reinstall_application_from_version_dir
Copy

此命令执行以下操作:

  • 从 Snowflake 账户中删除先前存在的 APPLICATIONAPPLICATION PACKAGE

  • 将 SDK jar 文件和从 jar 文件中提取的 sql 文件复制到目标 sf_build 目录。

  • 将应用程序的自定义 Streamlit 和 Java 组件复制到 sf_build 目录。

  • 使用 Snowflake 账户内 sf_build 目录中的文件创建新的 APPLICATION PACKAGE

  • 在 Snowflake 账户内创建新的 APPLICATION 实例。

此过程大约需要 2 到 3 分钟才能完成。完成后,导航至 Data Products – > `` 应用程序 `` tab inside Snowflake, your Connector should be visible there. If you have a lot of applications and have trouble finding it, try typing NATIVE_SDK_CONNECTOR_TEMPLATE in the search bar, or in the case of a custom APPLICATION 名称,改用自定义名称。此连接器已准备好进行配置。以下步骤将指导您完成整个过程并解释如何自定义每个步骤。

如果您需要在本教程的任何步骤中重新部署连接器,例如测试您的更改,那么只需重新运行上述命令即可。

先决条件步骤

部署后,连接器立即处于向导阶段。此阶段包括几个步骤,指导最终用户完成所有必要的配置。第一步是先决条件步骤。它是可选的,并且可能不是每个连接器都需要。先决条件通常是应用程序之外的用户所需操作,例如通过工作表运行查询、在源系统端进行一些配置等。

阅读有关先决条件的更多信息:

每个先决条件的内容直接从位于连接器内部的内部表 (STATE.PREREQUISITES) 中检索。它们可以通过 setup.sql 脚本自定义。然而,请记住每次安装、升级和降级应用程序时都会执行 setup.sql 脚本。插入必须是幂等的,因此建议使用合并查询,如下例所示:

MERGE INTO STATE.PREREQUISITES AS dest
USING (SELECT * FROM VALUES
           ('1',
            'Sample prerequisite',
            'Prerequisites can be used to notice the end user of the connector about external configurations. Read more in the SDK documentation below. This content can be modified inside `setup.sql` script',
            'https://docs.snowflake.com/developer-guide/native-apps/connector-sdk/flow/prerequisites',
            NULL,
            NULL,
            1
           )
) AS src (id, title, description, documentation_url, learnmore_url, guide_url, position)
ON dest.id = src.id
WHEN NOT MATCHED THEN
    INSERT (id, title, description, documentation_url, learnmore_url, guide_url, position)
    VALUES (src.id, src.title, src.description, src.documentation_url, src.learnmore_url, src.guide_url, src.position);
Copy

连接器配置步骤

向导阶段的下一步是连接器配置步骤。在此步骤中,您可以配置连接器所需的数据库对象和权限。此步骤允许指定以下配置属性:

  • warehouse

  • destination_database

  • destination_schema

  • operational_warehouse

  • global_schedule

  • data_owner_role

  • agent_username

  • agent_role

如果您需要任何其他自定义属性,可以在向导阶段的后续步骤之一中进行配置。有关每个属性的更多信息,请参阅:

此外,Streamlit 组件 (streamlit/wizard/connector_config.py) 模板中提供了如何触发 permissions-sdk 并向最终用户请求一些授权。只要可用的属性满足连接器的需求,就不需要覆盖任何后端类,尽管这仍然可以像配置的后续步骤中的组件一样。

有关内部过程和 Java 对象的更多信息,请参阅:

提供的 Streamlit 示例允许请求账户级别授权,例如 create databaseexecute tasks。它还允许用户通过 permissions-sdk 弹出窗口指定仓库参考。

在模板中,只要求用户提供 destination_databasedestination_schema。然而,streamlit/wizard/connector_configuration.py 中的 TODO 注释包含注释代码,可以重复使用以在 Streamlit UI 中显示更多输入框。

# TODO: Here you can add additional fields in connector configuration. Supported values are the following: warehouse, operational_warehouse, data_owner_role, agent_role, agent_username
# For example:
st.subheader("Operational warehouse")
input_col, _ = st.columns([2, 1])
with input_col:
    st.text_input("", key="operational_warehouse", label_visibility="collapsed")
st.caption("Name of the operational warehouse to be used")
Copy

连接配置步骤

向导阶段的下一步是连接配置步骤。此步骤允许最终用户配置连接器的外部连接参数。该配置可能包括密钥、集成等对象的标识符。由于这取决于连接器引入的数据的源系统,所以这是在源代码中进行更多自定义的第一个位置。

有关连接配置的更多信息,请参阅:

从 Streamlit UI 侧(streamlit/wizard/connection_config.py 文件)开始,您需要为所有需要的参数添加文本框。已为您实施了一个示例文本框,如果您在此文件中搜索代码,您可以找到带有新字段注释代码的 TODO

# TODO: Additional configuration properties can be added to the UI like this:
st.subheader("Additional connection parameter")
input_col, _ = st.columns([2, 1])
with input_col:
    st.text_input("", key="additional_connection_property", label_visibility="collapsed")
st.caption("Some description of the additional property")
Copy

将属性添加到表单后,需要将它们传递到连接器的后端层。为此,必须修改 Streamlit 文件中的另外两个位置。第一个是 streamlit/wizard/connection_config.py 文件中的 finish_config 功能。必须在这里读取新添加的文本框的状态。此外,如果需要,还可以进行验证,然后传递给 set_connection_configuration 功能。例如,如果添加了 additional_connection_property,则编辑后看起来如下:

def finish_config():
try:
    # TODO: If some additional properties were specified they need to be passed to the set_connection_configuration function.
    # The properties can also be validated, for example, check whether they are not blank strings etc.
    response = set_connection_configuration(
        custom_connection_property=st.session_state["custom_connection_property"],
        additional_connection_property=st.session_state["additional_connection_property"],
    )

# rest of the method without changes
Copy

然后必须编辑 set_connection_configuration 函数,以便在 streamlit/native_sdk_api/connection_config.py 文件中将其找到。此函数是 Streamlit UI 以及底层 SQL 过程之间的代理,它是连接器后端的入口点。

def set_connection_configuration(custom_connection_property: str, additional_connection_property: str):
    # TODO: this part of the code sends the config to the backend so all custom properties need to be added here
    config = {
        "custom_connection_property": escape_identifier(custom_connection_property),
        "additional_connection_property": escape_identifier(additional_connection_property),
    }

    return call_procedure(
        "PUBLIC.SET_CONNECTION_CONFIGURATION",
        [variant_argument(config)]
    )
Copy

完成此操作后,新属性将保存在包含配置的内部连接器表中。然而,这并不意味着可能的自定义结束。一些后端组件也可以自定义,可以在代码中查找以下注释来找到它们:

  • TODO: IMPLEMENT ME connection configuration validate

  • TODO: IMPLEMENT ME connection callback

  • TODO: IMPLEMENT ME test connection

验证部分允许进行对从 UI 接收到的任何额外验证。它还可以转换数据,例如将其转换为小写、进行修剪或检查具有所提供名称的对象是否确实存在于 Snowflake 中。

连接回调是允许您根据配置执行任何附加操作的部分,例如调整需要使用外部访问集成的过程。

测试连接是连接配置的最后一个组件,用于检查连接器和源系统之间是否可以建立连接。

有关这些内部组件的更多信息,请参阅:

示例实施可能如下所示:

public class TemplateConfigurationInputValidator implements ConnectionConfigurationInputValidator {

    private static final String ERROR_CODE = "INVALID_CONNECTION_CONFIGURATION";

    @Override
    public ConnectorResponse validate(Variant config) {
      // TODO: IMPLEMENT ME connection configuration validate: If the connection configuration input
      // requires some additional validation this is the place to implement this logic.
      // See more in docs:
      // https://docs.snowflake.com/developer-guide/native-apps/connector-sdk/reference/connection_configuration_reference
      // https://docs.snowflake.com/developer-guide/native-apps/connector-sdk/flow/connection_configuration
      var integrationCheck = checkParameter(config, INTEGRATION_PARAM, false);
      if (!integrationCheck.isOk()) {
        return integrationCheck;
      }

      var secretCheck = checkParameter(config, SECRET_PARAM, true);
      if (!secretCheck.isOk()) {
        return ConnectorResponse.error(ERROR_CODE);
      }

      return ConnectorResponse.success();
    }
}
Copy
public class TemplateConnectionConfigurationCallback implements ConnectionConfigurationCallback {

    private final Session session;

    public TemplateConnectionConfigurationCallback(Session session) {
      this.session = session;
    }

    @Override
    public ConnectorResponse execute(Variant config) {
      // TODO: If you need to alter some procedures with external access you can use
      // configureProcedure method or implement a similar method on your own.
      // TODO: IMPLEMENT ME connection callback: Implement the custom logic of changes in application
      // to be done after connection configuration, like altering procedures with external access.
      // See more in docs:
      // https://docs.snowflake.com/developer-guide/native-apps/connector-sdk/reference/connection_configuration_reference
      // https://docs.snowflake.com/developer-guide/native-apps/connector-sdk/flow/connection_configuration
      configureProcedure(format("PUBLIC.TEST_CONNECTION()"), config);

      return ConnectorResponse.success();
    }
}
Copy
public class TemplateConnectionValidator {

    private static final String ERROR_CODE = "TEST_CONNECTION_FAILED";

    public static Variant testConnection(Session session) {
      // TODO: IMPLEMENT ME test connection: Implement the custom logic of testing the connection to
      // the source system here. This usually requires connection to some webservice or other external
      // system. It is suggested to perform only the basic connectivity validation here.
      // If that's the case then this procedure must be altered in TemplateConnectionConfigurationCallback first.
      // See more in docs:
      // https://docs.snowflake.com/developer-guide/native-apps/connector-sdk/reference/connection_configuration_reference
      // https://docs.snowflake.com/developer-guide/native-apps/connector-sdk/flow/connection_configuration
      return test().toVariant();
    }

    private static ConnectorResponse test() {
      try {
        var response = SourceSystemHttpHelper.testEndpoint();

        if (isSuccessful(response.statusCode())) {
          return ConnectorResponse.success();
        } else {
          return ConnectorResponse.error(ERROR_CODE, "Connection to source system failed");
        }
      } catch (Exception exception) {
        return ConnectorResponse.error(ERROR_CODE, "Test connection failed");
      }
    }
}
Copy

完成配置步骤

完成连接器配置步骤是向导阶段的最后一步。此步骤有多项职责。首先,它允许用户指定连接器所需的任何附加配置。其次,它会为引入的数据创建接收数据库、架构以及(如果需要)一些表和视图。最后,它会初始化内部组件,例如调度程序和任务反应器。

有关配置完成的更多信息,请参阅:

有关任务反应器和调度的更多信息,请参阅:

与连接配置步骤类似,可以使用 Streamlit 开始自定义 UI。streamlit/wizard/finalize_config.py 包含具有示例属性的表单。根据连接器的需要,可以添加更多属性。要添加另一个属性,请寻找 TODO 注释,包含在所提及的文件中添加新属性的示例代码。

# TODO: Here you can add additional fields in finalize connector configuration.
# For example:
st.subheader("Some additional property")
input_col, _ = st.columns([2, 1])
with input_col:
    st.text_input("", key="some_additional_property", label_visibility="collapsed")
st.caption("Description of some new additional property")
Copy

为文本框添加新属性后,需要将其传递到后端。为此,需要修改同一文件中的 finalize_configuration 功能:

def finalize_configuration():
    try:
        st.session_state["show_main_error"] = False
        # TODO: If some additional properties were introduced, they need to be passed to the finalize_connector_configuration function.
        response = finalize_connector_configuration(
            st.session_state.get("custom_property"),
            st.session_state.get("some_additional_property")
        )
Copy

接下来,打开 streamlit/native_sdk_api/finalize_config.py 并将其添加到以下函数中:

def finalize_connector_configuration(custom_property: str, some_additional_property: str):
    # TODO: If some custom properties were configured, then they need to be specified here and passed to the FINALIZE_CONNECTOR_CONFIGURATION procedure.
    config = {
        "custom_property": custom_property,
        "some_additional_property": some_additional_property,
    }
    return call_procedure(
        "PUBLIC.FINALIZE_CONNECTOR_CONFIGURATION",
        [variant_argument(config)]
    )
Copy

同样,与连接配置步骤类似,此步骤也允许自定义各种后端组件,可以使用代码中的以下短语找到它们:

  • TODO: IMPLEMENT ME validate source

  • TODO: IMPLEMENT ME finalize internal

验证源部分负责对源系统执行更复杂的验证。如果前面的测试连接仅检查是否可以建立连接,那么验证源可以检查对系统中特定数据的访问,例如,提取单条数据记录。

Finalize Internal 是一个内部过程,负责初始化任务反应器和调度器、创建接收数据库和必要的嵌套对象。它还可用于保存在完成步骤中提供的配置(默认情况下不保存此配置)。

有关内部组件的更多信息,请参阅:

此外,可以将输入 FinalizeConnectorInputValidator 接口并将其提供给最终处理程序(检查 TemplateFinalizeConnectorConfigurationCustomHandler)以进行验证。有关使用构建器的更多信息,请参阅:

验证源的示例实施可能如下所示:

public class SourceSystemAccessValidator implements SourceValidator {

    @Override
    public ConnectorResponse validate(Variant variant) {
      // TODO: IMPLEMENT ME validate source: Implement the custom logic of validating the source
      // system. In some cases this can be the same validation that happened in
      // TemplateConnectionValidator.
      // However, it is suggested to perform more complex validations, like specific access rights to
      // some specific resources here.
      // See more in docs:
      // https://docs.snowflake.com/developer-guide/native-apps/connector-sdk/reference/finalize_configuration_reference
      // https://docs.snowflake.com/developer-guide/native-apps/connector-sdk/flow/finalize_configuration
      var finalizeProperties = Configuration.fromCustomConfig(variant);

      var httpResponse = SourceSystemHttpHelper.validateSource(finalizeProperties.get("custom_property"));
      return prepareConnectorResponse(httpResponse.statusCode());
    }

    private ConnectorResponse prepareConnectorResponse(int statusCode) {
      switch (statusCode) {
        case 200:
          return ConnectorResponse.success();
        case 401:
          return ConnectorResponse.error("Unauthorized error");
        case 404:
          return ConnectorResponse.error("Not found error");
        default:
          return ConnectorResponse.error("Unknown error");
      }
    }
}
Copy

创建资源

向导阶段完成后,连接器即可开始引入数据。但首先,必须实施和配置资源。资源是描述源系统中特定数据集的抽象概念,例如表、端点、文件等。

不同的源系统可能需要有关资源的不同信息,因此需要根据具体需求自定义资源定义。要进行此操作,请访问 streamlit/daily_use/data_sync_page.py 文件。在文件中可以找到味资源参数添加文本框的 TODO。资源参数应该允许从源系统识别和检索数据。然后可以在引入过程中提取这些参数:

# TODO: specify all the properties needed to define a resource in the source system. A subset of those properties should allow for a identification of a single resource, be it a table, endpoint, repository or some other data storage abstraction
st.text_input(
    "Resource name",
    key="resource_name",
)
st.text_input(
    "Some resource parameter",
    key="some_resource_parameter"
)
Copy

一旦所有必要的属性都被添加到表单中,它们就可以被传递到后端。首先,必须提取文本字段的状态并将其传递给 streamlit/daily_use/data_sync_page.py 中的 API 等级 queue_resource 方法:

def queue_resource():
    # TODO: add additional properties here and pass them to create_resource function
    resource_name = st.session_state.get("resource_name")
    some_resource_parameter = st.session_state.get("some_resource_parameter)

    if not resource_name:
        st.error("Resource name cannot be empty")
        return

    result = create_resource(resource_name, some_resource_parameter)
    if result.is_ok():
        st.success("Resource created")
    else:
        st.error(result.get_message())
Copy

来自 streamlit/native_sdk_api/resource_management.pycreate_resource 函数需要更新:

def create_resource(resource_name, some_resource_parameter):
    ingestion_config = [{
        "id": "ingestionConfig",
        "ingestionStrategy": "INCREMENTAL",
        # TODO: HINT: scheduleType and scheduleDefinition are currently not supported out of the box, due to globalSchedule being used. However, a custom implementation of the scheduler can use those fields. They need to be provided becuase they are mandatory in the resourceDefinition.
        "scheduleType": "INTERVAL",
        "scheduleDefinition": "60m"
    }]
    # TODO: HINT: resource_id should allow identification of a table, endpoint etc. in the source system. It should be unique.
    resource_id = {
        "resource_name": resource_name,
    }
    id = f"{resource_name}_{random_suffix()}"

    # TODO: if you specified some additional resource parameters then you need to put them inside resource metadata:
    resource_metadata = {
        "some_resource_parameter": some_resource_parameter
    }

    return call_procedure("PUBLIC.CREATE_RESOURCE",
                          [
                              varchar_argument(id),
                              variant_argument(resource_id),
                              variant_list_argument(ingestion_config),
                              varchar_argument(id),
                              "true",
                              variant_argument(resource_metadata)
                          ])
Copy

定制 CREATE_RESOURCE() 过程逻辑

PUBLIC.CREATE_RESOURCE() 过程允许开发人员通过实现插入到主执行流程的几个位置的自己的逻辑来自定义其实施。SDK 允许开发人员执行以下操作:

  1. 在创建资源之前对其进行验证。逻辑应该在 PUBLIC.CREATE_RESOURCE_VALIDATE() 过程中实施。

  2. 在创建资源之前进行一些自定义操作。逻辑应该在 PUBLIC.PRE_CREATE_RESOURCE() 过程中实施。

  3. 资源创建完成后,进行一些自定义操作。逻辑应该在 PUBLIC.POST_CREATE_RESOURCE() 过程中实施。

更多有关 PUBLIC.CREATE_RESOURCE() 过程自定义的信息可参阅此处:

TemplateCreateResourceHandler.java

该类是 PUBLIC.CREATE_RESOURCE() 过程的处理程序。在这里,您可以注入前面提到的回调过程的处理程序的 Java 实施。默认情况下,模板提供回调处理程序的模拟 Java 实现,以便摆脱调用延长整个过程执行时间的 SQL 过程。Java 实施使执行速度更快。这些模拟的实施除了返回成功响应之外不执行任何操作。您可以为模板准备的回调类提供自定义实施,也可以从头开始创建这些回调并将它们注入到处理程序构建器中的主要过程执行流中。

为了将自定义逻辑实施到默认调用的回调方法中,请在代码中查找以下短语:

  • TODO: IMPLEMENT ME create resource validate

  • TODO: IMPLEMENT ME pre create resource callback

  • TODO: IMPLEMENT ME post create resource callback

引入

要执行数据引入,您需要实施一个类,该类将根据资源配置处理与源系统的连接并检索数据。调度程序和任务反应器模块将负责引入任务的触发和排队。

TemplateIngestion 类提取逻辑,寻找代码中的 TODO: IMPLEMENT ME ingestion,用来自源系统的数据检索取代随机数据生成。如果在资源定义中添加了一些自定义属性,则可以使用 ResourceIngestionDefinitionRepository 以及可用的属性 TemplateWorkItem 从内部连接器表中获取它们:

  • resourceIngestionDefinitionId

  • ingestionConfigurationId

例如从某些 Web 服务 MIGHT 检索数据看起来像这样:

public final class SourceSystemHttpHelper {

  private static final String DATA_URL = "https://source_system.com/data/%s";
  private static final SourceSystemHttpClient sourceSystemClient = new SourceSystemHttpClient();
  private static final ObjectMapper objectMapper = new ObjectMapper();

  private static List<Variant> fetchData(String resourceId) {
    var response = sourceSystemClient.get(String.format(url, resourceId));
    var body = response.body();

    try {
        return Arrays.stream(objectMapper.readValue(body, Map[].class))
              .map(Variant::new)
              .collect(Collectors.toList());
    } catch (JsonProcessingException e) {
      throw new RuntimeException("Cannot parse json", e);
    }
  }
}
Copy
public class SourceSystemHttpClient {

  private static final Duration REQUEST_TIMEOUT = Duration.ofSeconds(15);

  private final HttpClient client;
  private final String secret;

  public SourceSystemHttpClient() {
    this.client = HttpClient.newHttpClient();
    this.secret =
        SnowflakeSecrets.newInstance()
            .getGenericSecretString(ConnectionConfiguration.TOKEN_NAME);
  }

  public HttpResponse<String> get(String url) {
    var request =
        HttpRequest.newBuilder()
            .uri(URI.create(url))
            .GET()
            .header("Authorization", format("Bearer %s", secret))
            .header("Content-Type", "application/json")
            .timeout(REQUEST_TIMEOUT)
            .build();

    try {
      return client.send(request, HttpResponse.BodyHandlers.ofString());
    } catch (IOException | InterruptedException ex) {
      throw new RuntimeException(format("HttpRequest failed: %s", ex.getMessage()), ex);
    }
  }
}
Copy

管理资源生命周期

一旦实施了创建资源及其引入的逻辑,您就可以按照以下步骤管理它们的生命周期:

  1. PUBLIC.ENABLE_RESOURCE() – 此过程启用特定资源,这意味着它将被安排用于引入

  2. PUBLIC.DISABLE_RESOURCE() – 此过程禁用特定资源,这意味着其引入调度将停止

  3. PUBLIC.UPDATE_RESOURCE() - 此过程允许更新特定资源的引入配置。默认情况下,Streamlit UI 中未进行实施,因为有时开发人员可能不希望允许连接器用户自定义引入配置(撤销授予应用程序角色 ACCOUNTADMIN 对此过程的权限以完全禁止其使用)。

所有这些过程都有 Java 处理程序,并通过回调进行扩展,以允许自定义其执行。您可以使用这些处理程序的构建器注入回调的自定义实施。默认情况下,模板提供回调处理程序的模拟 Java 实施,以便摆脱调用 SQL 过程延长上述过程整个执行时间。这些模拟的实施除了返回成功响应之外不执行任何操作。您可以为模板准备的回调类提供自定义实施,也可以从头开始创建这些回调并将它们注入到处理程序构建器中的主要过程执行流中。

TemplateEnableResourceHandler.java

此类为 PUBLIC.ENABLE_RESOURCE() 过程的处理程序,可以使用专用于以下操作的回调进行扩展:

  1. 在启用资源之前对其进行验证。寻找代码中的 TODO: IMPLEMENT ME enable resource validate 短语以提供自定义实施。

  2. 在资源启用前做一些自定义操作。寻找代码中的 TODO: IMPLEMENT ME pre enable resource 短语以提供自定义实施。

  3. 在资源启用后,进行一些自定义操作。寻找代码中的 TODO: IMPLEMENT ME post enable resource 短语以提供自定义实施。

通过 PUBLIC.ENABLE_RESOURCE() 过程详细文档了解更多信息:

TemplateDisableResourceHandler.java

此类为 PUBLIC.DISABLE_RESOURCE() 过程的处理程序,可以使用专用于以下操作的回调进行扩展:

  1. 在禁用资源之前对其进行验证。寻找代码中的 TODO: IMPLEMENT ME disable resource validate 短语以提供自定义实施。

  2. 在禁用资源之前做一些自定义操作。寻找代码中的 TODO: IMPLEMENT ME pre disable resource 短语以提供自定义实施。

通过 PUBLIC.DISABLE_RESOURCE() 过程详细文档了解更多信息:

TemplateUpdateResourceHandler.java

此类为 PUBLIC.UPDATE_RESOURCE() 过程的处理程序,可以使用专用于以下操作的回调进行扩展:

  1. 在更新资源之前对其进行验证。寻找代码中的 TODO: IMPLEMENT ME update resource validate 短语以提供自定义实施。

  2. 在资源更新之前做一些自定义操作。寻找代码中的 TODO: IMPLEMENT ME pre update resource 短语以提供自定义实施。

  3. 在资源更新后,做一些自定义操作。寻找代码中的 TODO: IMPLEMENT ME post update resource 短语以提供自定义实施。

通过 PUBLIC.UPDATE_RESOURCE() 过程详细文档了解更多信息:

设置

该模板包含一个设置选项卡,可让您查看之前进行的所有配置。但是,如果配置属性是自定义的,那么此视图也需要进行一些自定义。设置选项卡代码可以在 streamlit/daily_use/settings_page.py 文件中找到。要进行自定义,只需从配置中提取在相应配置中添加的键的值即可。

例如,如果早些时候 additional_connection_property 是在连接配置步骤中添加的,那么可以像这样添加:

def connection_config_page():
    current_config = get_connection_configuration()

    # TODO: implement the display for all the custom properties defined in the connection configuration step
    custom_property = current_config.get("custom_connection_property", "")
    additional_connection_property = current_config.get("additional_connection_property", "")


    st.header("Connector configuration")
    st.caption("Here you can see the connector connection configuration saved during the connection configuration step "
               "of the Wizard. If some new property was introduced it has to be added here to display.")
    st.divider()

    st.text_input(
        "Custom connection property:",
        value=custom_property,
        disabled=True
    )
    st.text_input(
        "Additional connection property:",
        value=additional_connection_property,
        disabled=True
    )
    st.divider()
Copy
语言: 中文