数据验证工具使用教程
1. 项目目录结构及介绍
数据验证工具(Data Validation Tool,简称DVT)的目录结构如下:
.
├── .github
│ ├── ci
│ └── workflows
├── ci
├── data_validation
│ ├── __init__.py
│ ├── cli.py
│ ├── config.py
│ ├── connections.py
│ ├── validations.py
│ └── utils.py
├── docs
│ ├── Installation.md
│ ├── Usage.md
│ ├── Validation_Logic.md
│ ├── contributing.md
│ ├── code_of_conduct.md
│ └── license.md
├── samples
├── terraform
├── tests
│ ├── __init__.py
│ ├── test_cli.py
│ ├── test_config.py
│ ├── test_connections.py
│ ├── test_validations.py
│ └── test_utils.py
├── third_party/
│ └── ibis
├── .coveragerc
├── .flake8
├── .gitignore
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── RELEASING.md
├── SECURITY.md
├── cloudbuild.yaml
├── noxfile.py
├── setup.cfg
└── setup.py
主要目录和文件介绍:
.github
: 包含GitHub Actions工作流文件,用于自动化测试和构建。data_validation
: 包含数据验证工具的核心Python代码。docs
: 存放项目的文档,包括安装、使用、贡献指南等。samples
: 示例配置文件和代码示例。tests
: 包含对数据验证工具的单元测试。third_party
: 存放第三方库的代码,如Ibis框架。- 其他文件:包括项目配置文件、构建脚本、许可证等。
2. 项目的启动文件介绍
项目的启动文件是data_validation/cli.py
。这个文件定义了命令行界面的入口点,用户可以通过命令行来运行数据验证工具。以下是一个简单的命令行使用示例:
data-validation validate column --source-conn <source_connection> --target-conn <target_connection> --tables-list <table_mapping>
用户需要指定源连接和目标连接,以及要验证的表。
3. 项目的配置文件介绍
数据验证工具支持使用YAML或JSON格式的配置文件来存储验证配置。配置文件可以定义连接信息、验证规则、输出结果处理等。
YAML配置文件示例:
connections:
source:
type: postgres
host: localhost
port: 5432
database: source_db
user: user
password: pass
target:
type: bigquery
project_id: project-id
dataset_id: dataset-id
validations:
- type: column
tables:
- source_schema.table1:target_schema.table1
aggregations:
- count: '*'
- sum: 'column1'
result_handler: project-id.dataset.table
在这个配置文件中,定义了源和目标的连接信息,以及一个列验证规则,该规则对source_schema.table1
和target_schema.table1
中的列进行计数和求和,并将结果存储在BigQuery中的project-id.dataset.table
。
用户可以根据需要创建自己的配置文件,并通过--config-file
或--config-file-json
参数在命令行中指定配置文件的路径。