Skip to main content

Generate sensor queries from your BigQuery queries.

Project description

bqsensorgen

A sensor generator for your BigQuery queries.

sensor_generator(query str, desired_pattern str, timezone str)

Args
        
1. query_text (str): A .sql file;
                          
	Example: 'SELECT * FROM x.y.z'
            
2. desired_pattern (str): RegEx string containing the desired pattern to look for. Default is BigQuery Pattern.
        
	Example: ".*\..*\..*" (looks for 'project.dataset.table' pattern)
                                           
3. timezone (str): A timezone for the datetime column of the sensor query (Big Query default is UTC)
        
	Example: 'America/Sao_Paulo'

Returns:
	str : A text with the complete sensor query.
	list: A list with all the sources (project.dataset.table) found.


--------------------------------------------------------------------	

Example: sensor_generator(query_text="SELECT * FROM x.y.z", desired_pattern=".*\..*\..*", timezone="America/Sao_Paulo")

How does it work?

You give it a text with your BigQuery query, and it'll spit out a BigQuery sensor query that hopefully can be checked as true or false.

It automatically detects 'source' tables from your query and builds a sensor based on the last updated metadata from that table (BigQuery gives out metadata base on the dataset the table is from, hence the usage of this simple library). It is easily editable as well, so you can quickly change what you want from its returned text.

Examples

from bqsensorgen.sensorgen import sensor_generator

query = """
	SELECT * 
	FROM my_project.my_dataset.my_table T1
	INNER JOIN my_project.my_dataset.my_other_table T2
	ON T1.A = T2.B
"""

sensor_query, sources = sensor_generator(query)

print(sensor_query)
print(sources)

Why BigQuery?

Because BigQuery uses the following pattern for its tables: <project>.<dataset>.<table> and you can only see a table's metadata through that table's dataset's metadata.

If you somehow want a different pattern, you can pass a RegEx expression through the arguments.

Who should use it?

Composer/Airflow users will find it most useful, specially when using sensor Operators.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bqsensorgen-0.0.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

bqsensorgen-0.0.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file bqsensorgen-0.0.1.tar.gz.

File metadata

  • Download URL: bqsensorgen-0.0.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for bqsensorgen-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0d21aac76280f199e84a361a0508ef9a067972a2cc7d600feffec6b6aa9440ae
MD5 0a40952415948048f2c79d05a48ab815
BLAKE2b-256 8b4bae48d8c22b667be4a676a3941a995c7a2a2251c69dcb2d439c2c3895791e

See more details on using hashes here.

File details

Details for the file bqsensorgen-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: bqsensorgen-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for bqsensorgen-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 be3488da40d66660e09ed275b199e1ab738ba44a7ad86da1009afbdbfbeba9a3
MD5 35b57b1a3b87ee5f25071713342a9a08
BLAKE2b-256 929285b7ed213828044bf9a4ef04490a9e4d5a8be3a3c8b0c4c6af7c90f966b3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page