Validators

Validators are the corner stone of SQVID. They basically take a look at a specific column and check whether the values in it are “valid”. If they are not, the validation fails and the rows that do not pass the validation requirement are returned.

Available validators

sqvid.validators.accepted_values(table, column, args=None)

Check that a column contains only specified values.

Parameters

vals (list) – a list of values

Example

[[test_sqvid_db.suppliers.Country]]
validator = 'accepted_values'
args.vals  = [
  'USA',
  'UK',
  'Spain',
  'Japan',
  'Germany',
  'Australia',
  'Sweden',
  'Finland',
  'Italy',
  'Brazil',
  'Singapore',
  'Norway',
  'Canada',
  'France',
  'Denmark',
  'Netherlands'
]
sqvid.validators.custom_sql(table, column, args=None)

Execute a custom (optionally Jinja-formatted) SQL query and fail if non-zero number of rows is returned.

Either query or query_file parameter needs to be provided. All the other arguments are passed as Jinja variables and can be used to build the query.

The table and column the validator is called on are automaticaly added to the list of Jinja variables.

Parameters
  • query (str) – query to be executed (optional).

  • query_file (str) – path to the file in which the query to be executed can be found (optional)

Example

[[test_sqvid_db.suppliers.SupplierID]]
validator = 'custom_sql'
args.query_file = './tests/queries/tables_equal_rows.sql'
args.other_table = 'suppliers_copy'
[[test_sqvid_db.suppliers.SupplierID]]
validator = 'custom_sql'
args.query= 'SELECT * FROM {{ table }} WHERE {{ column }} > 20'

# The config above would execute the query
#   SELECT * FROM suppliers WHERE SupplierID > 20
sqvid.validators.in_range(table, column, args=None)

Check whether values in a column fall within a specific range.

Parameters
  • min (int) – the minimum value of the range

  • max (int) – the maximum value of the range

Example

[[test_sqvid_db.suppliers.SupplierID]]
validator = 'in_range'
args = {min = 1, max = 256}
sqvid.validators.not_null(table, column, args=None)

Check that a column contains only non-NULL values.

Example

[[test_sqvid_db.suppliers.SupplierID]]
validator = 'not_null'
sqvid.validators.unique(table, column, args=None)

Check whether values in a column are unique.

Example

[[test_sqvid_db.suppliers.SupplierID]]
validator = 'unique'