Query¶
-
class
Query(query, parameters=None, project=None)[source]¶ this class control the query, validate, read sql files and return the price.
- query : str
- the query
- client : Client
- the client object for bigquery
- price()
- return the query price
- validate()
- validate that the query can run without errors
- read_file(query_file, parameters=None)
- parse query from file, the query can be with parameters inside the file
generate Query object with simple query
>>> from pbq import Query >>> query = Query("select * from table")
get query price
>>> from pbq import Query >>> query = Query("select * from table") >>> print("the query price:", query.price) # the query price: 0.312
validate query
>>> from pbq import Query >>> query = Query("select * from table") >>> if not query.validate(): >>> raise RuntimeError("table not valid")
query with parameters
>>> from pbq import Query >>> query = Query("select * from table where user_id={user_id}", parameters={'user_id': 123}) >>> print(query.query) # select * from table where user_id=123
read query from file with parameters
>>> from pbq import Query >>> query = Query.read_file('file_path.sql', parameters={'user_id':123}) >>> print(query.query) # select * from table where user_id=123
-
price¶ check the cost of the query
Returns: float the price of the query