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,
    )

本条目有帮助吗?