Python module for validating BigQuery sql queries with support for Jinja templated variables
Project description
Python BigQuery Validator
Python module for validating BigQuery sql queries with support for Jinja templated variables
This package was built with the goal of automating testing of sql for Apache Airflow dags.
Installation Instructions
pip install python-bigquery-validator
Validate sql using unit tests
class BigqueryValidatorTest(unittest.TestCase):
bigquery_validator = BigQueryValidator()
def test_valid_query_returns_true(self):
query = "SELECT count(*) FROM `bigquery-public-data.samples.github_timeline`"
valid_sql = self.bigquery_validator.validate_query(query)
self.assertTrue(valid_sql)
def test_bad_query_returns_false(self):
query = "SELECT count(*) ROM `bigquery-public-data.samples.github_timeline`"
bad_sql = self.bigquery_validator.validate_query(query)
self.assertFalse(bad_sql)
def test_valid_query_from_file_returns_true(self):
valid_sql = self.bigquery_validator.validate_query_from_file("./valid_query.sql")
self.assertTrue(valid_sql)
def test_bad_query_from_file_returns_false(self):
bad_sql = self.bigquery_validator.validate_query_from_file("./bad_query.sql")
self.assertFalse(bad_sql, 'assert_bad_sql_from_file_fails_validation')
Run functions using the command line
python -m bigquery_validator dry_run_query 'select true'
python -m bigquery_validator render_templated_query 'select date("{{ params.date }}") as date'
python -m bigquery_validator validate_query 'select true'
python -m bigquery_validator validate_query_from_file './valid_query.sql'
Build Instructions
Build steps
python3 -m pip install --upgrade build
python3 -m build
Upload
python3 -m pip install --upgrade twine
python3 -m twine upload --repository testpypi dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for python-bigquery-validator-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 712e56aa961bfc2fd08e3bdf3d13ac80848fbdae4d017f9c3dbd4948b7e15e3f |
|
MD5 | 1dc912235fac0d48f05fddeb7d2f86c2 |
|
BLAKE2b-256 | 592f2eeba2a8db8c281e5b4a8c5852fe8df2145d6d631d313937436c01a114f9 |
Close
Hashes for python_bigquery_validator-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f24e1e3dd633fba9aadd79d6c2ad67fb8f34eef1b9d03a61bdf8a4139f6214e |
|
MD5 | 1794b8a38cd25a2b5dab822eef3b5551 |
|
BLAKE2b-256 | 52a64ff2e0dcdaeb181553b22cf357ba42f7d09e468cf423e420bb4847411c6c |