Git Product home page Git Product logo

Comments (3)

koshy1123 avatar koshy1123 commented on May 23, 2024

My bad - the actual error I get is a sqlalchemy.exc.DatabaseError and I can except that and my script runs fine, however in my run, I still continue to see this

Failed to execute query.
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/pyathena/common.py", line 165, in _execute
    **request)
  File "/usr/local/lib/python3.6/site-packages/pyathena/util.py", line 44, in retry_api_call
    return retry(func, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/tenacity/__init__.py", line 330, in call
    start_time=start_time)
  File "/usr/local/lib/python3.6/site-packages/tenacity/__init__.py", line 279, in iter
    return fut.result()
  File "/usr/local/lib/python3.6/concurrent/futures/_base.py", line 425, in result
    return self.__get_result()
  File "/usr/local/lib/python3.6/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.6/site-packages/tenacity/__init__.py", line 333, in call
    result = fn(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/botocore/client.py", line 314, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/lib/python3.6/site-packages/botocore/client.py", line 612, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.InvalidRequestException: An error occurred (InvalidRequestException) when calling the StartQueryExecution operation: Your query has exceeded the maximum query length of 262144 bytes. Please reduce the length of your query and try again.  If you continue to see this issue after reducing your query length,  contact customer support for further assistance.

from pyathena.

laughingman7743 avatar laughingman7743 commented on May 23, 2024

All exceptions raised in this library are wrapped in the exception class described in error.py.
https://github.com/laughingman7743/PyAthena/blob/master/pyathena/error.py
https://www.python.org/dev/peps/pep-0249/#exceptions

If you want to handle InvalidRequestException, it is a good idea to do the following.

from pyathena import connect, DatabaseError

cursor = connect(s3_staging_dir='s3://YOUR_BUCKET/path/to/',
                 region_name='us-west-2').cursor()
try:
    cursor.execute("SELECT * FROM one_row orderby hoge")
except DatabaseError as e:
    print(type(e))  # pyathena.error.DatabaseError
    print(type(e.__cause__))  # botocore.errorfactory.InvalidRequestException
    # https://github.com/boto/botocore/pull/1113
    if isinstance(e.__cause__,
                  cursor._connection.exceptions.InvalidRequestException):
        print('catch InvalidRequestException')

from pyathena.

koshy1123 avatar koshy1123 commented on May 23, 2024

Gotcha - I ended up implementing a version of this^, thanks! Only concerned that I was using a private variable _connection in my script, otherwise works!

Closing this issue.

from pyathena.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.