分享方式:


磁碟區

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

磁碟區是 Unity 目錄物件,代表雲端物件儲存位置中的記憶體邏輯磁碟區。 磁碟區提供存取、儲存、控管和組織檔案的功能。 雖然數據表提供表格式數據集的控管,但磁碟區會透過非表格式數據集新增治理。 您可以使用磁碟區,以任何格式儲存和存取檔案,包括結構化、半結構化和非結構化數據。

磁碟區是依 Unity 目錄架構組織之數據表、檢視和其他物件的同層級。

磁碟區可以管理或外部。

如需詳細資訊和限制,請參閱 什麼是 Unity 目錄磁碟區?

受控磁碟區

受控磁碟區是在包含架構的受控儲存位置內建立的 Unity 目錄控管記憶體磁碟區。 受控磁碟區允許建立受控記憶體以處理檔案,而不需要外部位置和記憶體認證的額外負荷。 建立受控磁碟區時,您不需要指定位置,而且受控磁碟區中數據的所有檔案存取都是透過 Unity 目錄所管理的路徑。

外部磁碟區

外部磁碟區是針對外部位置內目錄註冊的 Unity 目錄控管記憶體磁碟區。

磁碟區命名和參考

磁碟 區名稱可在 SQL 命令中使用目錄和架構名稱限定的識別碼

存取磁碟區中檔案的路徑會使用下列格式:

/Volumes/<catalog_identifier>/<schema_identifier>/<volume_identifier>/<path>/<file_name>

請注意,Azure Databricks 會將標識符正規化為小寫。

Azure Databricks 也支持選擇性 dbfs:/ 配置,因此下列路徑也有效:

dbfs:/Volumes/<catalog_identifier>/<schema_identifier>/<volume_identifier>/<path>/<file_name>

注意

您也可以使用雲端記憶體 URI 存取外部磁碟區中的數據。

管理磁碟區中的檔案

適用於: 檢查標示為是 Databricks SQL 連接器

使用 Databricks SQL 連接器,您可以使用下列命令來管理磁碟區中的檔案:

  • PUT INTO ,將檔案從本機記憶體複製到磁碟區。
  • GET 將檔案從磁碟區複製到本機記憶體。
  • REMOVE 可移除磁碟區中的檔案。

範例

--- Create an external volume under the directory “my-path”
> CREATE EXTERNAL VOLUME IF NOT EXISTS myCatalog.mySchema.myExternalVolume
        COMMENT 'This is my example external volume'
        LOCATION 's3://my-bucket/my-location/my-path'
 OK

--- Set the current catalog
> USE CATALOG myCatalog;
 OK

--- Set the current schema
> USE SCHEMA mySchema;
 OK

--- Create a managed volume; it is not necessary to specify a location
> CREATE VOLUME myManagedVolume
    COMMENT 'This is my example managed volume';
 OK

--- List the files inside the volume, all names are lowercase
> LIST '/Volumes/mycatalog/myschema/myexternalvolume'
 sample.csv

> LIST 'dbfs:/Volumes/mycatalog/myschema/mymanagedvolume'
 sample.csv

--- Print the content of a csv file
> SELECT * FROM csv.`/Volumes/mycatalog/myschema/myexternalvolume/sample.csv`
 20

> SELECT * FROM csv.`dbfs:/Volumes/mycatalog/myschema/mymanagedvolume/sample.csv`
 20