airflow.providers.microsoft.azure.hooks.data_lake

模組內容

類別

AzureDataLakeHook

與 Azure Data Lake 整合。

AzureDataLakeStorageV2Hook

與 ADLS gen2 儲存體帳戶互動。

屬性

認證

airflow.providers.microsoft.azure.hooks.data_lake.Credentials[原始碼]
class airflow.providers.microsoft.azure.hooks.data_lake.AzureDataLakeHook(azure_data_lake_conn_id=default_conn_name)[原始碼]

Bases: airflow.hooks.base.BaseHook

與 Azure Data Lake 整合。

AzureDataLakeHook 透過與 WebHDFS 相容的 REST API 進行通訊。請確保存在類型為 azure_data_lake 的 Airflow 連線。授權可以透過提供登入名稱 (=用戶端 ID)、密碼 (=用戶端密碼) 和額外欄位 tenant (租用戶) 和 account_name (帳戶名稱) 來完成。請參閱連線 azure_data_lake_default 以取得範例。

用戶端 ID 和密碼應在使用者和密碼參數中。租用戶和帳戶名稱應作為額外欄位,格式為 {"tenant": "<TENANT>", "account_name": "ACCOUNT_NAME"}

參數

azure_data_lake_conn_id (str) – 參考至 Azure Data Lake 連線

conn_name_attr = 'azure_data_lake_conn_id'[原始碼]
default_conn_name = 'azure_data_lake_default'[原始碼]
conn_type = 'azure_data_lake'[原始碼]
hook_name = 'Azure Data Lake'[原始碼]
classmethod get_connection_form_widgets()[原始碼]

傳回要新增至連線表單的連線小工具。

classmethod get_ui_field_behaviour()[原始碼]

傳回自訂欄位行為。

get_conn()[原始碼]

傳回 AzureDLFileSystem 物件。

check_for_file(file_path)[原始碼]

檢查檔案是否存在於 Azure Data Lake 上。

參數

file_path (str) – 檔案的路徑和名稱。

返回

如果檔案存在,則為 True,否則為 False。

返回類型

bool

upload_file(local_path, remote_path, nthreads=64, overwrite=True, buffersize=4194304, blocksize=4194304, **kwargs)[原始碼]

上傳檔案至 Azure Data Lake。

參數
  • local_path (str) – 本機路徑。可以是單一檔案、目錄(在這種情況下,遞迴上傳)或 glob 模式。不支援使用 ** 的遞迴 glob 模式。

  • remote_path (str) – 要上傳到的遠端路徑;如果是多個檔案,則這是要寫入的根目錄。

  • nthreads (int) – 要使用的執行緒數。如果為 None,則使用核心數。

  • overwrite (bool) – 是否強制覆寫現有的檔案/目錄。如果為 False 且遠端路徑為目錄,則無論是否會覆寫任何檔案都將退出。如果為 True,則僅實際覆寫符合的檔案名稱。

  • buffersize (int) – int [2**22] 內部緩衝區的位元組數。此區塊不能大於區塊組,也不能小於區塊。

  • blocksize (int) – int [2**22] 區塊的位元組數。在每個區塊組中,我們為每個 API 呼叫寫入一個較小的區塊。此區塊不能大於區塊組。

download_file(local_path, remote_path, nthreads=64, overwrite=True, buffersize=4194304, blocksize=4194304, **kwargs)[原始碼]

從 Azure Blob 儲存體下載檔案。

參數
  • local_path (str) – 本機路徑。如果下載單一檔案,將寫入此特定檔案,除非它是現有的目錄,在這種情況下,會在其中建立檔案。如果下載多個檔案,則這是要寫入的根目錄。將根據需要建立目錄。

  • remote_path (str) – 要用於尋找遠端檔案的遠端路徑/glob 字串。不支援使用 ** 的遞迴 glob 模式。

  • nthreads (int) – 要使用的執行緒數。如果為 None,則使用核心數。

  • overwrite (bool) – 是否強制覆寫現有的檔案/目錄。如果為 False 且遠端路徑為目錄,則無論是否會覆寫任何檔案都將退出。如果為 True,則僅實際覆寫符合的檔案名稱。

  • buffersize (int) – int [2**22] 內部緩衝區的位元組數。此區塊不能大於區塊組,也不能小於區塊。

  • blocksize (int) – int [2**22] 區塊的位元組數。在每個區塊組中,我們為每個 API 呼叫寫入一個較小的區塊。此區塊不能大於區塊組。

list(path)[原始碼]

列出 Azure Data Lake Storage 中的檔案。

參數

path (str) – 要用於列出 ADLS 中檔案的完整路徑/glob 字串

remove(path, recursive=False, ignore_not_found=True)[原始碼]

移除 Azure Data Lake Storage 中的檔案。

參數
  • path (str) – 要在 ADLS 中移除的目錄或檔案

  • recursive (bool) – 是否迴圈進入位置中的目錄並移除檔案

  • ignore_not_found (bool) – 如果找不到要刪除的檔案是否引發錯誤

class airflow.providers.microsoft.azure.hooks.data_lake.AzureDataLakeStorageV2Hook(adls_conn_id, public_read=False)[原始碼]

