bqsensorgen


Namebqsensorgen JSON
Version 0.0.1 PyPI version JSON
download
home_page
SummaryGenerate sensor queries from your BigQuery queries.
upload_time2023-01-28 03:30:10
maintainer
docs_urlNone
author
requires_python>=3
licenseThe 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
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "bqsensorgen",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3",
    "maintainer_email": "",
    "keywords": "sensor,sql,query,bigquery,bq",
    "author": "",
    "author_email": "I\u00fary Pinto <iurysp@hotmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/8b/4b/ae48d8c22b667be4a676a3941a995c7a2a2251c69dcb2d439c2c3895791e/bqsensorgen-0.0.1.tar.gz",
    "platform": null,
    "description": "# bqsensorgen\r\nA sensor generator for your BigQuery queries.\r\n\r\n\r\n```\r\nsensor_generator(query str, desired_pattern str, timezone str)\r\n\r\nArgs\r\n        \r\n1. query_text (str): A .sql file;\r\n                          \r\n\tExample: 'SELECT * FROM x.y.z'\r\n            \r\n2. desired_pattern (str): RegEx string containing the desired pattern to look for. Default is BigQuery Pattern.\r\n        \r\n\tExample: \".*\\..*\\..*\" (looks for 'project.dataset.table' pattern)\r\n                                           \r\n3. timezone (str): A timezone for the datetime column of the sensor query (Big Query default is UTC)\r\n        \r\n\tExample: 'America/Sao_Paulo'\r\n\r\nReturns:\r\n\tstr : A text with the complete sensor query.\r\n\tlist: A list with all the sources (project.dataset.table) found.\r\n\r\n\r\n--------------------------------------------------------------------\t\r\n\r\nExample: sensor_generator(query_text=\"SELECT * FROM x.y.z\", desired_pattern=\".*\\..*\\..*\", timezone=\"America/Sao_Paulo\")\r\n```\r\n\r\n# How does it work?\r\n\r\nYou 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. \r\n\r\nIt automatically detects 'source' tables from your query and builds a sensor based on the last updated metadata from that table (BigQuery\r\ngives out metadata base on the dataset the table is from, hence the usage of this simple library). It is\r\neasily editable as well, so you can quickly change what you want from its returned text.\r\n\r\n\r\n\r\n# Examples\r\n\r\n```\r\nfrom bqsensorgen.sensorgen import sensor_generator\r\n\r\nquery = \"\"\"\r\n\tSELECT * \r\n\tFROM my_project.my_dataset.my_table T1\r\n\tINNER JOIN my_project.my_dataset.my_other_table T2\r\n\tON T1.A = T2.B\r\n\"\"\"\r\n\r\nsensor_query, sources = sensor_generator(query)\r\n\r\nprint(sensor_query)\r\nprint(sources)\r\n```\r\n\r\n\r\n# Why BigQuery?\r\n\r\nBecause BigQuery uses the following pattern for its tables: `<project>.<dataset>.<table>` \r\nand you can only see a table's metadata through that table's dataset's metadata.\r\n\r\nIf you somehow want a different pattern, you can pass a RegEx expression through the arguments.\r\n\r\n# Who should use it?\r\n\r\nComposer/Airflow users will find it most useful, specially when using sensor Operators.\r\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT) Copyright \u00a9 2023 I\u00fary Pinto  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \u201cSoftware\u201d), 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 \u201cAS IS\u201d, 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.",
    "summary": "Generate sensor queries from your BigQuery queries.",
    "version": "0.0.1",
    "split_keywords": [
        "sensor",
        "sql",
        "query",
        "bigquery",
        "bq"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "929285b7ed213828044bf9a4ef04490a9e4d5a8be3a3c8b0c4c6af7c90f966b3",
                "md5": "35b57b1a3b87ee5f25071713342a9a08",
                "sha256": "be3488da40d66660e09ed275b199e1ab738ba44a7ad86da1009afbdbfbeba9a3"
            },
            "downloads": -1,
            "filename": "bqsensorgen-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "35b57b1a3b87ee5f25071713342a9a08",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3",
            "size": 5707,
            "upload_time": "2023-01-28T03:30:09",
            "upload_time_iso_8601": "2023-01-28T03:30:09.242830Z",
            "url": "https://files.pythonhosted.org/packages/92/92/85b7ed213828044bf9a4ef04490a9e4d5a8be3a3c8b0c4c6af7c90f966b3/bqsensorgen-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8b4bae48d8c22b667be4a676a3941a995c7a2a2251c69dcb2d439c2c3895791e",
                "md5": "0a40952415948048f2c79d05a48ab815",
                "sha256": "0d21aac76280f199e84a361a0508ef9a067972a2cc7d600feffec6b6aa9440ae"
            },
            "downloads": -1,
            "filename": "bqsensorgen-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "0a40952415948048f2c79d05a48ab815",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3",
            "size": 4564,
            "upload_time": "2023-01-28T03:30:10",
            "upload_time_iso_8601": "2023-01-28T03:30:10.954873Z",
            "url": "https://files.pythonhosted.org/packages/8b/4b/ae48d8c22b667be4a676a3941a995c7a2a2251c69dcb2d439c2c3895791e/bqsensorgen-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-28 03:30:10",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "bqsensorgen"
}
        
Elapsed time: 0.03445s