外部位置

適用於:檢查標示為是Databricks SQL 檢查標示為是 Databricks Runtime 檢查標示為是 Unity 目錄

Unity 目錄和內建的 Azure Databricks Hive 中繼存放區會使用受控數據表的預設位置。 Unity 目錄引進數個新的安全性實體物件,以將許可權授與雲端物件記憶體中的數據。

外部位置

外部位置是一個安全性實體物件,可將記憶體路徑與授權存取該路徑的記憶體認證結合在一起。

外部位置的建立者是其初始擁有者。 外部位置的擁有者可以修改外部位置的名稱、URI 和記憶體認證。

建立外部位置之後,您可以將存取權授與帳戶層級 主體 (使用者和群組)。

具有使用外部位置許可權的使用者或群組可以存取位置路徑內的任何記憶體路徑,而不需要直接存取記憶體認證。

若要進一步精簡訪問控制,您可以在外部數據表上使用 GRANT 來封裝外部位置內個別檔案的存取權。

外部位置名稱 不限定,而且在中繼存放區內必須是唯一的。

任何外部位置的儲存路徑都不能包含在另一個外部位置的記憶體路徑中,或是使用明確記憶體認證的外部數據表記憶體路徑內。

警告

如果在工作區層級 Hive 中繼存放區中註冊架構(資料庫),則使用 CASCADE 選項卸除該架構會導致該架構位置中的所有檔案以遞歸方式刪除,而不論數據表類型(Managed 或 external)。

如果架構註冊至 Unity 目錄中繼存放區,則會以遞歸方式刪除 Unity 目錄 受控數據表 的檔案。 不過,不會刪除外部資料表檔案。 您必須直接使用雲端記憶體提供者來管理這些檔案。

因此,為了避免意外遺失數據,您絕對不應該在Hive中繼存放區中向具有現有數據的位置註冊架構。 您也不應該在 Hive 中繼存放區架構或包含 Unity 目錄受控數據表的位置中建立新的外部數據表。

關聯性的圖形表示法

下圖描述兩者之間的關聯性:

  • 記憶體認證
  • 外部位置
  • 外部數據表
  • 記憶體路徑
  • IAM 實體
  • Azure 服務帳戶

外部位置 ER 圖表

範例

-- Grant `finance` user permission to create external location on `my_azure_storage_cred` storage credential, and then create an external location on the specific path to which `my_azure_storage_cred` has access
> GRANT CREATE EXTERNAL LOCATION ON STORAGE CREDENTIAL `my_azure_storage_cred` TO `finance`
> CREATE EXTERNAL LOCATION `finance_loc` URL 'abfss://container@storageaccount.dfs.core.windows.net/depts/finance'
    WITH (CREDENTIAL `my_azure_storage_cred`)
    COMMENT 'finance';

-- Grant read, write, and create table access to the finance location to `finance` user
> GRANT READ FILES, WRITE FILES, CREATE EXTERNAL TABLE ON EXTERNAL LOCATION `finance_loc` TO `finance`;

-- `finance` can read from any storage path under abfss://depts/finance but nowhere else
> SELECT count(1) FROM `delta`.`abfss://container@storageaccount.dfs.core.windows.net/depts/finance` WITH (CREDENTIAL my_azure_storage_cred);
  100
> SELECT count(1) FROM `delta`.`abfss://container@storageaccount.dfs.core.windows.net/depts/hr/employees` WITH (CREDENTIAL my_azure_storage_cred);
  Error

-- `finance` can create an external table over specific object within the `finance_loc` location
> CREATE TABLE main.default.sec_filings LOCATION 'abfss://container@storageaccount.dfs.core.windows.net/depts/finance/sec_filings';

-- Cannot list files under an external table with a user that doesn't have SELECT permission on it
> LIST 'abfss://container@storageaccount.dfs.core.windows.net/depts/finance/sec_filings'
  Error
> LIST 'abfss://container@storageaccount.dfs.core.windows.net/depts/finance/sec_filings/_delta_log'
  Error