

workflow 之 Dagster 基本用法(qbit)
source link: https://xie.infoq.cn/article/be882b0063ff2c5c95335bc57
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

workflow 之 Dagster 基本用法(qbit)
- 2022 年 1 月 11 日
本文字数:1536 字
阅读完需:约 5 分钟

Python 3.8
poetry 1.1.7
dagster 0.13.13
用
poetry
初始化项目后在pyproject.toml
添加以下依赖,然后运行poetry update
# 国内镜像源(可选)
[[tool.poetry.source]]
name = "aliyun"
url = "https://mirrors.aliyun.com/pypi/simple/"
default = true
[tool.poetry.dependencies]
python = "^3.8"
dagster = "~0.13.13"
dagit = "~0.13.13"
test_dagster.py
# encoding: utf-8
# author: qbit
# date: 2022-01-11
# summary: 测试 dagster,加减乘除
from dagster import get_dagster_logger, job, op
loggerDag = get_dagster_logger()
@op
def OpSeed():
r""" 种子函数,生成初始参数 """
return (2, 1)
@op
def OpAdd(seed):
r""" 读入参数做加法 """
x, y = seed
result = x + y
loggerDag.info(f"{x} + {y} = {result}")
return result
@op
def OpSubtract(x):
r""" 读入参数减 1 """
result = x - 1
loggerDag.info(f"{x} - 1 = {result}")
return result
@op
def OpMultiply(x):
r""" 读入参数乘以 2 """
result = x * 2
loggerDag.info(f"{x} * 2 = {result}")
return result
@op
def OpDivide(x, y):
r""" 读入参数做除法 """
result = y / x
loggerDag.info(f"{y} / {x} = {result}")
return result
@job
def arithmetic():
r""" 四则运算 """
seed = OpSeed()
addResult = OpAdd(seed)
subResult = OpSubtract(addResult)
mulResult = OpMultiply(addResult)
OpDivide(subResult, mulResult)
if __name__ == "__main__":
result = arithmetic.execute_in_process(run_config={"loggers": {"console": {"config": {"log_level": "info"}}}})
直接使用
python
运行
poetry run python test_dagster.py
2022-01-11 16:29:48 +0800 - dagster - INFO - arithmetic - be4946d9-c8ec-4b4a-bebb-a09d47d1b231 - OpAdd - 2 + 1 = 3
2022-01-11 16:29:48 +0800 - dagster - INFO - arithmetic - be4946d9-c8ec-4b4a-bebb-a09d47d1b231 - OpMultiply - 3 * 2 = 6
2022-01-11 16:29:48 +0800 - dagster - INFO - arithmetic - be4946d9-c8ec-4b4a-bebb-a09d47d1b231 - OpSubtract - 3 - 1 = 2
2022-01-11 16:29:48 +0800 - dagster - INFO - arithmetic - be4946d9-c8ec-4b4a-bebb-a09d47d1b231 - OpDivide - 6 / 2 = 3.0
用 daster
运行
编辑配置文件
run_config.yaml
loggers:
console:
config:
log_level: INFO
poetry run dagster job execute -f test_dagster.py -c run_config.yaml
To persist information across sessions, set the environment variable DAGSTER_HOME to a directory to use.
2022-01-11 16:35:25 +0800 - dagster - INFO - arithmetic - b14bd796-f0dc-4f79-91a8-6d8a8689b105 - OpAdd - 2 + 1 = 3
2022-01-11 16:35:30 +0800 - dagster - INFO - arithmetic - b14bd796-f0dc-4f79-91a8-6d8a8689b105 - OpSubtract - 3 - 1 = 2
2022-01-11 16:35:30 +0800 - dagster - INFO - arithmetic - b14bd796-f0dc-4f79-91a8-6d8a8689b105 - OpMultiply - 3 * 2 = 6
2022-01-11 16:35:35 +0800 - dagster - INFO - arithmetic - b14bd796-f0dc-4f79-91a8-6d8a8689b105 - OpDivide - 6 / 2 = 3.0
用 dagit
运行
poetry run dagit -f test_dagster.py
用浏览器打开
http://127.0.0.1:3000
查看
点击
Launchpad
标签页,点击Launch Run
按钮运行,运行结果如下:
出自 qbit snap
版权声明: 本文为 InfoQ 作者【qbit】的原创文章。
原文链接:【https://xie.infoq.cn/article/be882b0063ff2c5c95335bc57】。文章转载请联系作者。

qbit
开箱即用,拿走不谢。 2018.10.09 加入
软件设计师 网络工程师
Recommend
-
35
README.md
-
4
In Conversation with Elementl (Dagster), Meroxa and Superconductive (Great Expectations) This last year has seen tremendous levels of activity for early stage startups in the data infrastructure ecosystem. A...
-
8
Elasticsearch 7.x 配置 IK 自定义词典(qbit)IK Dictionary Configuration
-
6
github:https://github.com/xonsh/xonshpip install pipx -i https://mirrors.aliyun.com/pypi/simple/ pipx install xonsh[full]...
-
9
简易的 shell 脚本:https://github.com/qbit-git/m...bash modern_cli_ubuntu2004.sh...
-
10
Iceberg+Spark+Trino+Dagster大数据分析开源技术栈 | by ZD
-
2
The data orchestrator that puts developer experience firstAfter three years of development, Dagster 1.0 and Dagster Cloud are now ready for prime time, and we are excited to share Dagster Cloud with all of you at Product Hunt on GA lau...
-
4
Dabbling with Dagster - Part 1Dissecting the Octopus
-
4
Dagster使用DuckDB从头构建一个穷人的数据湖 解道Jdon
-
6
March 16, 2023 • 7 minute readTracking the Fake GitHub Star Black Market with Dagster, dbt and BigQueryIt's easy for an open-source project to buy fake GitHub stars. We share two approaches for detecting them.
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK