從 GitHub 擷取資料

Important

這項功能位於 測試版 (Beta) 中。

本頁說明如何使用 Databricks Lakeflow Connect 建立受管理的 GitHub 擷取管線。

Requirements

  • 要建立一個攝取流程,你必須先符合以下條件:

    • 您的工作區必須啟用 Unity Catalog。

    • 您必須為工作區啟用無伺服器計算。 請參閱 無伺服器運算需求。

    • 若要建立新連線,您必須對元存放區具有 CREATE CONNECTION 權限。 請參閱管理 Unity Catalog 中的權限。

      如果連接器支援以 UI 為基礎的管線撰寫,系統管理員可以完成此頁面上的步驟,以同時建立連線和管線。 不過,如果建立管線的使用者使用API型管線編寫或非管理員使用者,則管理員必須先在目錄總管中建立連線。 請參閱 連線到受管理的擷取來源。

    • 若要使用現有的連線,您必須對該連線物件具有 USE CONNECTION 權限或 ALL PRIVILEGES。

    • 您必須擁有 USE CATALOG 目標目錄的權限。

    • 您必須擁有現有架構的 USE SCHEMA 和 CREATE TABLE 許可權或目標目錄的 CREATE SCHEMA 許可權。

  • 要從GitHub中擷取資料,您必須先完成 建立GitHub連線的步驟。

建立資料導入管道

每個來源資料表都會被導入至流動資料表。 有關支援的來源資料表清單,請參見 支援資料。

