pytd.query_engine.QueryEngine

class pytd.query_engine.QueryEngine(apikey, endpoint, database, header)[source]

An interface to Treasure Data query engine.

Parameters
apikeystring

Treasure Data API key.

endpointstring

Treasure Data API server.

databasestring

Name of connected database.

headerstring or boolean

Prepend comment strings, in the form “– comment”, as a header of queries.

__init__(self, apikey, endpoint, database, header)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(self, apikey, endpoint, database, …)

Initialize self.

close(self)

create_header(self[, extra_lines])

Build header comments.

cursor(self, \*\*kwargs)

execute(self, query, \*\*kwargs)

Execute a given SQL statement and return results.

Attributes

user_agent

User agent passed to a query engine connection.

__init__(self, apikey, endpoint, database, header)[source]

Initialize self. See help(type(self)) for accurate signature.

property user_agent

User agent passed to a query engine connection.

execute(self, query, **kwargs)[source]

Execute a given SQL statement and return results.

Parameters
querystring

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 the prestodb package.

  • db (str): use the database

  • result_url (str): result output URL

  • priority (int or str): priority
    • -2: “VERY LOW”

    • -1: “LOW”

    • 0: “NORMAL”

    • 1: “HIGH”

    • 2: “VERY HIGH”

  • retry_limit (int): max number of automatic retries

  • wait_interval (int): sleep interval until job finish

  • wait_callback (function): called every interval against job itself

Returns
dictkeys (‘data’, ‘columns’)
‘data’

List of rows. Every single row is represented as a list of column values.

‘columns’

List of column names.

create_header(self, extra_lines=[])[source]

Build header comments.

Parameters
extra_linesstring 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.

Returns
string
abstract cursor(self, **kwargs)[source]
abstract close(self)[source]