【问题标题】:How would you parameterize Dagster pipelines to run same solids with multiple different configurations/assets?您将如何参数化 Dagster 管道以运行具有多种不同配置/资产的相同实体?
【发布时间】:2020-08-03 10:46:09
【问题描述】:

假设我创建了一个包含以下实体的 Dagster 管道:

  1. 从文件执行 SQL 查询并获取结果
  2. 将结果写入表格

我想同时为 10 个不同的表执行此操作。每个表都需要不同的 SQL 查询。 最好的方法是什么?

【问题讨论】:

    标签: python dagster


    【解决方案1】:

    一种方法是使用实​​体工厂。 run_query_solid_factorywrite_results_solid_factory 是实体工厂,它们接受输入(例如名称和查询或表)并返回可以在管道中运行的实体。 summary_report 等待所有上游实体完成,然后打印出摘要信息。

    def run_query_solid_factory(name, query):
        @solid(name=name)
        def _run_query(context):
            context.log.info(query)
            return 'result'
    
        return _run_query
    
    def write_results_solid_factory(name, table):
        @solid(name=name)
        def _write_results(context, query_result):
            context.log.info(table)
            context.log.info(query_result)
            return 'success'
    
        return _write_results
    
    @solid
    def summary_report(context, statuses):
        context.log.info(' '.join(statuses))
    
    @pipeline
    def pipeline():
        solid_output_handles = []
        queries = [('table', 'query'), ('table2', 'query2')]
        for table, query in queries:
            get_data = run_query_solid_factory('run_query_{}'.format(query), query)
            write_results = write_results_solid_factory('write_results_to_table_{}'.format(table), table)
            solid_output_handles.append(write_results(get_data()))
    
        summary_report(solid_output_handles)
    

    上一个答案:

    我建议创建一个composite_solid,它由一个处理 (1) 的实体和一个处理 (2) 的实体组成。然后,您可以为 10 个表中的每一个表 aliascomposite_solid 一次,这样您就可以通过 config 传入 SQL 查询(参见 tutorial

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-07
    • 2016-04-26
    • 2017-06-17
    • 2018-05-29
    • 1970-01-01
    • 2014-04-08
    • 2020-03-28
    相关资源
    最近更新 更多