다음을 통해 공유

联合查询 (Lakehouse Federation)

适用于:勾选“是” Databricks SQL 勾选“是” Databricks Runtime 13.3 LTS 及更高版本 勾选“是” 仅 Unity Catalog

查询联合允许 Azure Databricks 针对其他 Azure Databricks 元存储以及许多第三方数据库管理系统 (DBMS)(例如 PostgreSQLmySQLSnowflake)提供的数据执行查询。

若要从另一个系统查询数据,必须:

  1. 创建外部连接

    这会向 Unity Catalog 注册特定的联合服务器,并建立与其通信的方法,例如使用的 URL、端口和凭据。

  2. 将联合服务器中的外部目录注册到 Unity Catalog

  3. 授予用户访问外部目录的权限。

    这可以在目录、架构或表级别完成,就像使用常规安全对象一样。

现在可以跨各种本地和外部关系发出查询。

外部连接

外部连接是用于标识外部服务器的 Unity Catalog 安全对象。 作为 CREATE CONNECTION 的一部分,可以指定可访问服务器的 URL。

还必须提供 Azure Databricks 将用于通信的用户名和密码或其他接受的身份验证等选项。

外部目录

如果外部连接支持三级命名空间 (catalog/database.schema.table),则可以使用 CREATE FOREIGN CATALOG 命令向 Unity Catalog 注册整个目录。 Azure Databricks 使目录架构的定义及其关系与外部源保持同步。

示例

-- Create a postgresql connection
> CREATE CONNECTION postgresql_connection
    TYPE POSTGRESQL
    OPTIONS (
       host 'qf-postgresql-demo.xxxxxx.cn-north-2.rds.amazonaws.com',
       port '5432',
       user 'postgresql_user',
       password 'password123');

-- Alternatively create a postgresql connection with secret scope
> CREATE CONNECTION postgresql_connection
    TYPE POSTGRESQL
    OPTIONS (
       host 'qf-postgresql-demo.xxxxxx.cn-north-2.rds.amazonaws.com',
       port '5432',
       user secret('secrets.r.us', 'postgresUser'),
       password secret('secrets.r.us', 'postgresPassword'));

-- Expose the "postgresdb" database with schemas and tables postgresql_user can access.
> CREATE FOREIGN CATALOG postgresql_catalog
    USING CONNECTION postgresql_connection
    OPTIONS (database 'postgresdb');

-- Execute a query across tables in the above catalog, schema, and table.
> SELECT * FROM postgresql_catalog.a_schema.table1
  UNION ALL
  SELECT * FROM default.postgresql_schema.table2
  UNION ALL
  SELECT * FROM default.postgresql.mytable
  UNION ALL
  SELECT local_table;
  ...