dbt flags 简单说明二

以前简单说过,实际上dbt 的flags 提供的参数还是不少的

参考内容

  • 一个参考内容
    可以看出还是不少信息的
flags Namespace(WRITE_JSON=True, WARN_ERROR=None, PROFILES_DIR='xxxx/.dbt', INDIRECT_SELECTION='eager', LOG_PATH='xxxxx/logs', TARGET_PATH=None, FAIL_FAST=False, USE_COLORS=True, VERSION_CHECK=True, CACHE_SELECTED_ONLY=False, WARN_ERROR_OPTIONS=WarnErrorOptions(include=[], exclude=[]), USE_EXPERIMENTAL_PARSER=False, LOG_CACHE_EVENTS=False, QUIET=False, LOG_FORMAT='default', DEBUG=False, PARTIAL_PARSE=True, INTROSPECT=True, STATIC_PARSER=True, NO_PRINT=None, PRINTER_WIDTH=80, SEND_ANONYMOUS_USAGE_STATS=True, INVOCATION_COMMAND='dbt run -s dalongv2', FULL_REFRESH=False, STORE_FAILURES=False, WHICH='run')
  • 几个比较有用的参数
    目前FULL_REFRESH,WHICH ,STORE_FAILURES ,SEND_ANONYMOUS_USAGE_STATS 是几个我们可能会使用到的
    FULL_REFRESH 是判断是否是全量刷新的,WHICH 是判断当前执行的命令的(主要包含了run,build,test ...)STORE_FAILURES 是是否进行
    测试异常存储的,SEND_ANONYMOUS_USAGE_STATS 是发送匿名上报信息的,这个是可以关闭的

内部处理

对于flags 处理实际包装了set_from_args以及get_flags,get_flags 会结合当前上下文信息进行数据准备

  • set_from_args 处理
def set_from_args(args: Namespace, project_flags):
    global GLOBAL_FLAGS
    from dbt.cli.main import cli
    from dbt.cli.flags import Flags, convert_config
 
    # we set attributes of args after initialize the flags, but project_flags
    # is being read in the Flags constructor, so we need to read it here and pass in
    # to make sure we use the correct project_flags
    profiles_dir = getattr(args, "PROFILES_DIR", None) or getattr(args, "profiles_dir", None)
    project_dir = getattr(args, "PROJECT_DIR", None) or getattr(args, "project_dir", None)
    if profiles_dir and project_dir:
        from dbt.config.project import read_project_flags
 
        project_flags = read_project_flags(project_dir, profiles_dir)
 
    # make a dummy context to get the flags, totally arbitrary
    ctx = cli.make_context("run", ["run"])
    flags = Flags(ctx, project_flags)
    for arg_name, args_param_value in vars(args).items():
        args_param_value = convert_config(arg_name, args_param_value)
        object.__setattr__(flags, arg_name.upper(), args_param_value)
        object.__setattr__(flags, arg_name.lower(), args_param_value)
    flags.set_common_global_flags()
    GLOBAL_FLAGS = flags  # type: ignore

说明

以上属于一个进一步说明

参考资料

core/dbt/cli/flags.py
core/dbt/flags.py
https://docs.getdbt.com/reference/dbt-jinja-functions/flags

posted on 2024-05-09 00:04  荣锋亮  阅读(10)  评论(0编辑  收藏  举报

导航