Databricks 使用者介面

  1. 在 Azure Databricks 工作區的側邊欄中,按一下 [ 數據擷取]。
  2. 在 Add data 頁面,Databricks connectors 下,點選 GitHub。
  3. 在擷取精靈的 Connection 頁面,選擇儲存你GitHub存取憑證的連線。 如果你對 metastore 具有 CREATE CONNECTION 權限,即可按一下 加號圖示。 建立連線,使用 建立 GitHub 連線 中的驗證詳細資料來建立新的連線。
  4. 按一下「下一步」。
  5. 在 「擷取設定 」頁面,輸入管線的唯一名稱。
  6. 選擇一個目錄和一個結構來撰寫事件日誌。 如果你有USE CATALOGCREATE SCHEMA目錄權限,可以點擊加號圖示。在下拉選單建立 schema 以建立新的 schema。
  7. 按兩下 [建立管線,然後繼續。
  8. 在 [ 來源] 頁面上,選取要內嵌的數據表。
  9. 按一下 [儲存並繼續]。
  10. 在 目的地 頁面,選擇目錄和結構來載入資料。 如果你有USE CATALOGCREATE SCHEMA目錄權限,可以點擊加號圖示。在下拉選單建立 schema 以建立新的 schema。
  11. 按一下 [儲存並繼續]。
  12. (可選)在 排程與通知 頁面,點擊 Plus 圖示。 制定時間表。 設定重新整理目的地數據表的頻率。
  13. (可選)點擊 Plus 圖示。 新增通知 以設定管道運作成功或失敗的電子郵件通知,然後點 選儲存並執行管道。

宣告式自動化套件組

使用宣告式自動化套件組,以程式碼形式管理 GitHub 管線。 套件組合可以包含作業和工作的 YAML 定義、使用 Databricks CLI 來管理,而且可以在不同的目標工作區中共用和執行 (例如開發、預備和生產環境)。 欲了解更多資訊,請參閱 《什麼是宣告式自動化套件?》。

  1. 使用 Databricks CLI 建立新的套件組合:

    databricks bundle init
    
  2. 將兩個新的資源檔案新增至套件組合:

    • 一個管線定義檔案(例如, resources/github_pipeline.yml)。 詳見 pipeline.ingestion_definition 與 範例。
    • 一個控制資料擷取頻率的工作定義檔案(例如, resources/github_job.yml)。
  3. 使用 Databricks CLI 部署管線:

    databricks bundle deploy
    

Databricks 筆記本

  1. 將以下筆記本匯入您的 Azure Databricks 工作區:

    取得 Notebook

  2. 保留一號儲存格不變。

  3. 將第三儲存格的管道配置細節修改。 詳見 pipeline.ingestion_definition 與 範例。

  4. 點擊 執行所有。

Examples

利用這些範例來配置你的管線。 source_schema 欄位指定要擷取資料的 GitHub 組織名稱。 destination_table名稱是可選的——如果你沒有提供名稱,連接器就會使用該source_table名稱。

引入單一來源資料表

宣告式自動化套件組

以下管線定義檔案會匯入單一來源資料表:

variables:
  dest_catalog:
    default: main
  dest_schema:
    default: ingest_destination_schema

# The main pipeline for github_dab
resources:
  pipelines:
    pipeline_github:
      name: github_pipeline
      catalog: ${var.dest_catalog}
      schema: ${var.dest_schema}
      ingestion_definition:
        connection_name: <github-connection>
        objects:
          # An array of objects to ingest from GitHub. This example ingests the repositories table.
          - table:
              source_schema: <your_org_name>
              source_table: repositories
              destination_catalog: ${var.dest_catalog}
              destination_schema: ${var.dest_schema}

Databricks 筆記本

以下是一個匯入單一來源資料表的管線規範範例:

pipeline_spec = """
{
  "name": "<pipeline-name>",
  "ingestion_definition": {
    "connection_name": "<github-connection>",
    "objects": [
      {
        "table": {
          "source_schema": "<your_org_name>",
          "source_table": "repositories",
          "destination_catalog": "main",
          "destination_schema": "ingest_destination_schema"
        }
      }
    ]
  }
}
"""
create_pipeline(pipeline_spec)

匯入多個來源資料表

宣告式自動化套件組

以下管線定義檔案會匯入多個來源資料表:

variables:
  dest_catalog:
    default: main
  dest_schema:
    default: ingest_destination_schema

# The main pipeline for github_dab
resources:
  pipelines:
    pipeline_github:
      name: github_pipeline
      catalog: ${var.dest_catalog}
      schema: ${var.dest_schema}
      ingestion_definition:
        connection_name: <github-connection>
        objects:
          # An array of objects to ingest from GitHub. This example ingests the repositories and pull_requests tables.
          - table:
              source_schema: <your_org_name>
              source_table: repositories
              destination_catalog: ${var.dest_catalog}
              destination_schema: ${var.dest_schema}
          - table:
              source_schema: <your_org_name>
              source_table: pull_requests
              destination_catalog: ${var.dest_catalog}
              destination_schema: ${var.dest_schema}

Databricks 筆記本

以下是一個匯入多個來源資料表的管線規範範例:

pipeline_spec = """
{
  "name": "<pipeline-name>",
  "ingestion_definition": {
    "connection_name": "<github-connection>",
    "objects": [
      {
        "table": {
          "source_schema": "<your_org_name>",
          "source_table": "repositories",
          "destination_catalog": "main",
          "destination_schema": "ingest_destination_schema"
        }
      },
      {
        "table": {
          "source_schema": "<your_org_name>",
          "source_table": "pull_requests",
          "destination_catalog": "main",
          "destination_schema": "ingest_destination_schema"
        }
      }
    ]
  }
}
"""
create_pipeline(pipeline_spec)

將擷取限制為特定儲存庫

預設情況下,連接器會接收組織內所有的儲存庫。 若要僅擷取特定的儲存庫,請將 repository_id_selections 下的 github_options 連接器選項設為由數字組成的 GitHub 儲存庫 ID 清單。 此選項會套用至管線中每個以儲存庫為範圍的資料表,因此只要在擷取定義中的其中一個物件上設定即可。 關於該選項的語意及其適用的表格,請參見 連接器選項。

宣告式自動化套件組

variables:
  dest_catalog:
    default: main
  dest_schema:
    default: ingest_destination_schema

resources:
  pipelines:
    pipeline_github:
      name: github_pipeline
      catalog: ${var.dest_catalog}
      schema: ${var.dest_schema}
      ingestion_definition:
        connection_name: <github-connection>
        objects:
          - table:
              source_schema: <your_org_name>
              source_table: repositories
              destination_catalog: ${var.dest_catalog}
              destination_schema: ${var.dest_schema}
              connector_options:
                github_options:
                  repository_id_selections:
                    - '123456789'
                    - '987654321'

Databricks 筆記本

pipeline_spec = """
{
  "name": "<pipeline-name>",
  "ingestion_definition": {
    "connection_name": "<github-connection>",
    "objects": [
      {
        "table": {
          "source_schema": "<your_org_name>",
          "source_table": "repositories",
          "destination_catalog": "main",
          "destination_schema": "ingest_destination_schema",
          "connector_options": {
            "github_options": {
              "repository_id_selections": ["123456789", "987654321"]
            }
          }
        }
      }
    ]
  }
}
"""
create_pipeline(pipeline_spec)

封包工作定義文件

以下是一個範例工作定義檔案,供宣告式自動化套件使用。 這個工作每天都會進行,每次執行間隔正好一天。

resources:
  jobs:
    github_dab_job:
      name: github_dab_job

      trigger:
        periodic:
          interval: 1
          unit: DAYS

      email_notifications:
        on_failure:
          - <email-address>

      tasks:
        - task_key: refresh_pipeline
          pipeline_task:
            pipeline_id: ${resources.pipelines.pipeline_github.id}

常見模式

關於進階的管線配置,請參見 「管理式吞取管線的常見模式」。

下一步

啟動、排程並設定您的流程提醒。 請參閱 常見管線維護任務。

其他資源