Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in SQL query interface of RestApiClient #135

Open
hmlpinto opened this issue Nov 18, 2022 · 0 comments
Open

Bug in SQL query interface of RestApiClient #135

hmlpinto opened this issue Nov 18, 2022 · 0 comments

Comments

@hmlpinto
Copy link

When interacting with the sql method of the RestApiClient, the function leverages the method sql_post from QueriesAPI.

This latter method does not leverage the query argument passed by the function.

The method from QueriesAPI that leverages the query argument directly is the sql_get

At the moment, I'm forced to override the call from sql_post to sql_get in method sql of the RestApiClient
for the method to work.

def override_sql(self, dataset_key, query, desired_mimetype='application/json',
        **kwargs):
    """Executes SQL queries against a dataset via POST

    :param dataset_key: Dataset identifier, in the form of owner/id
    :type dataset_key: str
    :param query: SQL query
    :type query: str
    :param include_table_schema: Flags indicating to include table schema
        in the response
    :type include_table_schema: bool
    :returns: file object that can be used in file parsers and
        data handling modules.
    :rtype: file-like object
    :raises RestApiException: If a server error occurs

    Examples
    --------
    >>> import datadotworld as dw
    >>> api_client = dw.api_client()
    >>> api_client.sql('username/test-dataset', 'query') # doctest: +SKIP
    """
    api_client = self._build_api_client(
        default_mimetype_header_accept=desired_mimetype)
    queries_api = kwargs.get('queries_api_mock',
                                 _swagger.QueriesApi(api_client))
    owner_id, dataset_id = parse_dataset_key(dataset_key)
    try:
        response = queries_api.sql_get(
            owner_id, dataset_id, query, _preload_content=False, **kwargs)
        return six.BytesIO(response.data)
    except _swagger.rest.ApiException as e:
        raise RestApiError(cause=e)

RestApiClient.sql = override_sql

Should I use a different method to leverage the sql query functionality?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant