Metadata-Version: 2.1
Name: bqsensorgen
Version: 0.0.1
Summary: Generate sensor queries from your BigQuery queries.
Author-email: Iúry Pinto <iurysp@hotmail.com>
License: The MIT License (MIT)
        Copyright © 2023 Iúry Pinto
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Keywords: sensor,sql,query,bigquery,bq
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Requires-Python: >=3
Description-Content-Type: text/markdown
License-File: LICENSE

# 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.
