我试图将执行日期作为运行时参数传递给 postgres 运算符
class MyPostgresOperator(PostgresOperator):
template_fields = ('sql','parameters')
task = MyPostgresOperator(
task_id='test_date',
postgres_conn_id='redshift',
sql="test_file.sql",
parameters={'crunch_date':'{{ ds }}'},
dag=dag
)
Run Code Online (Sandbox Code Playgroud)
然后我尝试在 sql 查询中使用此参数来接受 dag 传递的值
select
{{ crunch_date }} as test1,
Run Code Online (Sandbox Code Playgroud)
dag 正确发送参数,但是查询只是采用空值而不是传递的执行日期。有没有办法让 postgresql with redshift 接受这个参数的正确值?
我想将数据从 Redshift 数据库卸载到 S3 存储桶,稍后将用于复制到另一个数据库中。我已经写了我的 DAG 如下:
from airflow.operators import RedshiftToS3Transfer
from datetime import datetime, timedelta
from airflow import DAG
default_args = {
'owner': 'me',
'start_date': datetime.today(),
'max_active_runs': 1,
}
dag = DAG(dag_id='redshift_S3',
default_args=default_args,
schedule_interval="@once",
catchup=False
)
unload_to_S3 = RedshiftToS3Transfer(
task_id='unload_to_S3',
schema='schema_name',
table='table_name',
s3_bucket='bucket_name',
s3_key='s3_key',
redshift_conn_id='redshift',
aws_conn_id='my_s3_conn',
dag=dag
)
Run Code Online (Sandbox Code Playgroud)
但我收到错误消息“损坏的 DAG:无法从‘airflow.operators’(未知位置)导入名称‘RedshiftToS3Transfer’”。关于如何导入 RedshiftToS3Transfer 的任何想法都会有所帮助。