同盟查詢 (Lakehouse 同盟)

適用於:檢查標示為是Databricks SQL 檢查標示為是 Databricks Runtime 13.3 LTS 和更新版本檢查標示為是僅限 Unity 目錄

查詢同盟可讓 Azure Databricks 針對其他 Azure Databricks 中繼存放區提供的數據,以及許多第三方資料庫管理系統(DBMS),例如 PostgreSQLmySQLSnowflake 來執行查詢。

若要從另一個系統查詢數據,您必須:

  1. 建立 外部連線。 這會向 Unity 目錄註冊特定的同盟伺服器,並建立與其通訊的方法,例如所使用的 URL、埠和認證。
  2. 向 Unity 目錄註冊來自同盟伺服器的外部目錄
  3. 與使用者對外部目錄的存取權。 這可以在目錄、架構或數據表層級完成,就像使用一般安全性實體一樣。

您現在可以跨各種地方和對外關係發出查詢。

外部連線

外部連線是 Unity 目錄安全性實體物件,可識別外部伺服器。 在 CREATE CONNECTION,您可以指定可存取伺服器的 URL。

您也必須提供選項,例如使用者名稱和密碼或其他已接受的驗證,Azure Databricks 將用來通訊。

外部目錄

假設有支援三層命名空間的外接,catalog/database.schema.table您可以使用 CREATE FOREIGN CATALOG 命令向 Unity 目錄註冊整個目錄。 Azure Databricks 會讓目錄的架構及其關係與外部來源保持同步。

範例

-- Create a postgresql connection
> CREATE CONNECTION postgresql_connection
    TYPE POSTGRESQL
    OPTIONS (
       host 'qf-postgresql-demo.xxxxxx.us-west-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.us-west-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;
  ...