PyHive icon indicating copy to clipboard operation
PyHive copied to clipboard

Configure timezone of Presto client in SQLAlchemy

Open xiaoxi-s opened this issue 5 months ago • 0 comments

Configuring the presto's timezone in SQLAlchemy's create_engine function failed.

Details

Code:

# Option 1 - with http header
connect_args["protocol"] = "https"
connect_args["http_headers"] = {"X-Presto-Time-Zone": "America/New_York"}

# Option 2 - with session properties
connect_args["session_props"] = {"timezone": "America/Los_Angeles"}
# Or
# connect_args["session_properties"] = {"timezone": "America/Los_Angeles"}

Error:

E           sqlalchemy.exc.DatabaseError: (pyhive.exc.DatabaseError) {'message': 'Unknown session property timezone', 'errorCode': 14, 'errorName': 'INVALID_SESSION_PROPERTY', 'errorType': 'USER_ERROR', 'retriable': False, 'failureInfo': {'type': 'com.facebook.presto.spi.PrestoException', 'message': 'Unknown session property timezone', 'suppressed': [], 'stack': ['com.facebook.presto.metadata.SessionPropertyManager.lambda$validateSystemSessionProperty$2(SessionPropertyManager.java:191)', 'java.base/java.util.Optional.orElseThrow(Optional.java:408)', 'com.facebook.presto.metadata.SessionPropertyManager.validateSystemSessionProperty(SessionPropertyManager.java:191)', 'com.facebook.presto.Session.beginTransactionId(Session.java:349)', 'com.facebook.presto.execution.QueryStateMachine.beginWithTicker(QueryStateMachine.java:254)', 'com.facebook.presto.execution.QueryStateMachine.begin(QueryStateMachine.java:219)', 'com.facebook.presto.dispatcher.LocalDispatchQueryFactory.createDispatchQuery(LocalDispatchQueryFactory.java:144)', 'com.facebook.presto.dispatcher.DispatchManager.createQueryInternal(DispatchManager.java:312)', 'com.facebook.presto.dispatcher.DispatchManager.lambda$createQuery$0(DispatchManager.java:254)', 'com.facebook.airlift.concurrent.BoundedExecutor.drainQueue(BoundedExecutor.java:78)', 'java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)', 'java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)', 'java.base/java.lang.Thread.run(Thread.java:829)']}}

The raw presto.connect(...) also failed with session_properties

Details

Code: ``` conn = presto.connect( host="localhost", port=8080, username="user", catalog="memory", schema="default", session_properties={ "timezone": "UTC", # or "session.time_zone": "America/New_York", }, ) ```

Error:

    def cursor(self):
        """Return a new :py:class:`Cursor` object using the connection."""
>       return Cursor(*self._args, **self._kwargs)
E       TypeError: Cursor.__init__() got an unexpected keyword argument 'session_properties'

Is there a documentation about how to set timezone for presto connections (SQLAlchemy)? Or it is about SQLAlchemy or PyHive version? For the above experiment, the version SQLAlchemy is 1.4.46 and the version of PyHive is 0.7.0. The presto local instance has image tag 0.286.

Executing SET SESSION timezone = 'UTC'; in the presto instance also errored out:

presto> set SESSION timezone = 'UTC';
Query 20250519_083400_00062_kkxba failed: line 1:1: Session property timezone does not exist
set SESSION timezone = 'UTC'

xiaoxi-s avatar May 22 '25 19:05 xiaoxi-s