Skip to content

Commit

Permalink
Merge pull request #45 from treasure-data/query-type
Browse files Browse the repository at this point in the history
Disable query parameter `type`
  • Loading branch information
takuti committed Sep 6, 2019
2 parents e20bb32 + eda21b8 commit 26a061a
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 6 deletions.
19 changes: 19 additions & 0 deletions pytd/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,25 @@ def query(self, query, engine=None, **kwargs):
Query engine. If not given, default query engine created in the
constructor will be used.
**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``; that is, if ``engine`` is
Presto, you cannot enjoy efficient direct access to the query
engine provided by ``prestodb``.
- ``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
-------
dict : keys ('data', 'columns')
Expand Down
21 changes: 16 additions & 5 deletions pytd/pandas_td/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,23 @@ def read_td_query(
See https://prestodb.io/docs/current/release/release-0.77.html
params : dict, optional
Parameters to pass to execute method.
Parameters to pass to execute method. pytd does not support parameter
``type`` ('hive', 'presto'), and query type needs to be defined by
``engine``.
Available parameters:
- result_url (str): result output URL
- priority (int or str): priority (e.g. "NORMAL", "HIGH", etc.)
- retry_limit (int): retry limit
pytd: This argument will be ignored.
- ``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
-------
Expand Down
83 changes: 82 additions & 1 deletion pytd/query_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ def execute(self, query, **kwargs):
query : string
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
-------
dict : keys ('data', 'columns')
Expand Down Expand Up @@ -125,13 +143,30 @@ def _get_tdclient_cursor(self, con, **kwargs):
con : tdclient.connection.Connection
Handler created by ``tdclient#connect``.
**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
-------
tdclient.cursor.Cursor
"""
api_param_names = set(
[
"type",
"db",
"result_url",
"priority",
Expand All @@ -141,6 +176,13 @@ def _get_tdclient_cursor(self, con, **kwargs):
]
)

if "type" in kwargs:
raise RuntimeError(
"optional query parameter 'type' is unsupported. Issue query "
"from a proper QueryEngine instance: "
"{PrestoQueryEngine, HiveQueryEngine}."
)

# update a clone of the original params
cursor_kwargs = con._cursor_kwargs.copy()
for k, v in kwargs.items():
Expand Down Expand Up @@ -215,6 +257,26 @@ def presto_api_host(self):
def cursor(self, **kwargs):
"""Get cursor defined by DB-API.
Parameters
----------
**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
-------
prestodb.dbapi.Cursor, or tdclient.cursor.Cursor
Expand Down Expand Up @@ -282,6 +344,25 @@ def user_agent(self):
def cursor(self, **kwargs):
"""Get cursor defined by DB-API.
Parameters
----------
**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
Returns
-------
tdclient.cursor.Cursor
Expand Down

0 comments on commit 26a061a

Please sign in to comment.