Unique Constraint Check
Documentsunique_constraint_checkUnique Constraint Check is an Agent Skill for documents published in the cas-bigdatalab/piflow repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
唯一性约束校验工具。检查指定字段的值是否在全表中唯一,标记重复出现的值所在行 (保留首次出现),支持空值跳过。当用户提到唯一性检查、重复值检测、主键约束等需求时使用此skill。
QUICK START
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/cas-bigdatalab/piflow/blob/HEAD/workspace/skills/unique_constraint_check/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/unique-constraint-check, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
unique_constraint_check 唯一性约束校验Skill
功能概述
检查字段值是否在全表中唯一。多字段时分别独立检查(非组合唯一键),空值默认跳过不参与检测。适用于主键约束、业务唯一键(如邮箱、手机号)验证。
处理逻辑
- 读取输入数据表
- 对每个 unique_fields 中的字段分别执行 duplicated(keep='first')
- 空值(空串/nan/None/NA/null)默认跳过
- 重复行标记 qc_mark(首次出现保留,后续重复标记)
- 输出每字段的重复统计和样例值
支持的文件格式
- CSV (.csv) / TSV (.tsv) / Excel (.xls, .xlsx) / SPSS (.sav)
使用方法
# 检查 email 和 phone 分别唯一
python scripts/unique_constraint_check.py \
--input_path data.csv \
--output_path checked.csv \
--unique_fields "email,phone" \
--qc_mark QC0027
参数说明
| 参数 | 必填 | 说明 |
|---|---|---|
--input_path | 是 | 输入文件路径 |
--output_path | 是 | 输出文件路径 |
--unique_fields | 是 | 唯一字段,逗号分隔(分别检查) |
--allow_null | 否 | 允许多个空值(开启后空值不视为重复) |
--qc_mark | 是 | 质控标识 |
--mark_field_name | 否 | 质控标识字段名(默认 QC0000) |
输出示例
[QC FAIL] 唯一性约束未通过 (2 项):
[email] 1 行重复,示例: ['[email protected]']
[phone] 1 行重复,示例: ['13800138000']
注意事项
- 多字段是分别独立检查(如
email,phone检查 email 唯一 AND phone 唯一),不是组合唯一键 - 如有组合唯一需求(如 email+phone 同时相同),请先用 Pi 技能合并字段再检查
- 空值默认跳过,使用
--allow_null可将空值也视为可重复的值 - keep='first' 保留首次出现,后续重复标记