ume*_*esh 8 airflow jupyter-notebook papermill airflow-operator
使用 PapermillOperator 运行气流作业时,dag 执行失败。
我在将参数传递给 PapermillOperator 时遇到问题。
我打开papermill_operator.py (packages/ airflow /operators/papermill_operator.py) 并硬编码一行来指定 papameters
def execute(self, context):
for i in range(len(self.inlets)):
pm.execute_notebook(self.inlets[i].location,
self.outlets[i].location,
parameters = dict(msgs="hello")
progress_bar=False, report_mode=True)
Run Code Online (Sandbox Code Playgroud)
然后它的工作
而原始代码是
def execute(self, context):
for i in range(len(self.inlets)):
pm.execute_notebook(self.inlets[i].location,
self.outlets[i].location,
parameters=self.inlets[i].parameters,
progress_bar=False, report_mode=True)
Run Code Online (Sandbox Code Playgroud)
尝试了另一个解决方案 https://github.com/nteract/papermill/issues/324#issuecomment-472446375 它工作正常
我的 DAG 代码是
import airflow
from airflow.models import DAG
from airflow.operators.papermill_operator import PapermillOperator
from datetime import timedelta
args = {
'owner': 'Airflow',
'start_date': airflow.utils.dates.days_ago(2),
}
dag = DAG(
dag_id='9', default_args=args,
schedule_interval='@once',
dagrun_timeout=timedelta(minutes=10))
run_this = PapermillOperator(
task_id="1",
dag=dag,
input_nb="/home/exa00112/abc.ipynb",
output_nb="/home/exa00112/umesh.ipynb",
parameters = dict("msgs" = "hello")
)
run_this
Run Code Online (Sandbox Code Playgroud)
[2019-09-10 20:36:48,806] {logging_mixin.py:95} INFO - [2019-09-10 > > > 20:36:48,806] {datasets.py:62} INFO - 参数 [2019-09] -10 20:36:48,806] { init .py:1580} 错误 - 无法编译非 > 模板节点回溯(最近一次调用):文件“/usr/local/lib/python3.5/dist-packages/气流/模型/ init .py”,第 1441 行,在 _run_raw_task 结果 = task_copy.execute(context=context) 文件“/usr/local/lib/python3.5/dist-packages/airflow/operators/papermill_operator.py”中,第 63 行,在getattr中执行 parameters=self.inlets[i].parameters,文件“/usr/local/lib/python3.5/dist-packages/airflow/lineage/datasets.py”,第 66 行 返回 env.from_string(self._data.get(attr)).render(**self.context) 文件“/home/exa00112/.local/lib/python3.5/site-packages/jinja2/environment.py”,第 880 行,在 from_string 中返回 cls.from_code(self, self.compile(source), globals, None) 文件“/home/exa00112/.local/lib/python3.5/site-packages/jinja2/environment.py”,第 581 行,在编译 defer_init=defer_init) 文件“/home/exa00112/.local/lib/python3.5/site-packages/jinja2/environment.py”,第 543 行,在 _generate optimization=self.optimized) 文件“/ home/exa00112/.local/lib/python3.5/site-packages/jinja2/compiler.py", line 78, in generate raise TypeError('Can\'t compile non template nodes') TypeError: Can't compile non模板节点 [2019-09-10 20:36:48,808] { init .py:1611} 信息 - 将任务标记为失败。
小智 1
这似乎是 Papermill 操作员将无效参数数据结构传递给 Papermill 的一个已知问题(当 papermill 查找字典时传递字符串参数字典)
https://issues.apache.org/jira/browse/AIRFLOW-5774
不确定什么时候会修复,因为它看起来像是一个重复的问题,所以很难追踪
| 归档时间: |
|
| 查看次数: |
1377 次 |
| 最近记录: |