GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Data Contract CLI
  • Join Community
  • Quickstart
  • Open Data Contract Standard
  • Installation
  • Test your Data
  • Amazon Athena
  • Amazon Redshift
  • Amazon S3
  • Amazon S3 Tables
  • Apache Hive
  • Apache Iceberg
  • Apache Impala
  • Azure Blob / ADLS

This view

  • Original page
  • New address

GeezerVison is showing cli.datacontract.com — Test your Data | Data Contract CLI

datacontract test connects to the data source defined in the contract's servers block and runs schema and quality tests to verify that the actual data complies with the data contract.

Data Contracts and Data Quality, explained in 2 minutes. Entropy Explains #9: slides and video
datacontract test --server production datacontract.yaml

Supported connections​

SnowflakeImport a contract from your tables and test in 5 minutesGoogle BigQueryImport a contract from your tables and test in 5 minutesDatabricksImport a contract from Unity Catalog and test in 5 minutesAmazon RedshiftImport a contract from your tables and test in 5 minutesPostgresPostgres and Postgres-compatible (e.g. RisingWave)Amazon S3CSV, JSON, Delta, Parquet on S3 / S3-compatible storageAmazon S3 TablesImport and test Iceberg tables using AWS credentialsDuckDBTables inside a DuckDB database fileLocal filesTry it in 60 seconds — no credentials neededAmazon AthenaAthena over data in S3Apache HiveTables in a HiveServer2Apache IcebergTables in a REST catalog (Polaris, Nessie, Unity, Glue, S3 Tables)Apache ImpalaImpalaAzure Blob / ADLSFiles on Azure Blob storage or ADLS Gen2ClickHouseClickHouse databasesDremioTables and views in Dremio sources, spaces and foldersExasolExasol databasesGoogle Cloud StorageFiles on GCS via S3 interoperabilityHTTP APIJSON and YAML HTTP APIs, GET and POST, one or more endpointsKafkaKafka topics (experimental)Microsoft SQL ServerSQL Server, Azure SQL, Synapse, FabricMySQLMySQL / MariaDBOracleOracle DatabaseSAP HANASAP HANA Cloud and SAP Datasphere Open SQL schemasSpark DataFrameIn-memory Spark DataFrames (programmatic)TrinoTrino (basic, JWT, OAuth2)XML filesXML documents, with a contract from their XML Schema
tip

Missing a source? Open an issue on GitHub.

Each connection requires the matching optional dependency (extra), or install everything with datacontract-cli[all].

Every other server type in ODCS, including the ones added in v3.2.0 (teradata, ingres, vectorwise, versant, poet), lints and exports, but test reports a warning that it cannot connect. fastobjects and btrieve are the ODCS synonyms of poet and zen, and postgresql of postgres.

How it works​

The CLI uses different engines based on the server type. Internally it connects with DuckDB, Spark, or a native connection, executes most checks with ibis (compiling dialect-specific SQL per backend), and validates JSON with fastjsonschema.

Checks fall into categories you can select with --checks:

  • properties — the schema attributes: presence, types, required, unique, primary keys, and logicalTypeOptions. schema is kept as a legacy alias. Not every ODCS attribute produces a check — see What is not checked if one you declared appears to have no effect.
  • quality — the quality rules defined in the contract.
  • slaProperties — the service levels defined in the contract. servicelevel is kept as a legacy alias.
  • custom — custom checks.

Omit --checks to run all of them.

note

Selecting properties (or its legacy alias schema) is not metadata-only. The category says where a rule is defined in the contract, not how the check reads the database: constraints such as required, unique, enum, pattern, and ranges read column values and may scan data.

Use --metadata-only to skip these value-level checks: only the schema-reading checks (field presence and types) run, and the rest show as skipped. One exception: on JSON file and API sources, record validation still reads every record; --metadata-only does not disable it.

--dimension cuts across those categories instead: it selects every check that measures one aspect of data quality — the quality rules tagged with that dimension plus the schema and service level checks that measure the same thing.

--quality-id and --tag go the other way and narrow the run to individual quality rules: --quality-id runs the one rule declaring that id, --tag runs every rule declaring that tag, and neither runs any schema or service level check.

Metadata checks​

On S3, Google Cloud Storage, Azure, and local files, a server with format: metadata is tested against the metadata of its files (size, content type, last modified, …) instead of their contents.

On databases, point the server's schema (or database) at the catalog instead, and the schemas name its views. Every check works on them as on a table:

