You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Great Expectations规则化分析器的Expectation Suite如何保存与复用?

Great Expectations Rule-Based Profiler生成Suite的保存与验证指南

一、Suite的保存方式与存储位置

  • 保存操作:
    若通过CLI或UI生成Suite,完成后会自动保存到项目目录;若用代码调用Rule-Based Profiler,生成Suite后需调用suite.save()方法手动触发保存,示例代码:
    from great_expectations.data_context import DataContext
    from great_expectations.profiler.rule_based_profiler import RuleBasedProfiler
    
    # 初始化数据上下文
    context = DataContext()
    # 初始化Profiler(需提前配置规则、数据源等)
    profiler = RuleBasedProfiler(
        name="my_profiler",
        config_version=1.0,
        rules={...},  # 自定义规则配置
        data_context=context
    )
    # 生成Expectation Suite
    suite = profiler.build_suite()
    # 保存Suite到本地
    suite.save()
    
  • 存储位置:保存后的Suite以JSON格式存放在项目根目录的expectations/文件夹下,文件名对应创建Suite时指定的名称(如user_behavior_suite.json)。

二、用Suite验证未来数据

方式1:代码直接验证

加载已保存的Suite,关联新数据批次后执行验证:

# 加载已保存的Suite
suite = context.get_expectation_suite(expectation_suite_name="user_behavior_suite")

# 定义新数据的批次请求(根据数据源类型调整参数)
batch_request = {
    "datasource_name": "my_datasource",
    "data_asset_name": "new_user_data",
    "batch_identifiers": {"batch_id": "latest"}
}

# 获取新数据批次
batch = context.get_batch(batch_request, suite)

# 运行验证
validation_results = context.run_validation_operator(
    "action_list_operator",
    assets_to_validate=[batch]
)

# 查看验证结果
print(f"验证是否通过:{validation_results['success']}")

方式2:CLI+Checkpoint验证

  1. 在项目checkpoints/目录下创建Checkpoint配置文件(如validate_new_data.yml),关联目标Suite与新数据源:
name: validate_new_data
config_version: 1.0
class_name: SimpleCheckpoint
run_name_template: "%Y%m%d-%H%M%S-validate-new-data"
expectation_suite_name: user_behavior_suite
batch_request:
  datasource_name: my_datasource
  data_asset_name: new_user_data
  batch_identifiers:
    batch_id: latest
action_list:
  - name: store_validation_result
    action:
      class_name: StoreValidationResultAction
  - name: store_evaluation_params
    action:
      class_name: StoreEvaluationParametersAction
  1. 在项目根目录执行CLI命令触发验证:
great_expectations checkpoint run validate_new_data

内容的提问来源于stack exchange,提问作者Heether

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 13:27:17