本文介绍 Notebook 类型的 Activity 配置,用于在 Pipeline 中执行 Notebook 文件。
Notebook Activity 执行一个已有的 Notebook 文件,支持混合 SQL Cell 与 Python/Scala Cell。Notebook 中的所有 Cell 按顺序依次执行。
适用场景:
- name: data_analysis type: notebook source: WORKSPACE path: /Workspace/Users/zhang3/notebooks/analysis.notebook sqlEngineType: emr_serverless_spark sqlEngineQueue: default sqlComputingResourceGroupName: default_sql_group sqlComputingResourceGroupId: 1 generalComputingResourceGroupName: default_py_group generalComputingResourceGroupId: 2 parameterValues: biz_date: "{{pipeline.parameters.biz_date}}" region: "cn-beijing" retryPolicy: maxRetries: 2 minRetryIntervalMillis: 60000 position: x: "200" y: "100"
字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| String | 是 | 固定为 |
| Enum | 是 | 代码来源,固定为 |
| String | 是 | Notebook 文件在工作空间中的路径 |
| Enum | 条件必填 | SQL Cell 的计算引擎类型 |
| String | 条件必填 | SQL Cell 的计算队列名称 |
| String | 条件必填 | SQL Cell 的资源组名称 |
| Long | 条件必填 | SQL Cell 的资源组 ID |
| String | 条件必填 | Python/Scala Cell 的资源组名称 |
| Long | 条件必填 | Python/Scala Cell 的资源组 ID |
| Map | 否 | 参数传值(键值对),注入到 Notebook 执行上下文 |
Notebook 的资源组配置取决于其包含的 Cell 类型:
Cell 类型 | 需要配置的资源 |
|---|---|
仅包含 SQL Cell |
|
仅包含 Python/Scala Cell |
|
混合 SQL 和 Python/Scala | 以上全部 |
值 | 说明 |
|---|---|
| EMR Serverless Spark 引擎 |
| Presto 引擎 |
| ByteHouse 引擎 |
通过 parameterValues 向 Notebook 传入参数,参数在 Notebook 中可直接作为变量使用:
parameterValues: biz_date: "{{pipeline.parameters.biz_date}}" threshold: "100"
在 Notebook Python Cell 中引用:
# 参数自动注入为同名变量 print(biz_date) # 输出:2026-06-01 print(threshold) # 输出:100
在 Notebook SQL Cell 中引用:
SELECT * FROM orders WHERE dt = '${biz_date}'
建议 | 说明 |
|---|---|
明确资源组配置 | 根据 Notebook 中实际使用的 Cell 类型配置对应资源组,避免运行时报错。 |
参数化日期 | 使用 |
控制 Notebook 长度 | 单个 Notebook 不宜过长,复杂逻辑建议拆分为多个 Activity。 |
避免交互式操作 | Pipeline 中的 Notebook 以非交互模式运行,不支持手动输入和 Widget。 |