DatabricksCopyIntoOperator

使用 DatabricksCopyIntoOperator operator 利用 COPY INTO 命令將資料匯入到 Databricks 表中。

使用 Operator

該 Operator 從指定位置載入資料到表中,使用已配置的 endpoint。唯一的必填引數是

  • table_name - 表名的字串

  • file_location - 要載入資料的 URI 的字串

  • file_format - 指定要載入資料的檔案的格式的字串。支援的格式包括 CSV, JSON, AVRO, ORC, PARQUET, TEXT, BINARYFILE

  • sql_endpoint_name (要使用的 Databricks SQL endpoint 名稱) 或 http_path (Databricks SQL endpoint 或 Databricks cluster 的 HTTP 路徑) 中的一個。

其他引數是可選的,可以在類文件中找到。

示例

匯入 CSV 資料

以下是使用 DatabricksCopyIntoOperator 將 CSV 資料匯入到表中的示例用法:

tests/system/databricks/example_databricks_sql.py

    # Example of importing data using COPY_INTO SQL command
    import_csv = DatabricksCopyIntoOperator(
        task_id="import_csv",
        databricks_conn_id=connection_id,
        sql_endpoint_name=sql_endpoint_name,
        table_name="my_table",
        file_format="CSV",
        file_location="abfss://container@account.dfs.core.windows.net/my-data/csv",
        format_options={"header": "true"},
        force_copy=True,
    )

本條目有幫助嗎?