From eb72e00a3b5756050b2f58e6caa1cda7cb8806a8 Mon Sep 17 00:00:00 2001 From: Damian Owsianny Date: Fri, 23 Dec 2022 12:33:11 +0100 Subject: [PATCH] Change experimental_python_types to legacy_primitive_types. Invert logic behind interpreting this parameter. --- README.md | 27 ++--- tests/integration/test_dbapi_integration.py | 124 +++++++++++--------- tests/integration/test_types_integration.py | 4 +- tests/unit/sqlalchemy/test_dialect.py | 12 +- trino/client.py | 12 +- trino/dbapi.py | 24 ++-- trino/sqlalchemy/dialect.py | 4 +- trino/sqlalchemy/util.py | 6 +- 8 files changed, 109 insertions(+), 104 deletions(-) diff --git a/README.md b/README.md index 67dfec7f..c4fe751e 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,6 @@ engine = create_engine( connect_args={ "session_properties": {'query_max_run_time': '1d'}, "client_tags": ["tag1", "tag2"], - "experimental_python_types": True, "roles": {"catalog1": "role1"}, } ) @@ -126,7 +125,6 @@ engine = create_engine( 'trino://user@localhost:8080/system?' 'session_properties={"query_max_run_time": "1d"}' '&client_tags=["tag1", "tag2"]' - '&experimental_python_types=true' '&roles={"catalog1": "role1"}' ) @@ -134,8 +132,7 @@ engine = create_engine( engine = create_engine(URL( host="localhost", port=8080, - client_tags=["tag1", "tag2"], - experimental_python_types=True + client_tags=["tag1", "tag2"] )) ``` @@ -440,35 +437,33 @@ The transaction is created when the first SQL statement is executed. exits the *with* context and the queries succeed, otherwise `trino.dbapi.Connection.rollback()` will be called. -## Improved Python types +## Legacy Primitive types -If you enable the flag `experimental_python_types`, the client will convert the results of the query to the +By default, the client will convert the results of the query to the corresponding Python types. For example, if the query returns a `DECIMAL` column, the result will be a `Decimal` object. +If you want to disable this behaviour, set flag `legacy_primitive_types` to `True`. Limitations of the Python types are described in the [Python types documentation](https://docs.python.org/3/library/datatypes.html). These limitations will generate an -exception `trino.exceptions.DataError` if the query returns a value that cannot be converted to the corresponding Python +exception `trino.exceptions.TrinoDataError` if the query returns a value that cannot be converted to the corresponding Python type. ```python import trino -import pytz -from datetime import datetime conn = trino.dbapi.connect( - experimental_python_types=True, + legacy_primitive_types=True, ... ) cur = conn.cursor() - -params = datetime(2020, 1, 1, 16, 43, 22, 320000, tzinfo=pytz.timezone('America/Los_Angeles')) - -cur.execute("SELECT ?", params=(params,)) +# Negative DATE cannot be represented with Python types +# legacy_primitive_types needs to be enabled +cur.execute("SELECT DATE '-2001-08-22'") rows = cur.fetchall() -assert rows[0][0] == params -assert cur.description[0][1] == "timestamp with time zone" +assert rows[0][0] == "-2001-08-22" +assert cur.description[0][1] == "date" ``` # Need help? diff --git a/tests/integration/test_dbapi_integration.py b/tests/integration/test_dbapi_integration.py index 57c6c604..38e8637f 100644 --- a/tests/integration/test_dbapi_integration.py +++ b/tests/integration/test_dbapi_integration.py @@ -171,22 +171,23 @@ def test_execute_many_select(trino_connection): assert "Query must return update type" in str(e.value) -@pytest.mark.parametrize("connection_experimental_python_types,cursor_experimental_python_types,expected", - [ - (None, None, False), - (None, False, False), - (None, True, True), - (False, None, False), - (False, False, False), - (False, True, True), - (True, None, True), - (True, False, False), - (True, True, True), - ]) -def test_experimental_python_types_with_connection_and_cursor( - connection_experimental_python_types, - cursor_experimental_python_types, - expected, +@pytest.mark.parametrize( + "connection_legacy_primitive_types,cursor_legacy_primitive_types,expected_legacy_primitive_types", + [ + (None, None, False), + (None, False, False), + (None, True, True), + (False, None, False), + (False, False, False), + (False, True, True), + (True, None, True), + (True, False, False), + (True, True, True), + ]) +def test_legacy_primitive_types_with_connection_and_cursor( + connection_legacy_primitive_types, + cursor_legacy_primitive_types, + expected_legacy_primitive_types, run_trino ): _, host, port = run_trino @@ -195,12 +196,12 @@ def test_experimental_python_types_with_connection_and_cursor( host=host, port=port, user="test", - experimental_python_types=connection_experimental_python_types, + legacy_primitive_types=connection_legacy_primitive_types, ) - cur = connection.cursor(experimental_python_types=cursor_experimental_python_types) + cur = connection.cursor(legacy_primitive_types=cursor_legacy_primitive_types) - cur.execute(""" + test_query = """ SELECT DECIMAL '0.142857', DATE '2018-01-01', @@ -208,10 +209,17 @@ def test_experimental_python_types_with_connection_and_cursor( TIMESTAMP '2019-01-01 00:00:00.000 UTC', TIMESTAMP '2019-01-01 00:00:00.000', TIME '00:00:00.000' - """) + """ + # Check values which cannot be represented by Python types + if expected_legacy_primitive_types: + test_query += """ + ,DATE '-2001-08-22' + """ + cur.execute(test_query) rows = cur.fetchall() - if expected: + if not expected_legacy_primitive_types: + assert len(rows[0]) == 6 assert rows[0][0] == Decimal('0.142857') assert rows[0][1] == date(2018, 1, 1) assert rows[0][2] == datetime(2019, 1, 1, tzinfo=timezone(timedelta(hours=1))) @@ -222,16 +230,18 @@ def test_experimental_python_types_with_connection_and_cursor( for value in rows[0]: assert isinstance(value, str) + assert len(rows[0]) == 7 assert rows[0][0] == '0.142857' assert rows[0][1] == '2018-01-01' assert rows[0][2] == '2019-01-01 00:00:00.000 +01:00' assert rows[0][3] == '2019-01-01 00:00:00.000 UTC' assert rows[0][4] == '2019-01-01 00:00:00.000' assert rows[0][5] == '00:00:00.000' + assert rows[0][6] == '-2001-08-22' def test_decimal_query_param(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() cur.execute("SELECT ?", params=(Decimal('0.142857'),)) rows = cur.fetchall() @@ -240,7 +250,7 @@ def test_decimal_query_param(trino_connection): def test_null_decimal(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() cur.execute("SELECT CAST(NULL AS DECIMAL)") rows = cur.fetchall() @@ -249,7 +259,7 @@ def test_null_decimal(trino_connection): def test_biggest_decimal(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() params = Decimal('99999999999999999999999999999999999999') cur.execute("SELECT ?", params=(params,)) @@ -259,7 +269,7 @@ def test_biggest_decimal(trino_connection): def test_smallest_decimal(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() params = Decimal('-99999999999999999999999999999999999999') cur.execute("SELECT ?", params=(params,)) @@ -269,7 +279,7 @@ def test_smallest_decimal(trino_connection): def test_highest_precision_decimal(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() params = Decimal('0.99999999999999999999999999999999999999') cur.execute("SELECT ?", params=(params,)) @@ -279,7 +289,7 @@ def test_highest_precision_decimal(trino_connection): def test_datetime_query_param(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() params = datetime(2020, 1, 1, 16, 43, 22, 320000) @@ -291,7 +301,7 @@ def test_datetime_query_param(trino_connection): def test_datetime_with_utc_time_zone_query_param(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() params = datetime(2020, 1, 1, 16, 43, 22, 320000, tzinfo=pytz.timezone('UTC')) @@ -303,7 +313,7 @@ def test_datetime_with_utc_time_zone_query_param(trino_connection): def test_datetime_with_numeric_offset_time_zone_query_param(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() tz = timezone(-timedelta(hours=5, minutes=30)) @@ -317,7 +327,7 @@ def test_datetime_with_numeric_offset_time_zone_query_param(trino_connection): def test_datetime_with_named_time_zone_query_param(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() params = datetime(2020, 1, 1, 16, 43, 22, 320000, tzinfo=pytz.timezone('America/Los_Angeles')) @@ -329,7 +339,7 @@ def test_datetime_with_named_time_zone_query_param(trino_connection): def test_datetime_with_trailing_zeros(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() cur.execute("SELECT TIMESTAMP '2001-08-22 03:04:05.321000'") rows = cur.fetchall() @@ -338,7 +348,7 @@ def test_datetime_with_trailing_zeros(trino_connection): def test_null_datetime_with_time_zone(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() cur.execute("SELECT CAST(NULL AS TIMESTAMP WITH TIME ZONE)") rows = cur.fetchall() @@ -347,7 +357,7 @@ def test_null_datetime_with_time_zone(trino_connection): def test_datetime_with_time_zone_numeric_offset(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() cur.execute("SELECT TIMESTAMP '2001-08-22 03:04:05.321 -08:00'") rows = cur.fetchall() @@ -356,7 +366,7 @@ def test_datetime_with_time_zone_numeric_offset(trino_connection): def test_datetimes_with_time_zone_in_dst_gap_query_param(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() # This is a datetime that lies within a DST transition and not actually exists. params = datetime(2021, 3, 28, 2, 30, 0, tzinfo=pytz.timezone('Europe/Brussels')) @@ -368,7 +378,7 @@ def test_datetimes_with_time_zone_in_dst_gap_query_param(trino_connection): def test_doubled_datetimes(trino_connection): # Trino doesn't distinguish between doubled datetimes that lie within a DST transition. See also # See also https://github.com/trinodb/trino/issues/5781 - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() params = pytz.timezone('US/Eastern').localize(datetime(2002, 10, 27, 1, 30, 0), is_dst=True) @@ -377,7 +387,7 @@ def test_doubled_datetimes(trino_connection): assert rows[0][0] == datetime(2002, 10, 27, 1, 30, 0, tzinfo=pytz.timezone('US/Eastern')) - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() params = pytz.timezone('US/Eastern').localize(datetime(2002, 10, 27, 1, 30, 0), is_dst=False) @@ -388,7 +398,7 @@ def test_doubled_datetimes(trino_connection): def test_date_query_param(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() params = datetime(2020, 1, 1, 0, 0, 0).date() @@ -399,7 +409,7 @@ def test_date_query_param(trino_connection): def test_null_date(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() cur.execute("SELECT CAST(NULL AS DATE)") rows = cur.fetchall() @@ -408,7 +418,7 @@ def test_null_date(trino_connection): def test_unsupported_python_dates(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() # dates below python min (1-1-1) or above max date (9999-12-31) are not supported for unsupported_date in [ @@ -424,7 +434,7 @@ def test_unsupported_python_dates(trino_connection): def test_supported_special_dates_query_param(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() for params in ( # min python date @@ -455,7 +465,7 @@ def test_supported_special_dates_query_param(trino_connection): def test_time_query_param(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() params = time(12, 3, 44, 333000) @@ -486,7 +496,7 @@ def test_time_with_numeric_offset_time_zone_query_param(trino_connection): def test_time(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() cur.execute("SELECT TIME '01:02:03.456'") rows = cur.fetchall() @@ -495,7 +505,7 @@ def test_time(trino_connection): def test_null_time(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() cur.execute("SELECT CAST(NULL AS TIME)") rows = cur.fetchall() @@ -504,7 +514,7 @@ def test_null_time(trino_connection): def test_time_with_time_zone_negative_offset(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() cur.execute("SELECT TIME '01:02:03.456 -08:00'") rows = cur.fetchall() @@ -515,7 +525,7 @@ def test_time_with_time_zone_negative_offset(trino_connection): def test_time_with_time_zone_positive_offset(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() cur.execute("SELECT TIME '01:02:03.456 +08:00'") rows = cur.fetchall() @@ -526,7 +536,7 @@ def test_time_with_time_zone_positive_offset(trino_connection): def test_null_date_with_time_zone(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() cur.execute("SELECT CAST(NULL AS TIME WITH TIME ZONE)") rows = cur.fetchall() @@ -545,7 +555,7 @@ def test_null_date_with_time_zone(trino_connection): ], ) def test_binary_query_param(trino_connection, binary_input): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() cur.execute("SELECT ?", params=(binary_input,)) rows = cur.fetchall() @@ -573,7 +583,7 @@ def test_array_query_param(trino_connection): def test_array_none_query_param(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() params = [None, None] @@ -589,7 +599,7 @@ def test_array_none_query_param(trino_connection): def test_array_none_and_another_type_query_param(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() params = [None, 1] @@ -605,7 +615,7 @@ def test_array_none_and_another_type_query_param(trino_connection): def test_array_timestamp_query_param(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() params = [datetime(2020, 1, 1, 0, 0, 0), datetime(2020, 1, 2, 0, 0, 0)] @@ -621,7 +631,7 @@ def test_array_timestamp_query_param(trino_connection): def test_array_timestamp_with_timezone_query_param(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() params = [datetime(2020, 1, 1, 0, 0, 0, tzinfo=pytz.utc), datetime(2020, 1, 2, 0, 0, 0, tzinfo=pytz.utc)] @@ -651,7 +661,7 @@ def test_dict_query_param(trino_connection): def test_dict_timestamp_query_param_types(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() params = {"foo": datetime(2020, 1, 1, 16, 43, 22, 320000)} cur.execute("SELECT ?", params=(params,)) @@ -675,7 +685,7 @@ def test_boolean_query_param(trino_connection): def test_row(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() params = (1, Decimal("2.0"), datetime(2020, 1, 1, 0, 0, 0)) cur.execute("SELECT ?", (params,)) rows = cur.fetchall() @@ -684,7 +694,7 @@ def test_row(trino_connection): def test_nested_row(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() params = ((1, "test", Decimal("3.1")), Decimal("2.0"), datetime(2020, 1, 1, 0, 0, 0)) cur.execute("SELECT ?", (params,)) rows = cur.fetchall() @@ -693,7 +703,7 @@ def test_nested_row(trino_connection): def test_named_row(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() cur.execute("SELECT CAST(ROW(1, 2e0) AS ROW(x BIGINT, y DOUBLE))") rows = cur.fetchall() @@ -710,7 +720,7 @@ def test_float_query_param(trino_connection): def test_float_nan_query_param(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() cur.execute("SELECT ?", params=(float("nan"),)) rows = cur.fetchall() @@ -720,7 +730,7 @@ def test_float_nan_query_param(trino_connection): def test_float_inf_query_param(trino_connection): - cur = trino_connection.cursor(experimental_python_types=True) + cur = trino_connection.cursor() cur.execute("SELECT ?", params=(float("inf"),)) rows = cur.fetchall() diff --git a/tests/integration/test_types_integration.py b/tests/integration/test_types_integration.py index 37201a1d..cb9971ac 100644 --- a/tests/integration/test_types_integration.py +++ b/tests/integration/test_types_integration.py @@ -773,7 +773,7 @@ def test_digest(trino_connection): class SqlTest: def __init__(self, trino_connection): - self.cur = trino_connection.cursor(experimental_python_types=True) + self.cur = trino_connection.cursor(legacy_primitive_types=False) self.sql_args = [] self.expected_result = [] @@ -803,7 +803,7 @@ def _compare_results(self, actual, expected): class SqlExpectFailureTest: def __init__(self, trino_connection): - self.cur = trino_connection.cursor(experimental_python_types=True) + self.cur = trino_connection.cursor(legacy_primitive_types=False) def execute(self, field): sql = 'SELECT ' + field diff --git a/tests/unit/sqlalchemy/test_dialect.py b/tests/unit/sqlalchemy/test_dialect.py index 3316fa6c..ee2f7e79 100644 --- a/tests/unit/sqlalchemy/test_dialect.py +++ b/tests/unit/sqlalchemy/test_dialect.py @@ -110,13 +110,13 @@ def setup(self): http_headers={"trino": 1}, extra_credential=[("a", "b"), ("c", "d")], client_tags=["1", "sql"], - experimental_python_types=True, + legacy_primitive_types=False, )), 'trino://user@localhost:8080/' '?client_tags=%5B%221%22%2C+%22sql%22%5D' - '&experimental_python_types=true' '&extra_credential=%5B%5B%22a%22%2C+%22b%22%5D%2C+%5B%22c%22%2C+%22d%22%5D%5D' '&http_headers=%7B%22trino%22%3A+1%7D' + '&legacy_primitive_types=false' '&session_properties=%7B%22query_max_run_time%22%3A+%221d%22%7D' '&source=trino-sqlalchemy', list(), @@ -130,7 +130,7 @@ def setup(self): http_headers={"trino": 1}, extra_credential=[("a", "b"), ("c", "d")], client_tags=["1", "sql"], - experimental_python_types=True, + legacy_primitive_types=False, ), ), # url encoding @@ -144,18 +144,18 @@ def setup(self): extra_credential=[ ("user1@test.org/my_role", "user2@test.org/my_role"), ("user3@test.org/my_role", "user36@test.org/my_role")], - experimental_python_types=True, + legacy_primitive_types=False, client_tags=["1 @& /\"", "sql"], verify=False, )), 'trino://user%40test.org%2Fmy_role:***@localhost:8080/' '?client_tags=%5B%221+%40%26+%2F%5C%22%22%2C+%22sql%22%5D' - '&experimental_python_types=true' '&extra_credential=%5B%5B%22user1%40test.org%2Fmy_role%22%2C+' '%22user2%40test.org%2Fmy_role%22%5D%2C+' '%5B%22user3%40test.org%2Fmy_role%22%2C+' '%22user36%40test.org%2Fmy_role%22%5D%5D' '&http_headers=%7B%22trino%22%3A+1%7D' + '&legacy_primitive_types=false' '&session_properties=%7B%22query_max_run_time%22%3A+%221d%22%7D' '&source=trino-sqlalchemy' '&verify=false', @@ -173,7 +173,7 @@ def setup(self): extra_credential=[ ("user1@test.org/my_role", "user2@test.org/my_role"), ("user3@test.org/my_role", "user36@test.org/my_role")], - experimental_python_types=True, + legacy_primitive_types=False, client_tags=["1 @& /\"", "sql"], verify=False, ), diff --git a/trino/client.py b/trino/client.py index c945b11a..46aa1751 100644 --- a/trino/client.py +++ b/trino/client.py @@ -710,7 +710,7 @@ def __init__( self, request: TrinoRequest, sql: str, - experimental_python_types: bool = False, + legacy_primitive_types: bool = False, ) -> None: self.query_id: Optional[str] = None @@ -724,7 +724,7 @@ def __init__( self._update_type = None self._sql = sql self._result: Optional[TrinoResult] = None - self._experimental_python_types = experimental_python_types + self._legacy_primitive_types = legacy_primitive_types self._row_mapper: Optional[RowMapper] = None @property @@ -790,7 +790,7 @@ def _update_state(self, status): self._update_type = status.update_type if not self._row_mapper and status.columns: self._row_mapper = RowMapperFactory().create(columns=status.columns, - experimental_python_types=self._experimental_python_types) + legacy_primitive_types=self._legacy_primitive_types) if status.columns: self._columns = status.columns @@ -1116,7 +1116,7 @@ def map(self, values: Any) -> Optional[Dict[Any, Optional[Any]]]: class NoOpRowMapper: """ No-op RowMapper which does not perform any transformation - Used when experimental_python_types is False. + Used when legacy_primitive_types is False. """ def map(self, rows): @@ -1131,10 +1131,10 @@ class RowMapperFactory: """ NO_OP_ROW_MAPPER = NoOpRowMapper() - def create(self, columns, experimental_python_types): + def create(self, columns, legacy_primitive_types): assert columns is not None - if experimental_python_types: + if not legacy_primitive_types: return RowMapper([self._create_value_mapper(column['typeSignature']) for column in columns]) return RowMapperFactory.NO_OP_ROW_MAPPER diff --git a/trino/dbapi.py b/trino/dbapi.py index 21dbfc6e..ac8d2893 100644 --- a/trino/dbapi.py +++ b/trino/dbapi.py @@ -109,7 +109,7 @@ def __init__( verify=True, http_session=None, client_tags=None, - experimental_python_types=False, + legacy_primitive_types=False, roles=None, timezone=None, ): @@ -151,7 +151,7 @@ def __init__( self._isolation_level = isolation_level self._request = None self._transaction = None - self.experimental_python_types = experimental_python_types + self.legacy_primitive_types = legacy_primitive_types @property def isolation_level(self): @@ -206,7 +206,7 @@ def _create_request(self): self.request_timeout, ) - def cursor(self, experimental_python_types: bool = None): + def cursor(self, legacy_primitive_types: bool = None): """Return a new :py:class:`Cursor` object using the connection.""" if self.isolation_level != IsolationLevel.AUTOCOMMIT: if self.transaction is None: @@ -218,8 +218,8 @@ def cursor(self, experimental_python_types: bool = None): return Cursor( self, request, - # if experimental_python_types is not explicitly set in Cursor, take from Connection - experimental_python_types if experimental_python_types is not None else self.experimental_python_types + # if legacy_primitive_types is not explicitly set in Cursor, take from Connection + legacy_primitive_types if legacy_primitive_types is not None else self.legacy_primitive_types ) @@ -245,7 +245,7 @@ class Cursor(object): """ - def __init__(self, connection, request, experimental_python_types: bool = False): + def __init__(self, connection, request, legacy_primitive_types: bool = False): if not isinstance(connection, Connection): raise ValueError( "connection must be a Connection object: {}".format(type(connection)) @@ -256,7 +256,7 @@ def __init__(self, connection, request, experimental_python_types: bool = False) self.arraysize = 1 self._iterator = None self._query = None - self._experimental_pyton_types = experimental_python_types + self._legacy_primitive_types = legacy_primitive_types def __iter__(self): return self._iterator @@ -333,7 +333,7 @@ def _prepare_statement(self, statement: str, name: str) -> None: """ sql = f"PREPARE {name} FROM {statement}" query = trino.client.TrinoQuery(self.connection._create_request(), sql=sql, - experimental_python_types=self._experimental_pyton_types) + legacy_primitive_types=self._legacy_primitive_types) query.execute() def _execute_prepared_statement( @@ -342,7 +342,7 @@ def _execute_prepared_statement( params ): sql = 'EXECUTE ' + statement_name + ' USING ' + ','.join(map(self._format_prepared_param, params)) - return trino.client.TrinoQuery(self._request, sql=sql, experimental_python_types=self._experimental_pyton_types) + return trino.client.TrinoQuery(self._request, sql=sql, legacy_primitive_types=self._legacy_primitive_types) def _format_prepared_param(self, param): """ @@ -423,7 +423,7 @@ def _format_prepared_param(self, param): def _deallocate_prepared_statement(self, statement_name: str) -> None: sql = 'DEALLOCATE PREPARE ' + statement_name query = trino.client.TrinoQuery(self.connection._create_request(), sql=sql, - experimental_python_types=self._experimental_pyton_types) + legacy_primitive_types=self._legacy_primitive_types) query.execute() def _generate_unique_statement_name(self): @@ -455,7 +455,7 @@ def execute(self, operation, params=None): else: self._query = trino.client.TrinoQuery(self._request, sql=operation, - experimental_python_types=self._experimental_pyton_types) + legacy_primitive_types=self._legacy_primitive_types) result = self._query.execute() self._iterator = iter(result) return result @@ -551,7 +551,7 @@ def describe(self, sql: str) -> List[DescribeOutput]: self._query = trino.client.TrinoQuery( self._request, sql=sql, - experimental_python_types=self._experimental_pyton_types, + legacy_primitive_types=self._legacy_primitive_types, ) result = self._query.execute() finally: diff --git a/trino/sqlalchemy/dialect.py b/trino/sqlalchemy/dialect.py index 2aaac3de..76dc6881 100644 --- a/trino/sqlalchemy/dialect.py +++ b/trino/sqlalchemy/dialect.py @@ -125,8 +125,8 @@ def create_connect_args(self, url: URL) -> Tuple[Sequence[Any], Mapping[str, Any if "client_tags" in url.query: kwargs["client_tags"] = json.loads(unquote_plus(url.query["client_tags"])) - if "experimental_python_types" in url.query: - kwargs["experimental_python_types"] = json.loads(unquote_plus(url.query["experimental_python_types"])) + if "legacy_primitive_types" in url.query: + kwargs["legacy_primitive_types"] = json.loads(unquote_plus(url.query["legacy_primitive_types"])) if "verify" in url.query: kwargs["verify"] = json.loads(unquote_plus(url.query["verify"])) diff --git a/trino/sqlalchemy/util.py b/trino/sqlalchemy/util.py index 117830bb..cfa9c6b1 100644 --- a/trino/sqlalchemy/util.py +++ b/trino/sqlalchemy/util.py @@ -22,7 +22,7 @@ def _url( http_headers: Dict[str, Union[str, int]] = None, extra_credential: Optional[List[Tuple[str, str]]] = None, client_tags: Optional[List[str]] = None, - experimental_python_types: Optional[bool] = None, + legacy_primitive_types: Optional[bool] = None, access_token: Optional[str] = None, cert: Optional[str] = None, key: Optional[str] = None, @@ -82,8 +82,8 @@ def _url( if client_tags is not None: trino_url += f"&client_tags={quote_plus(json.dumps(client_tags))}" - if experimental_python_types is not None: - trino_url += f"&experimental_python_types={json.dumps(experimental_python_types)}" + if legacy_primitive_types is not None: + trino_url += f"&legacy_primitive_types={json.dumps(legacy_primitive_types)}" if access_token is not None: trino_url += f"&access_token={quote_plus(access_token)}"