taolib.testing.data_sync.pipeline.validator#
数据验证器。
在 Transform 和 Load 之间对文档进行验证。
Attributes#
Classes#
数据验证器。 |
Module Contents#
- taolib.testing.data_sync.pipeline.validator.logger#
- class taolib.testing.data_sync.pipeline.validator.DataValidator#
数据验证器。
支持注册多个验证函数,在文档写入目标数据库前进行校验。
每个验证函数签名为:
def my_validator(doc: dict, ctx: TransformContext) -> list[str]
返回空列表表示验证通过,否则返回错误消息列表。
- _validators: list[collections.abc.Callable[[dict[str, Any], taolib.testing.data_sync.pipeline.protocols.TransformContext], list[str]]] = []#
- register(fn: collections.abc.Callable[[dict[str, Any], taolib.testing.data_sync.pipeline.protocols.TransformContext], list[str]]) None#
注册验证函数。
- 参数:
fn -- 验证函数,接收文档和上下文,返回错误消息列表
- async validate(documents: list[dict[str, Any]], context: taolib.testing.data_sync.pipeline.protocols.TransformContext) taolib.testing.data_sync.pipeline.protocols.ValidateResult#
验证文档批次。
- 参数:
documents -- 待验证的文档列表
context -- 转换上下文
- 返回:
验证结果(通过的文档 + 失败记录)