Skip to main content

xaudit 用法

命令

xaudit CONFIG_PATH

读取单个 .sql 或 .txt 配置文件,生成 HTML 报告。默认输出到当前目录,文件名为 <配置文件名>.html。

xaudit CONFIG_PATH --output report.html
xaudit CONFIG_PATH -o report.html

读取单个配置文件,并把报告写入指定路径。--output 只能和单个配置文件一起使用,不能用于目录扫描。

xaudit DIRECTORY

按文件名顺序扫描目录第一层的 .sql 和 .txt 配置文件,并在该目录下分别生成 <配置文件名>.html。

xaudit

扫描当前目录第一层的 .sql 和 .txt 配置文件。

xaudit --version

查看版本号。

配置文件格式

配置文件使用 .sql 或 .txt 后缀。每个配置块之间用 ---- 分隔。

  • 必须定义两个 -- connection: 块;第一个连接用于每个对比的第一段 SQL,第二个连接用于第二段 SQL。
  • -- url: 必须是完整的字面量数据库 URL,不能写环境变量。
  • 每个 -- compare: 块必须包含两个以分号结束的 SQL 语句。
  • -- tolerance: 可作为全局容差,也可写在单个 -- compare: 块中覆盖全局容差。
  • -- keys: 可作为全局主键列,也可写在单个 -- compare: 块中覆盖全局主键列;多个列用逗号分隔。未配置时默认使用查询结果第一列作为主键列。
  • -- param: 支持固定值列表或查询结果;参数名只能使用大写字母、数字和下划线。
  • SQL 中使用 {{PARAM_NAME}} 引用参数;多个参数会按笛卡尔积展开为多个对比。
  • -- rule: 格式为 <expression> => <result>,结果支持字符串、IGNORE、NONE。

rule 表达式示例

rule 使用 Python 表达式语法,布尔与/或需要写成小写 and / or。

-- rule: FA['id'] == IBOR['id'] and abs(FA['amount'] - IBOR['amount']) < 1 => IGNORE
-- rule: FA['status'] == 'CANCELLED' or IBOR['status'] == 'CANCELLED' => "cancelled record"
-- rule: (FA['id'] == IBOR['id']) and (FA['amount'] != IBOR['amount']) => "same id amount diff"

最简范例

保存为 amount_check.sql:

-- connection: FA
-- url: postgresql://user:password@localhost:5432/source_db
----
-- connection: IBOR
-- url: postgresql://user:password@localhost:5432/target_db
----
-- compare: amount_check
select id, amount
from source_amount;

select id, amount
from target_amount;

运行:

xaudit amount_check.sql --output amount_check.html

全功能范例

保存为 full_check.sql:

-- connection: FA
-- url: postgresql://ibor_user:ibor_user@localhost:5432/ibor-demo
----
-- connection: IBOR
-- url: postgresql://ibor_user:ibor_user@localhost:5432/ibor-demo
----
-- tolerance: 0.01
----
-- keys: trade_date, portfolio_id, secu_code
----
-- param: TRADE_DATE
-- values: 20260604,20260605
----
-- param: PORTFOLIO_ID
-- connection: IBOR
select distinct portfolio_id
from irmp.ibor_bond_position
where trade_date in (20260604, 20260605)
  and secu_code like '%HK'
  and calc_basis = '1'
  and invest_type = '1';
----
-- compare: total_pnl
-- tolerance: 0.001
-- keys: trade_date, portfolio_id, secu_code
-- rule: abs(FA['ytd_total_pnl'] - IBOR['ytd_total_pnl']) < 1 => "rounding difference"
-- rule: FA['trade_date'] == IBOR['trade_date'] => IGNORE
select
  cast(replace(enddate, '-', '') as int) as trade_date,
  concat(t1.stkid, '.', 'HK') as secu_code,
  'XIR_' || book as portfolio_id,
  reportpl as ytd_total_pnl
from ods_faas.bd_ods_faas_glhs_bond_rpt_nxt_his t1
where cast(replace(enddate, '-', '') as int) = {{TRADE_DATE}}
  and 'XIR_' || book = {{PORTFOLIO_ID}};

select
  trade_date,
  portfolio_id,
  secu_code,
  ytd_total_pnl
from irmp.ibor_bond_position
where secu_code like '%HK'
  and trade_date = {{TRADE_DATE}}
  and portfolio_id = {{PORTFOLIO_ID}}
  and calc_basis = '1'
  and invest_type = '1';

运行:

xaudit full_check.sql --output full_check.html

Metadata

Release files for ibor-audit-tool 0.1.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ibor-audit-tool 0.1.10
File Size Uploaded
ibor_audit_tool-0.1.10.tar.gz 52.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ibor-audit-tool 0.1.10
File Interpreter ABI Platform
ibor_audit_tool-0.1.10-py3-none-any.whl Python 3 none any Details

Total release size: 80.1 kB

Release files / ibor_audit_tool-0.1.10.tar.gz

Download URL ibor_audit_tool-0.1.10.tar.gz
Size 52.6 kB
Tags Source
SHA-256 checksum
How to use checksums
726532a44d950146dfbdc894658abd2680a3a2eb345a462d1515348adc4590d7
BLAKE2b-256 checksum
How to use checksums
10eacf5829e5b2daa987194fe5388a8dd292233a1b2763b74f8fcbce454a3f74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / ibor_audit_tool-0.1.10-py3-none-any.whl

Download URL ibor_audit_tool-0.1.10-py3-none-any.whl
Size 27.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9c328f4df8223b9a4c5e66423f81717629d5f1e3deb1dd917fcb3b81825de7b
BLAKE2b-256 checksum
How to use checksums
7d2911b50e9418a896c3541f397ce92f8e3260d047c982fca2f902372815f337
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.10 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page