airflow.providers.microsoft.azure.hooks.data_lake

屬性

憑據

AzureDataLakeHook

與 Azure Data Lake 的整合。

AzureDataLakeStorageV2Hook

與 ADLS gen2 儲存賬戶互動。

模組內容

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

基類: airflow.hooks.base.BaseHook

與 Azure Data Lake 的整合。

AzureDataLakeHook 透過與 WebHDFS 相容的 REST API 進行通訊。請確保存在型別為 azure_data_lake 的 Airflow 連線。授權可以透過提供 *登入名* (=Client ID),*密碼* (=Client Secret),以及 extra 欄位 *tenant* (Tenant) 和 *account_name* (Account Name) 來完成。請參閱連線 azure_data_lake_default 以獲取示例。

Client ID 和 secret 應作為使用者和密碼引數。Tenant 和 account name 應作為 extra 欄位,格式為 {"tenant": "<TENANT>", "account_name": "ACCOUNT_NAME"}

引數:

azure_data_lake_conn_id (str) – 引用 Azure Data Lake 連線

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

返回要新增到連線表單的連線小部件。

classmethod get_ui_field_behaviour()[source]

返回自定義欄位行為。

conn_id = 'azure_data_lake_default'[source]
account_name: str | None = None[source]
get_conn()[source]

返回一個 AzureDLFileSystem 物件。

check_for_file(file_path)[source]

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

引數:

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

返回:

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

返回型別:

bool

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

將檔案上傳到 Azure Data Lake。

引數:
  • local_path (str) – 本地路徑。可以是單個檔案、目錄(此時會遞迴上傳)或 glob 模式。不支援使用 ** 的遞迴 glob 模式。

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

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

  • overwrite (bool) – 是否強制覆蓋現有檔案/目錄。如果為 False 且遠端路徑為目錄,則無論是否有檔案會被覆蓋都會退出。如果為 True,則只覆蓋匹配的檔名。

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

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

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

從 Azure Blob Storage 下載檔案。

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

  • remote_path (str) – 用於查詢遠端檔案的遠端路徑/globstring。不支援使用 ** 的遞迴 glob 模式。

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

  • overwrite (bool) – 是否強制覆蓋現有檔案/目錄。如果為 False 且遠端路徑為目錄,則無論是否有檔案會被覆蓋都會退出。如果為 True,則只覆蓋匹配的檔名。

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

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

list(path)[source]

列出 Azure Data Lake Storage 中的檔案。

引數:

path (str) – 用於列出 ADLS 中檔案的完整路徑/globstring

remove(path, recursive=False, ignore_not_found=True)[source]

移除 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)[source]

基類: 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'[source]
default_conn_name = 'adls_default'[source]
conn_type = 'adls'[source]
hook_name = 'Azure Date Lake Storage V2'[source]
classmethod get_connection_form_widgets()[source]

返回要新增到連線表單的連線小部件。

classmethod get_ui_field_behaviour()[source]

返回自定義欄位行為。

conn_id[source]
public_read = False[source]
property service_client: azure.storage.filedatalake.DataLakeServiceClient[source]

返回 DataLakeServiceClient 物件(已快取)。

get_conn()[source]

返回 DataLakeServiceClient 物件。

create_file_system(file_system_name)[source]

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

容器充當檔案系統。

如果同名檔案系統已存在,將引發 ResourceExistsError。此方法返回一個用於與新建立的檔案系統互動的客戶端。

get_file_system(file_system)[source]

獲取一個用於與指定檔案系統互動的客戶端。

引數:

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

create_directory(file_system_name, directory_name, **kwargs)[source]

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

引數:
  • file_system_name (azure.storage.filedatalake.FileSystemProperties | str) – 檔案系統的名稱或 FileSystemProperties 的例項。

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

get_directory_client(file_system_name, directory_name)[source]

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

引數:
  • file_system_name (azure.storage.filedatalake.FileSystemProperties | str) – 檔案系統的名稱或 FileSystemProperties 的例項。

  • directory_name (azure.storage.filedatalake.DirectoryProperties | str) – 需要從檔案系統中檢索的目錄名稱或 DirectoryProperties 的例項。

create_file(file_system_name, file_name)[source]

在檔案系統下建立檔案。

引數:
  • file_system_name (azure.storage.filedatalake.FileSystemProperties | str) – 檔案系統的名稱或 FileSystemProperties 的例項。

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

upload_file(file_system_name, file_name, file_path, overwrite=False, **kwargs)[source]

在檔案系統下建立檔案並上傳資料。

引數:
  • 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)[source]

將資料上傳到檔案。

引數:
  • file_system_name (str) – 檔案系統的名稱或 FileSystemProperties 的例項。

  • directory_name (str) – 目錄名稱。

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

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

  • overwrite (bool) – 是否覆蓋現有檔案的布林標誌。

list_files_directory(file_system_name, directory_name)[source]

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

引數:
  • file_system_name (azure.storage.filedatalake.FileSystemProperties | str) – 檔案系統的名稱或 FileSystemProperties 的例項。

  • directory_name (str) – 目錄名稱。

list_file_system(prefix=None, include_metadata=False, **kwargs)[source]

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

引數:
  • prefix (str | None) – 篩選結果,只返回名稱以指定字首開頭的檔案系統。

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

delete_file_system(file_system_name)[source]

刪除檔案系統。

引數:

file_system_name (azure.storage.filedatalake.FileSystemProperties | str) – 檔案系統的名稱或 FileSystemProperties 的例項。

delete_directory(file_system_name, directory_name)[source]

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

引數:
  • file_system_name (azure.storage.filedatalake.FileSystemProperties | str) – 檔案系統的名稱或 FileSystemProperties 的例項。

  • directory_name (str) – 目錄名稱。

test_connection()[source]

測試 ADLS Gen2 Storage 連線。

此條目有用嗎?