pytd.query_engine.HiveQueryEngine

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

An interface to Treasure Data Hive 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.

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

Methods

__init__(apikey, endpoint, database, header)

close()

Close a connection to Hive.

create_header([extra_lines])

Build header comments.

cursor([force_tdclient])

Get cursor defined by DB-API.

execute(query, **kwargs)

Execute a given SQL statement and return results.

Attributes

user_agent

User agent passed to a Hive connection.

__init__(apikey, endpoint, database, header)[source]
property user_agent

User agent passed to a Hive connection.

cursor(force_tdclient=True, **kwargs)[source]

Get cursor defined by DB-API.

Parameters
  • force_tdclient (bool) – Specify whether the method always returns tdclient.cursor.Cursor. Currently, the parameter changes nothing in HiveQueryEngine since tdclient.cursor.Curosr is the only option as a type of returned value.

  • **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.

    • 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

    • engine_version (str): run query with Hive 2 if this parameter is set to "stable". https://docs.treasuredata.com/display/public/PD/Writing+Hive+Queries

Return type

tdclient.cursor.Cursor

close()[source]

Close a connection to Hive.