Server typeCatalogExample views
Postgresschema: pg_catalogpg_stat_user_tables, pg_tables, pg_class
ClickHousedatabase: systemtables, parts
DuckDBschema: information_schematables, columns
Exasolany schema: the system views are globalEXA_ALL_OBJECTS, EXA_ALL_TABLES
MySQLdatabase: information_schemaTABLES, COLUMNS
Oracleschema: SYSALL_TABLES, ALL_TAB_COLUMNS
Trinoschema: information_schematables, columns

The catalog views cover the whole database; narrow them to the data with --filter or a SQL rule, such as database = 'default'.

servers:
- server: catalog
type: clickhouse
host: localhost
port: 8123
database: system
schema:
- name: tables
properties:
- name: total_bytes
logicalType: integer
logicalTypeOptions:
maximum: 1000000000000

Dry Run​

--dry-run reports the checks a run would execute and stops there. No data is read from the server, so every reported check has the result skipped (or warning if they cannot be planned).

datacontract test datacontract.yaml --dry-run

A dry run needs no server credentials, which makes it usable on a pull request build that has no warehouse access. A dry run exits 0: it is a plan, not a verdict.

note

A dry run is not offline in general: a contract that references external semantics still fetches them. This is necessary to build all of its checks.

caution

Azure servers with format: metadata do not support dry runs.

Configuring the connection​

The connection details (host, catalog, location, …) live in the contract's servers block; credentials are provided as environment variables.

servers:
- server: production
type: postgres # selects the connection engine
host: localhost
port: 5432
database: postgres
schema: public

Environment variables are also loaded from a .env file in the current working directory (or the nearest parent directory containing one). Already-set environment variables take precedence over values from .env.

# .env
DATACONTRACT_POSTGRES_USERNAME=postgres
DATACONTRACT_POSTGRES_PASSWORD=postgres

Server fields may also hold ${VAR} or ${VAR:-default} references (ODCS v3.2.0), which test resolves from the environment when it connects; see Variables in the data contract.

The page for each source above lists its servers fields and the environment variables it expects. Credentials can also come from a YAML config file (--config-file), the Python Config class, or per-request API headers; see Configuration for all mechanisms and their precedence.

Options​

--server, --schema-name, --checks, --dimension, --quality-id, and --tag narrow down what runs. --output with --output-format writes the results to a file as json, junit, or oors (Open Observability Results Standard v0.8.1, experimental; a file name ending in .oors.yaml or .oors.json selects it, and .yaml writes YAML), --publish sends them to a URL, and --include-failed-samples collects a small sample of the offending rows. See the full test command reference.

For CI/CD pipelines, use the ci command. It runs the same checks as test, takes several contracts at once, and adds annotations, summaries, and exit-code control.

Testing only a subset of rows​

On large tables, a full scan for every test run is slow and expensive. --filter restricts the checks to the rows matching a SQL predicate, written in the dialect of the server:

# Test only the rows ingested in the last 24 hours
datacontract test datacontract.yaml --server production --filter "ingested_at >= CURRENT_TIMESTAMP - INTERVAL '24 hours'"

# Test a specific partition
datacontract test datacontract.yaml --server production --filter "batch_id = '2026-07-31'"

--filter requires that a single schema is tested. If the contract defines several schemas, either select one with --schema-name or pass --filters with a JSON object mapping schema name to predicate:

datacontract test datacontract.yaml --server production \
--filters '{"orders": "ingested_at >= CURRENT_DATE - 1", "line_items": "ingested_at >= CURRENT_DATE - 1"}'

The predicate references the columns of the schema unqualified. It applies to all row-based checks: row counts, missing/invalid values, duplicates, freshness, retention, and failed-row samples. Schema checks (column presence and types) read metadata, not rows, so a filter does not change them. Custom SQL quality checks (quality.type: sql) and JSON schema validation of files run the query or file as-is and are not filtered.

The API server's POST /test accepts the same filter and filters as query parameters.

A filtered run only makes a statement about the tested subset. So the applied filters are recorded in the test results: the Run carries a filters field (per schema), the console output prints a Row filter: line, and the recorded SQL of each check contains the WHERE clause.

Next steps​

  • Run the tests from Python instead of the CLI: Python Library.
  • Keep the tests running automatically: Scheduling.
  • Roll data contracts out across a team: Adopting Data Contracts.
  • Supported connections
  • How it works
    • Metadata checks
  • Dry Run
  • Configuring the connection
  • Options
  • Testing only a subset of rows
  • Next steps
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.