Bases: airflow.hooks.base.BaseHook

與 ADLS gen2 儲存體帳戶互動。

它主要協助在具有階層式命名空間的儲存體帳戶中建立和管理目錄和檔案。使用 Adls_v2 連線詳細資訊建立 DataLakeServiceClient 物件。

由於 Wasb 被標記為舊版且 (ADLS1) 即將淘汰,因此實作 ADLS gen2 Hook 以與儲存體帳戶互動會很好。

參數
  • adls_conn_id (str) – 參考至 adls 連線

  • public_read (bool) – 是否應使用匿名公開讀取存取權。預設值為 False

conn_name_attr = 'adls_conn_id'[原始碼]
default_conn_name = 'adls_default'[原始碼]
conn_type = 'adls'[原始碼]
hook_name = 'Azure Date Lake Storage V2'[原始碼]
classmethod get_connection_form_widgets()[原始碼]

傳回要新增至連線表單的連線小工具。

classmethod get_ui_field_behaviour()[原始碼]

傳回自訂欄位行為。

service_client()[原始碼]

傳回 DataLakeServiceClient 物件 (已快取)。

get_conn()[原始碼]

傳回 DataLakeServiceClient 物件。

create_file_system(file_system_name)[原始碼]

在指定的帳戶下建立新的檔案系統。

容器充當檔案的檔案系統。

如果具有相同名稱的檔案系統已存在,則會引發 ResourceExistsError。此方法傳回一個用戶端,可用於與新建立的檔案系統互動。

get_file_system(file_system)[原始碼]

取得用戶端以與指定的檔案系統互動。

參數

file_system (azure.storage.filedatalake.FileSystemProperties | str) – 這可以是檔案系統的名稱或 FileSystemProperties 的執行個體。

create_directory(file_system_name, directory_name, **kwargs)[原始碼]

在指定的檔案系統下建立目錄。

參數
  • file_system_name (azure.storage.filedatalake.FileSystemProperties | str) – 檔案系統的名稱或 FileSystemProperties 的執行個體。

  • directory_name (str) – 需要在檔案系統中建立的目錄名稱。

get_directory_client(file_system_name, directory_name)[原始碼]

取得指定檔案系統下的特定目錄。

參數
  • file_system_name (azure.storage.filedatalake.FileSystemProperties | str) – 檔案系統的名稱或 FileSystemProperties 的執行個體。

  • directory_name (azure.storage.filedatalake.DirectoryProperties | str) – 需要從檔案系統擷取的目錄名稱或 DirectoryProperties 的執行個體。

create_file(file_system_name, file_name)[原始碼]

在檔案系統下建立檔案。

參數
  • file_system_name (azure.storage.filedatalake.FileSystemProperties | str) – 檔案系統的名稱或 FileSystemProperties 的執行個體。

  • file_name (str) – 需要在檔案系統中建立的檔案名稱。

upload_file(file_system_name, file_name, file_path, overwrite=False, **kwargs)[原始碼]

在檔案系統中建立具有資料的檔案。

參數
  • file_system_name (azure.storage.filedatalake.FileSystemProperties | str) – 檔案系統的名稱或 FileSystemProperties 的執行個體。

  • file_name (str) – 要使用名稱建立的檔案名稱。

  • file_path (str) – 要載入的檔案路徑。

  • overwrite (bool) – 布林旗標,用於覆寫現有檔案或不覆寫。

upload_file_to_directory(file_system_name, directory_name, file_name, file_path, overwrite=False, **kwargs)[原始碼]

將資料上傳到檔案。

參數
  • file_system_name (str) – 檔案系統的名稱或 FileSystemProperties 的執行個體。

  • directory_name (str) – 目錄名稱。

  • file_name (str) – 要使用名稱建立的檔案名稱。

  • file_path (str) – 要載入的檔案路徑。

  • overwrite (bool) – 布林旗標,用於覆寫現有檔案或不覆寫。

list_files_directory(file_system_name, directory_name)[原始碼]

列出指定檔案系統下的檔案或目錄。

參數
  • file_system_name (azure.storage.filedatalake.FileSystemProperties | str) – 檔案系統的名稱或 FileSystemProperties 的執行個體。

  • directory_name (str) – 目錄名稱。

list_file_system(prefix=None, include_metadata=False, **kwargs)[原始碼]

列出指定帳戶下的檔案系統。

參數
  • prefix (str | None) – 篩選結果,僅傳回名稱以指定前綴開頭的檔案系統。

  • include_metadata (bool) – 指定在回應中傳回檔案系統中繼資料。預設值為 False

delete_file_system(file_system_name)[原始碼]

刪除檔案系統。

參數

file_system_name (azure.storage.filedatalake.FileSystemProperties | str) – 檔案系統的名稱或 FileSystemProperties 的執行個體。

delete_directory(file_system_name, directory_name)[原始碼]

刪除檔案系統中指定的目錄。

參數
  • file_system_name (azure.storage.filedatalake.FileSystemProperties | str) – 檔案系統的名稱或 FileSystemProperties 的執行個體。

  • directory_name (str) – 目錄名稱。

test_connection()[原始碼]

測試 ADLS Gen2 儲存體連線。

此條目是否有幫助?