pytd.query_engine.QueryEngine
- class pytd.query_engine.QueryEngine(apikey: str, endpoint: str, database: str, header: str | bool)[source]
An interface to Treasure Data query engine.
- Parameters:
apikey (str) – Treasure Data API key.
endpoint (str) – Treasure Data API server.
database (str) – Name of connected database.
header (str or bool) – Prepend comment strings, in the form “– comment”, as a header of queries.
Methods
__init__(apikey, endpoint, database, header)close()create_header([extra_lines])Build header comments.
cursor([force_tdclient])execute(query, **kwargs)Execute a given SQL statement and return results.
Attributes
User agent passed to a query engine connection.
- property user_agent: str
User agent passed to a query engine connection.
- execute(query: str, **kwargs: Any) QueryResult[source]
Execute a given SQL statement and return results.
Executed result returned by Cursor object is stored in
self.executed.- Parameters:
query (str) – Query.
**kwargs –
Treasure Data-specific optional query parameters. Giving these keyword arguments forces query engine to issue a query via Treasure Data REST API provided by
tdclient, rather than using a direct connection established by thetrinopackage.db(str): use the databaseresult_url(str): result output URLpriority(int or str): priority-2: “VERY LOW”
-1: “LOW”
0: “NORMAL”
1: “HIGH”
2: “VERY HIGH”
retry_limit(int): max number of automatic retrieswait_interval(int): sleep interval until job finishwait_callback(function): called every interval against job itselfengine_version(str): run query with Hive 2 if this parameter is set to"stable"inHiveQueryEngine. https://api-docs.treasuredata.com/en/tools/hive/writing_hive_queries
Meanwhile, when a following argument is set to
True, query is deterministically issued viatdclient.force_tdclient(bool): force Presto engines to issue a query viatdclientrather than its defaulttrinointerface.
- Returns:
dict –
- ‘data’
List of rows. Every single row is represented as a list of column values.
- ’columns’
List of column names.
- Return type:
keys (‘data’, ‘columns’)
- create_header(extra_lines: str | list[str] | tuple[str, ...] | None = None) str[source]
Build header comments.
- Parameters:
extra_lines (string or array-like, default: []) – Comments appended to the default one, which corresponds to a user agent string. If
self.header=None, empty string is returned regardless of this argument.- Return type:
str