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 pypi 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.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0690874fa5c2c3091dff7ebe5dead6c0ed06549900ef64091c279046203b406 |
|
MD5 | 4f53dfd4a2629b733cd3deb532ca7a16 |
|
BLAKE2b-256 | 4967d66727159435e090eda559f6f06654c5976ddeef632caa840ea3e2649b9e |
Close
Hashes for python_bigquery_validator-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09330c59d85e006ab2edfe36d91395cdb103dcf7f2c70343ce2fb0478ebd2848 |
|
MD5 | 2f7f304a1b925e29ddc720989e22c6eb |
|
BLAKE2b-256 | 4cf15e0eedcae5aa4d582b671536087b3854a5e2f0263dbfbb8448f404e12c9a |