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

Feature/trino provider timezone #35963

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions airflow/providers/trino/hooks/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def get_conn(self) -> Connection:
verify=_boolify(extra.get("verify", True)),
session_properties=extra.get("session_properties") or None,
client_tags=extra.get("client_tags") or None,
timezone=extra.get("timezone") or None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: May I know if we need the or None here? I thought if "timezone" is not presented, it will return None by default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that we have that in other parameters as well.
@romsharon98 can you check it and if needed handle it in a followup PR?

)

return trino_conn
Expand Down
1 change: 1 addition & 0 deletions docs/apache-airflow-providers-trino/connections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ Extra (optional, connection parameters)
* ``kerberos__service_name``, ``kerberos__config``, ``kerberos__mutual_authentication``, ``kerberos__force_preemptive``, ``kerberos__hostname_override``, ``kerberos__sanitize_mutual_error_response``, ``kerberos__principal``,``kerberos__delegate``, ``kerberos__ca_bundle`` - These parameters can be set when enabling ``kerberos`` authentication.
* ``session_properties`` - JSON dictionary which allows to set session_properties. Example: ``{'session_properties':{'scale_writers':true,'task_writer_count:1'}}``
* ``client_tags`` - List of comma separated tags. Example ``{'client_tags':['sales','cluster1']}```
* ``timezone`` - The time zone for the session can be explicitly set using the IANA time zone name. Example: ``{'timezone':'Asia/Jerusalem'}``.

Note: If ``jwt__file`` and ``jwt__token`` are both given, ``jwt__file`` will take precedent.
17 changes: 16 additions & 1 deletion tests/providers/trino/hooks/test_trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ def test_get_conn_verify(self, mock_connect, mock_get_connection, current_verify
TrinoHook().get_conn()
self.assert_connection_called_with(mock_connect, verify=expected_verify)

@patch(HOOK_GET_CONNECTION)
@patch(TRINO_DBAPI_CONNECT)
def test_get_conn_timezone(self, mock_connect, mock_get_connection):
extras = {"timezone": "Asia/Jerusalem"}
self.set_get_connection_return_value(mock_get_connection, extra=json.dumps(extras))
TrinoHook().get_conn()
self.assert_connection_called_with(mock_connect, timezone="Asia/Jerusalem")

@staticmethod
def set_get_connection_return_value(mock_get_connection, extra=None, password=None):
mocked_connection = Connection(
Expand All @@ -248,7 +256,13 @@ def set_get_connection_return_value(mock_get_connection, extra=None, password=No

@staticmethod
def assert_connection_called_with(
mock_connect, http_headers=mock.ANY, auth=None, verify=True, session_properties=None, client_tags=None
mock_connect,
http_headers=mock.ANY,
auth=None,
verify=True,
session_properties=None,
client_tags=None,
timezone=None,
):
mock_connect.assert_called_once_with(
catalog="hive",
Expand All @@ -264,6 +278,7 @@ def assert_connection_called_with(
verify=verify,
session_properties=session_properties,
client_tags=client_tags,
timezone=timezone,
)


Expand Down