From a810cd3c202007212ea2648cb3c9fdc8d42dc9a6 Mon Sep 17 00:00:00 2001 From: lpoulain Date: Mon, 18 Jul 2022 18:05:33 -0400 Subject: [PATCH 1/9] Support for time, datetime, json, real, double types as well as Infinity and NaN --- tests/unit/test_types.py | 1852 ++++++++++++++++++++++++++++++++++++++ trino/client.py | 63 +- 2 files changed, 1914 insertions(+), 1 deletion(-) create mode 100644 tests/unit/test_types.py diff --git a/tests/unit/test_types.py b/tests/unit/test_types.py new file mode 100644 index 00000000..c3d112d5 --- /dev/null +++ b/tests/unit/test_types.py @@ -0,0 +1,1852 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import datetime +import math + +from trino.client import TrinoStatus + +""" +SQL query which generates the expected rows and columns: + +SELECT false AS col_bool, + cast(null AS BOOLEAN) AS col_bool_null, + cast(127 AS TINYINT) AS col_tinyint, + cast(-128 AS TINYINT) AS col_tinyint_min, + cast(null AS TINYINT) AS col_tinyint_null, + cast(32767 AS SMALLINT) AS col_smallint, + cast(-32768 AS SMALLINT) AS col_smallint_min, + cast(null AS SMALLINT) AS col_smallint_null, + cast(2147483647 AS INTEGER) AS col_integer, + cast(-2147483648 AS INTEGER) AS col_integer_min, + cast(null AS INTEGER) AS col_integer_null, + cast(9223372036854775807 AS BIGINT) AS col_bigint, + cast(-9223372036854775808 AS BIGINT) AS col_bigint_min, + cast(null AS BIGINT) AS col_bigint_null, + cast(3.4028235E38 AS REAL) AS col_real, + cast(1.4E-45 AS REAL) as col_real_min, + cast('Infinity' AS REAL) AS col_real_inf, + cast('-Infinity' AS REAL) AS col_real_ninf, + cast('NaN' AS REAL) AS col_real_nan, + cast(null AS REAL) AS col_real_null, + cast(1.7976931348623157E308 AS DOUBLE) AS col_double, + cast(4.9E-324 AS DOUBLE) as col_double_min, + cast('Infinity' AS DOUBLE) AS col_double_inf, + cast('-Infinity' AS DOUBLE) AS col_double_ninf, + cast('NaN' AS DOUBLE) AS col_double_nan, + cast(null AS DOUBLE) AS col_double_null, + DECIMAL '10.3' AS col_decimal, + cast(null AS DECIMAL) AS col_decimal_null, + cast('0.123456789123456789' AS DECIMAL(18,18)) col_decimal18, + cast(null AS DECIMAL(18,18)) AS col_decimal18_null, + cast('10.3' AS DECIMAL(38,0)) col_decimal38, + cast(null AS DECIMAL(38,0)) AS col_decimal38_null, + 'aaa' AS col_varchar, + U&'Hello winter \2603 !' AS col_varchar_uni, + cast(null AS VARCHAR) AS col_varchar_null, + cast('bbb' AS VARCHAR(1)) AS col_varchar1, + cast(null AS VARCHAR(1)) AS col_varchar1_null, + cast('ccc' AS CHAR) AS col_char, + cast(null AS CHAR) AS col_char_null, + cast('ddd' AS CHAR(1)) AS col_char1, + cast(null AS CHAR(1)) AS col_char1_null, + X'65683F' AS col_varbinary, + cast(null AS VARBINARY) AS col_varbinary_null, + cast('{}' AS JSON) AS col_json, + cast('null' AS JSON) AS col_json_null2, + cast(null AS JSON) AS col_json_null, + DATE '2001-08-22' AS col_date, + cast(null AS DATE) AS col_date_null, + TIME '01:23:45.123' AS col_time, + cast(null AS TIME) AS col_time_null, + cast('01:23:45' AS TIME(0)) AS col_time0, + cast(null AS TIME(0)) AS col_time0_null, + cast('01:23:45.123' AS TIME(3)) AS col_time3, + cast(null AS TIME(3)) AS col_time3_null, + cast('01:23:45.123456' AS TIME(6)) AS col_time6, + cast(null AS TIME(6)) AS col_time6_null, + cast('01:23:45.123456789' AS TIME(9)) AS col_time9, + cast(null AS TIME(9)) AS col_time9_null, + cast('01:23:45.123456789123' AS TIME(12)) AS col_time12, + cast(null AS TIME(12)) AS col_time12_null, + TIME '01:23:45.123 -08:00' AS col_timetz, + cast(null AS TIME WITH TIME ZONE) AS col_timetz_null, + cast('01:23:45 -08:00' AS TIME(0) WITH TIME ZONE) AS col_timetz0, + cast(null AS TIME(0) WITH TIME ZONE) AS col_timetz0_null, + cast('01:23:45.123 -08:00' AS TIME(3) WITH TIME ZONE) AS col_timetz3, + cast(null AS TIME(3) WITH TIME ZONE) AS col_timetz3_null, + cast('01:23:45.123456 -08:00' AS TIME(6) WITH TIME ZONE) AS col_timetz6, + cast(null AS TIME(6) WITH TIME ZONE) AS col_timetz6_null, + cast('01:23:45.123456789 -08:00' AS TIME(9) WITH TIME ZONE) AS col_timetz9, + cast(null AS TIME(9) WITH TIME ZONE) AS col_timetz9_null, + cast('01:23:45.123456789123 -08:00' AS TIME(12) WITH TIME ZONE) AS col_timetz12, + cast(null AS TIME(12) WITH TIME ZONE) AS col_timetz12_null, + TIMESTAMP '2001-08-22 01:23:45.123' AS col_ts, + cast(null AS TIMESTAMP) AS col_ts_null, + cast('2001-08-22 01:23:45' AS TIMESTAMP(0)) AS col_ts0, + cast(null AS TIMESTAMP(0)) AS col_ts0_null, + cast('2001-08-22 01:23:45.123' AS TIMESTAMP(3)) AS col_ts3, + cast(null AS TIMESTAMP(3)) AS col_ts3_null, + cast('2001-08-22 01:23:45.123456' AS TIMESTAMP(6)) AS col_ts6, + cast(null AS TIMESTAMP(6)) AS col_ts6_null, + cast('2001-08-22 01:23:45.123456789' AS TIMESTAMP(9)) AS col_ts9, + cast(null AS TIMESTAMP(9)) AS col_ts9_null, + cast('2001-08-22 01:23:45.123456789123' AS TIMESTAMP(12)) AS col_ts12, + cast(null AS TIMESTAMP(12)) AS col_ts12_null, + TIMESTAMP '2001-08-22 01:23:45.123 -08:00' AS col_tstz, + cast(null AS TIMESTAMP WITH TIME ZONE) AS col_tstz_null, + cast('2001-08-22 01:23:45 -08:00' AS TIMESTAMP(0) WITH TIME ZONE) AS col_tstz0, + cast(null AS TIMESTAMP(0) WITH TIME ZONE) AS col_tstz0_null, + cast('2001-08-22 01:23:45.123 -08:00' AS TIMESTAMP(3) WITH TIME ZONE) AS col_tstz3, + cast(null AS TIMESTAMP(3) WITH TIME ZONE) AS col_tstz3_null, + cast('2001-08-22 01:23:45.123456 -08:00' AS TIMESTAMP(6) WITH TIME ZONE) AS col_tstz6, + cast(null AS TIMESTAMP(6) WITH TIME ZONE) AS col_tstz6_null, + cast('2001-08-22 01:23:45.123456789 -08:00' AS TIMESTAMP(9) WITH TIME ZONE) AS col_tstz9, + cast(null AS TIMESTAMP(9) WITH TIME ZONE) AS col_tstz9_null, + cast('2001-08-22 01:23:45.123456789123 -08:00' AS TIMESTAMP(12) WITH TIME ZONE) AS col_tstz12, + cast(null AS TIMESTAMP(12) WITH TIME ZONE) AS col_tstz12_null, + INTERVAL '3' MONTH AS col_int_year, + cast(null AS INTERVAL YEAR TO MONTH) AS col_int_year_null, + INTERVAL '2' DAY AS col_int_day, + cast(null AS INTERVAL DAY TO SECOND) AS col_int_day_null, + ARRAY['a', 'b', null] AS col_array, + cast(null AS ARRAY(VARCHAR)) AS col_array_null, + MAP(ARRAY['a', 'b'], ARRAY[1, null]) AS col_map, + cast(null AS MAP(VARCHAR, INTEGER)) AS col_map_null, + cast(ROW(1, 2e0) AS ROW(x BIGINT, y DOUBLE)) AS col_row, + cast(null AS ROW(x BIGINT, y DOUBLE)) AS col_row_null, + IPADDRESS '2001:db8::1' AS col_ipaddr, + cast(null AS IPADDRESS) AS col_ipaddr_null, + UUID '12151fd2-7586-11e9-8f9e-2a86e4085a59' AS col_uuid, + cast(null AS UUID) AS col_uuid_null, + approx_set(1) AS col_hll, + cast(null AS HyperLogLog) AS col_hll_null, + cast(approx_set(1) AS P4HyperLogLog) AS col_p4hll, + cast(null AS P4HyperLogLog) AS col_p4hll_null, + make_set_digest(1) AS col_setdigest, + cast(null AS SetDigest) AS col_setdigest_null, + qdigest_agg(1) AS col_qdigest, + cast(null AS QDigest(BIGINT)) AS col_qdigest_null, + tdigest_agg(1) AS col_tdigest, + cast(null AS TDigest) AS col_tdigest_null + """ + +columns = [ + { + "name": "col_bool", + "type": "boolean", + "typeSignature": { + "rawType": "boolean", + "arguments": [] + } + }, + { + "name": "col_bool_null", + "type": "boolean", + "typeSignature": { + "rawType": "boolean", + "arguments": [] + } + }, + { + "name": "col_tinyint", + "type": "tinyint", + "typeSignature": { + "rawType": "tinyint", + "arguments": [] + } + }, + { + "name": "col_tinyint_min", + "type": "tinyint", + "typeSignature": { + "rawType": "tinyint", + "arguments": [] + } + }, + { + "name": "col_tinyint_null", + "type": "tinyint", + "typeSignature": { + "rawType": "tinyint", + "arguments": [] + } + }, + { + "name": "col_smallint", + "type": "smallint", + "typeSignature": { + "rawType": "smallint", + "arguments": [] + } + }, + { + "name": "col_smallint_min", + "type": "smallint", + "typeSignature": { + "rawType": "smallint", + "arguments": [] + } + }, + { + "name": "col_smallint_null", + "type": "smallint", + "typeSignature": { + "rawType": "smallint", + "arguments": [] + } + }, + { + "name": "col_integer", + "type": "integer", + "typeSignature": { + "rawType": "integer", + "arguments": [] + } + }, + { + "name": "col_integer_min", + "type": "integer", + "typeSignature": { + "rawType": "integer", + "arguments": [] + } + }, + { + "name": "col_integer_null", + "type": "integer", + "typeSignature": { + "rawType": "integer", + "arguments": [] + } + }, + { + "name": "col_bigint", + "type": "bigint", + "typeSignature": { + "rawType": "bigint", + "arguments": [] + } + }, + { + "name": "col_bigint_min", + "type": "bigint", + "typeSignature": { + "rawType": "bigint", + "arguments": [] + } + }, + { + "name": "col_bigint_null", + "type": "bigint", + "typeSignature": { + "rawType": "bigint", + "arguments": [] + } + }, + { + "name": "col_real", + "type": "real", + "typeSignature": { + "rawType": "real", + "arguments": [] + } + }, + { + "name": "col_real_min", + "type": "real", + "typeSignature": { + "rawType": "real", + "arguments": [] + } + }, + { + "name": "col_real_inf", + "type": "real", + "typeSignature": { + "rawType": "real", + "arguments": [] + } + }, + { + "name": "col_real_ninf", + "type": "real", + "typeSignature": { + "rawType": "real", + "arguments": [] + } + }, + { + "name": "col_real_nan", + "type": "real", + "typeSignature": { + "rawType": "real", + "arguments": [] + } + }, + { + "name": "col_real_null", + "type": "real", + "typeSignature": { + "rawType": "real", + "arguments": [] + } + }, + { + "name": "col_double", + "type": "double", + "typeSignature": { + "rawType": "double", + "arguments": [] + } + }, + { + "name": "col_double_min", + "type": "double", + "typeSignature": { + "rawType": "double", + "arguments": [] + } + }, + { + "name": "col_double_inf", + "type": "double", + "typeSignature": { + "rawType": "double", + "arguments": [] + } + }, + { + "name": "col_double_ninf", + "type": "double", + "typeSignature": { + "rawType": "double", + "arguments": [] + } + }, + { + "name": "col_double_nan", + "type": "double", + "typeSignature": { + "rawType": "double", + "arguments": [] + } + }, + { + "name": "col_double_null", + "type": "double", + "typeSignature": { + "rawType": "double", + "arguments": [] + } + }, + { + "name": "col_decimal", + "type": "decimal(3, 1)", + "typeSignature": { + "rawType": "decimal", + "arguments": [ + { + "kind": "LONG", + "value": 3 + }, + { + "kind": "LONG", + "value": 1 + } + ] + } + }, + { + "name": "col_decimal_null", + "type": "decimal(38, 0)", + "typeSignature": { + "rawType": "decimal", + "arguments": [ + { + "kind": "LONG", + "value": 38 + }, + { + "kind": "LONG", + "value": 0 + } + ] + } + }, + { + "name": "col_decimal18", + "type": "decimal(18, 18)", + "typeSignature": { + "rawType": "decimal", + "arguments": [ + { + "kind": "LONG", + "value": 18 + }, + { + "kind": "LONG", + "value": 18 + } + ] + } + }, + { + "name": "col_decimal18_null", + "type": "decimal(18, 18)", + "typeSignature": { + "rawType": "decimal", + "arguments": [ + { + "kind": "LONG", + "value": 18 + }, + { + "kind": "LONG", + "value": 18 + } + ] + } + }, + { + "name": "col_decimal38", + "type": "decimal(38, 0)", + "typeSignature": { + "rawType": "decimal", + "arguments": [ + { + "kind": "LONG", + "value": 38 + }, + { + "kind": "LONG", + "value": 0 + } + ] + } + }, + { + "name": "col_decimal38_null", + "type": "decimal(38, 0)", + "typeSignature": { + "rawType": "decimal", + "arguments": [ + { + "kind": "LONG", + "value": 38 + }, + { + "kind": "LONG", + "value": 0 + } + ] + } + }, + { + "name": "col_varchar", + "type": "varchar(3)", + "typeSignature": { + "rawType": "varchar", + "arguments": [ + { + "kind": "LONG", + "value": 3 + } + ] + } + }, + { + "name": "col_varchar_uni", + "type": "varchar(16)", + "typeSignature": { + "rawType": "varchar", + "arguments": [ + { + "kind": "LONG", + "value": 16 + } + ] + } + }, + { + "name": "col_varchar_null", + "type": "varchar", + "typeSignature": { + "rawType": "varchar", + "arguments": [ + { + "kind": "LONG", + "value": 2147483647 + } + ] + } + }, + { + "name": "col_varchar1", + "type": "varchar(1)", + "typeSignature": { + "rawType": "varchar", + "arguments": [ + { + "kind": "LONG", + "value": 1 + } + ] + } + }, + { + "name": "col_varchar1_null", + "type": "varchar(1)", + "typeSignature": { + "rawType": "varchar", + "arguments": [ + { + "kind": "LONG", + "value": 1 + } + ] + } + }, + { + "name": "col_char", + "type": "char(1)", + "typeSignature": { + "rawType": "char", + "arguments": [ + { + "kind": "LONG", + "value": 1 + } + ] + } + }, + { + "name": "col_char_null", + "type": "char(1)", + "typeSignature": { + "rawType": "char", + "arguments": [ + { + "kind": "LONG", + "value": 1 + } + ] + } + }, + { + "name": "col_char1", + "type": "char(1)", + "typeSignature": { + "rawType": "char", + "arguments": [ + { + "kind": "LONG", + "value": 1 + } + ] + } + }, + { + "name": "col_char1_null", + "type": "char(1)", + "typeSignature": { + "rawType": "char", + "arguments": [ + { + "kind": "LONG", + "value": 1 + } + ] + } + }, + { + "name": "col_varbinary", + "type": "varbinary", + "typeSignature": { + "rawType": "varbinary", + "arguments": [] + } + }, + { + "name": "col_varbinary_null", + "type": "varbinary", + "typeSignature": { + "rawType": "varbinary", + "arguments": [] + } + }, + { + "name": "col_json", + "type": "json", + "typeSignature": { + "rawType": "json", + "arguments": [] + } + }, + { + "name": "col_json_null2", + "type": "json", + "typeSignature": { + "rawType": "json", + "arguments": [] + } + }, + { + "name": "col_json_null", + "type": "json", + "typeSignature": { + "rawType": "json", + "arguments": [] + } + }, + { + "name": "col_date", + "type": "date", + "typeSignature": { + "rawType": "date", + "arguments": [] + } + }, + { + "name": "col_date_null", + "type": "date", + "typeSignature": { + "rawType": "date", + "arguments": [] + } + }, + { + "name": "col_time", + "type": "time(3)", + "typeSignature": { + "rawType": "time", + "arguments": [ + { + "kind": "LONG", + "value": 3 + } + ] + } + }, + { + "name": "col_time_null", + "type": "time(3)", + "typeSignature": { + "rawType": "time", + "arguments": [ + { + "kind": "LONG", + "value": 3 + } + ] + } + }, + { + "name": "col_time0", + "type": "time(0)", + "typeSignature": { + "rawType": "time", + "arguments": [ + { + "kind": "LONG", + "value": 0 + } + ] + } + }, + { + "name": "col_time0_null", + "type": "time(0)", + "typeSignature": { + "rawType": "time", + "arguments": [ + { + "kind": "LONG", + "value": 0 + } + ] + } + }, + { + "name": "col_time3", + "type": "time(3)", + "typeSignature": { + "rawType": "time", + "arguments": [ + { + "kind": "LONG", + "value": 3 + } + ] + } + }, + { + "name": "col_time3_null", + "type": "time(3)", + "typeSignature": { + "rawType": "time", + "arguments": [ + { + "kind": "LONG", + "value": 3 + } + ] + } + }, + { + "name": "col_time6", + "type": "time(6)", + "typeSignature": { + "rawType": "time", + "arguments": [ + { + "kind": "LONG", + "value": 6 + } + ] + } + }, + { + "name": "col_time6_null", + "type": "time(6)", + "typeSignature": { + "rawType": "time", + "arguments": [ + { + "kind": "LONG", + "value": 6 + } + ] + } + }, + { + "name": "col_time9", + "type": "time(9)", + "typeSignature": { + "rawType": "time", + "arguments": [ + { + "kind": "LONG", + "value": 9 + } + ] + } + }, + { + "name": "col_time9_null", + "type": "time(9)", + "typeSignature": { + "rawType": "time", + "arguments": [ + { + "kind": "LONG", + "value": 9 + } + ] + } + }, + { + "name": "col_time12", + "type": "time(12)", + "typeSignature": { + "rawType": "time", + "arguments": [ + { + "kind": "LONG", + "value": 12 + } + ] + } + }, + { + "name": "col_time12_null", + "type": "time(12)", + "typeSignature": { + "rawType": "time", + "arguments": [ + { + "kind": "LONG", + "value": 12 + } + ] + } + }, + { + "name": "col_timetz", + "type": "time(3) with time zone", + "typeSignature": { + "rawType": "time with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 3 + } + ] + } + }, + { + "name": "col_timetz_null", + "type": "time(3) with time zone", + "typeSignature": { + "rawType": "time with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 3 + } + ] + } + }, + { + "name": "col_timetz0", + "type": "time(0) with time zone", + "typeSignature": { + "rawType": "time with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 0 + } + ] + } + }, + { + "name": "col_timetz0_null", + "type": "time(0) with time zone", + "typeSignature": { + "rawType": "time with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 0 + } + ] + } + }, + { + "name": "col_timetz3", + "type": "time(3) with time zone", + "typeSignature": { + "rawType": "time with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 3 + } + ] + } + }, + { + "name": "col_timetz3_null", + "type": "time(3) with time zone", + "typeSignature": { + "rawType": "time with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 3 + } + ] + } + }, + { + "name": "col_timetz6", + "type": "time(6) with time zone", + "typeSignature": { + "rawType": "time with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 6 + } + ] + } + }, + { + "name": "col_timetz6_null", + "type": "time(6) with time zone", + "typeSignature": { + "rawType": "time with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 6 + } + ] + } + }, + { + "name": "col_timetz9", + "type": "time(9) with time zone", + "typeSignature": { + "rawType": "time with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 9 + } + ] + } + }, + { + "name": "col_timetz9_null", + "type": "time(9) with time zone", + "typeSignature": { + "rawType": "time with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 9 + } + ] + } + }, + { + "name": "col_timetz12", + "type": "time(12) with time zone", + "typeSignature": { + "rawType": "time with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 12 + } + ] + } + }, + { + "name": "col_timetz12_null", + "type": "time(12) with time zone", + "typeSignature": { + "rawType": "time with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 12 + } + ] + } + }, + { + "name": "col_ts", + "type": "timestamp(3)", + "typeSignature": { + "rawType": "timestamp", + "arguments": [ + { + "kind": "LONG", + "value": 3 + } + ] + } + }, + { + "name": "col_ts_null", + "type": "timestamp(3)", + "typeSignature": { + "rawType": "timestamp", + "arguments": [ + { + "kind": "LONG", + "value": 3 + } + ] + } + }, + { + "name": "col_ts0", + "type": "timestamp(0)", + "typeSignature": { + "rawType": "timestamp", + "arguments": [ + { + "kind": "LONG", + "value": 0 + } + ] + } + }, + { + "name": "col_ts0_null", + "type": "timestamp(0)", + "typeSignature": { + "rawType": "timestamp", + "arguments": [ + { + "kind": "LONG", + "value": 0 + } + ] + } + }, + { + "name": "col_ts3", + "type": "timestamp(3)", + "typeSignature": { + "rawType": "timestamp", + "arguments": [ + { + "kind": "LONG", + "value": 3 + } + ] + } + }, + { + "name": "col_ts3_null", + "type": "timestamp(3)", + "typeSignature": { + "rawType": "timestamp", + "arguments": [ + { + "kind": "LONG", + "value": 3 + } + ] + } + }, + { + "name": "col_ts6", + "type": "timestamp(6)", + "typeSignature": { + "rawType": "timestamp", + "arguments": [ + { + "kind": "LONG", + "value": 6 + } + ] + } + }, + { + "name": "col_ts6_null", + "type": "timestamp(6)", + "typeSignature": { + "rawType": "timestamp", + "arguments": [ + { + "kind": "LONG", + "value": 6 + } + ] + } + }, + { + "name": "col_ts9", + "type": "timestamp(9)", + "typeSignature": { + "rawType": "timestamp", + "arguments": [ + { + "kind": "LONG", + "value": 9 + } + ] + } + }, + { + "name": "col_ts9_null", + "type": "timestamp(9)", + "typeSignature": { + "rawType": "timestamp", + "arguments": [ + { + "kind": "LONG", + "value": 9 + } + ] + } + }, + { + "name": "col_ts12", + "type": "timestamp(12)", + "typeSignature": { + "rawType": "timestamp", + "arguments": [ + { + "kind": "LONG", + "value": 12 + } + ] + } + }, + { + "name": "col_ts12_null", + "type": "timestamp(12)", + "typeSignature": { + "rawType": "timestamp", + "arguments": [ + { + "kind": "LONG", + "value": 12 + } + ] + } + }, + { + "name": "col_tstz", + "type": "timestamp(3) with time zone", + "typeSignature": { + "rawType": "timestamp with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 3 + } + ] + } + }, + { + "name": "col_tstz_null", + "type": "timestamp(3) with time zone", + "typeSignature": { + "rawType": "timestamp with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 3 + } + ] + } + }, + { + "name": "col_tstz0", + "type": "timestamp(0) with time zone", + "typeSignature": { + "rawType": "timestamp with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 0 + } + ] + } + }, + { + "name": "col_tstz0_null", + "type": "timestamp(0) with time zone", + "typeSignature": { + "rawType": "timestamp with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 0 + } + ] + } + }, + { + "name": "col_tstz3", + "type": "timestamp(3) with time zone", + "typeSignature": { + "rawType": "timestamp with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 3 + } + ] + } + }, + { + "name": "col_tstz3_null", + "type": "timestamp(3) with time zone", + "typeSignature": { + "rawType": "timestamp with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 3 + } + ] + } + }, + { + "name": "col_tstz6", + "type": "timestamp(6) with time zone", + "typeSignature": { + "rawType": "timestamp with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 6 + } + ] + } + }, + { + "name": "col_tstz6_null", + "type": "timestamp(6) with time zone", + "typeSignature": { + "rawType": "timestamp with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 6 + } + ] + } + }, + { + "name": "col_tstz9", + "type": "timestamp(9) with time zone", + "typeSignature": { + "rawType": "timestamp with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 9 + } + ] + } + }, + { + "name": "col_tstz9_null", + "type": "timestamp(9) with time zone", + "typeSignature": { + "rawType": "timestamp with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 9 + } + ] + } + }, + { + "name": "col_tstz12", + "type": "timestamp(12) with time zone", + "typeSignature": { + "rawType": "timestamp with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 12 + } + ] + } + }, + { + "name": "col_tstz12_null", + "type": "timestamp(12) with time zone", + "typeSignature": { + "rawType": "timestamp with time zone", + "arguments": [ + { + "kind": "LONG", + "value": 12 + } + ] + } + }, + { + "name": "col_int_year", + "type": "INTERVAL YEAR TO MONTH", + "typeSignature": { + "rawType": "interval year to month", + "arguments": [] + } + }, + { + "name": "col_int_year_null", + "type": "INTERVAL YEAR TO MONTH", + "typeSignature": { + "rawType": "interval year to month", + "arguments": [] + } + }, + { + "name": "col_int_day", + "type": "INTERVAL DAY TO SECOND", + "typeSignature": { + "rawType": "interval day to second", + "arguments": [] + } + }, + { + "name": "col_int_day_null", + "type": "INTERVAL DAY TO SECOND", + "typeSignature": { + "rawType": "interval day to second", + "arguments": [] + } + }, + { + "name": "col_array", + "type": "array(varchar(1))", + "typeSignature": { + "rawType": "array", + "arguments": [ + { + "kind": "TYPE", + "value": { + "rawType": "varchar", + "arguments": [ + { + "kind": "LONG", + "value": 1 + } + ] + } + } + ] + } + }, + { + "name": "col_array_null", + "type": "array(varchar)", + "typeSignature": { + "rawType": "array", + "arguments": [ + { + "kind": "TYPE", + "value": { + "rawType": "varchar", + "arguments": [ + { + "kind": "LONG", + "value": 2147483647 + } + ] + } + } + ] + } + }, + { + "name": "col_map", + "type": "map(varchar(1), integer)", + "typeSignature": { + "rawType": "map", + "arguments": [ + { + "kind": "TYPE", + "value": { + "rawType": "varchar", + "arguments": [ + { + "kind": "LONG", + "value": 1 + } + ] + } + }, + { + "kind": "TYPE", + "value": { + "rawType": "integer", + "arguments": [] + } + } + ] + } + }, + { + "name": "col_map_null", + "type": "map(varchar, integer)", + "typeSignature": { + "rawType": "map", + "arguments": [ + { + "kind": "TYPE", + "value": { + "rawType": "varchar", + "arguments": [ + { + "kind": "LONG", + "value": 2147483647 + } + ] + } + }, + { + "kind": "TYPE", + "value": { + "rawType": "integer", + "arguments": [] + } + } + ] + } + }, + { + "name": "col_row", + "type": "row(x bigint, y double)", + "typeSignature": { + "rawType": "row", + "arguments": [ + { + "kind": "NAMED_TYPE", + "value": { + "fieldName": { + "name": "x" + }, + "typeSignature": { + "rawType": "bigint", + "arguments": [] + } + } + }, + { + "kind": "NAMED_TYPE", + "value": { + "fieldName": { + "name": "y" + }, + "typeSignature": { + "rawType": "double", + "arguments": [] + } + } + } + ] + } + }, + { + "name": "col_row_null", + "type": "row(x bigint, y double)", + "typeSignature": { + "rawType": "row", + "arguments": [ + { + "kind": "NAMED_TYPE", + "value": { + "fieldName": { + "name": "x" + }, + "typeSignature": { + "rawType": "bigint", + "arguments": [] + } + } + }, + { + "kind": "NAMED_TYPE", + "value": { + "fieldName": { + "name": "y" + }, + "typeSignature": { + "rawType": "double", + "arguments": [] + } + } + } + ] + } + }, + { + "name": "col_ipaddr", + "type": "ipaddress", + "typeSignature": { + "rawType": "ipaddress", + "arguments": [] + } + }, + { + "name": "col_ipaddr_null", + "type": "ipaddress", + "typeSignature": { + "rawType": "ipaddress", + "arguments": [] + } + }, + { + "name": "col_uuid", + "type": "uuid", + "typeSignature": { + "rawType": "uuid", + "arguments": [] + } + }, + { + "name": "col_uuid_null", + "type": "uuid", + "typeSignature": { + "rawType": "uuid", + "arguments": [] + } + }, + { + "name": "col_hll", + "type": "HyperLogLog", + "typeSignature": { + "rawType": "HyperLogLog", + "arguments": [] + } + }, + { + "name": "col_hll_null", + "type": "HyperLogLog", + "typeSignature": { + "rawType": "HyperLogLog", + "arguments": [] + } + }, + { + "name": "col_p4hll", + "type": "P4HyperLogLog", + "typeSignature": { + "rawType": "P4HyperLogLog", + "arguments": [] + } + }, + { + "name": "col_p4hll_null", + "type": "P4HyperLogLog", + "typeSignature": { + "rawType": "P4HyperLogLog", + "arguments": [] + } + }, + { + "name": "col_setdigest", + "type": "SetDigest", + "typeSignature": { + "rawType": "SetDigest", + "arguments": [] + } + }, + { + "name": "col_setdigest_null", + "type": "SetDigest", + "typeSignature": { + "rawType": "SetDigest", + "arguments": [] + } + }, + { + "name": "col_qdigest", + "type": "qdigest(bigint)", + "typeSignature": { + "rawType": "qdigest", + "arguments": [ + { + "kind": "TYPE", + "value": { + "rawType": "bigint", + "arguments": [] + } + } + ] + } + }, + { + "name": "col_qdigest_null", + "type": "qdigest(bigint)", + "typeSignature": { + "rawType": "qdigest", + "arguments": [ + { + "kind": "TYPE", + "value": { + "rawType": "bigint", + "arguments": [] + } + } + ] + } + }, + { + "name": "col_tdigest", + "type": "tdigest", + "typeSignature": { + "rawType": "tdigest", + "arguments": [] + } + }, + { + "name": "col_tdigest_null", + "type": "tdigest", + "typeSignature": { + "rawType": "tdigest", + "arguments": [] + } + } + ] + +rows = [ + [ + False, + None, + 127, + -128, + None, + 32767, + -32768, + None, + 2147483647, + -2147483648, + None, + 9223372036854775807, + -9223372036854775808, + None, + 3.4028235E38, + 1.4E-45, + "Infinity", + "-Infinity", + "NaN", + None, + 1.7976931348623157E308, + 4.9E-324, + "Infinity", + "-Infinity", + "NaN", + None, + "10.3", + None, + "0.123456789123456789", + None, + "10", + None, + "aaa", + "Hello winter °3 !", + None, + "b", + None, + "c", + None, + "d", + None, + "ZWg/", + None, + "\"{}\"", + "\"null\"", + None, + "2001-08-22", + None, + "01:23:45.123", + None, + "01:23:45", + None, + "01:23:45.123", + None, + "01:23:45.123456", + None, + "01:23:45.123456789", + None, + "01:23:45.123456789123", + None, + "01:23:45.123-08:00", + None, + "01:23:45-08:00", + None, + "01:23:45.123-08:00", + None, + "01:23:45.123456-08:00", + None, + "01:23:45.123456789-08:00", + None, + "01:23:45.123456789123-08:00", + None, + "2001-08-22 01:23:45.123", + None, + "2001-08-22 01:23:45", + None, + "2001-08-22 01:23:45.123", + None, + "2001-08-22 01:23:45.123456", + None, + "2001-08-22 01:23:45.123456789", + None, + "2001-08-22 01:23:45.123456789123", + None, + "2001-08-22 01:23:45.123 -08:00", + None, + "2001-08-22 01:23:45 -08:00", + None, + "2001-08-22 01:23:45.123 -08:00", + None, + "2001-08-22 01:23:45.123456 -08:00", + None, + "2001-08-22 01:23:45.123456789 -08:00", + None, + "2001-08-22 01:23:45.123456789123 -08:00", + None, + "0-3", + None, + "2 00:00:00.000", + None, + [ + "a", + "b", + None + ], + None, + { + "a": 1, + "b": None + }, + None, + [ + 1, + 2.0 + ], + None, + "2001:db8::1", + None, + "12151fd2-7586-11e9-8f9e-2a86e4085a59", + None, + "AgwBAIADRAA=", + None, + "AwwAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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A=", + None, + "AAAAAAAAAPA/AAAAAAAA8D8AAAAAAABZQAAAAAAAAPA/AQAAAAAAAAAAAPA/AAAAAAAA8D8=", + None + ] + ] + + +EXPECTED_RESPONSE = [ + False, + None, + 127, + -128, + None, + 32767, + -32768, + None, + 2147483647, + -2147483648, + None, + 9223372036854775807, + -9223372036854775808, + None, + 3.4028235e+38, + 1.4e-45, + math.inf, + -math.inf, + math.nan, + None, + 1.7976931348623157e+308, + 5e-324, + math.inf, + -math.inf, + math.nan, + None, + 10.3, + None, + 0.12345678912345678, + None, + 10.0, + None, + 'aaa', + 'Hello winter \2603 !', + None, + 'b', + None, + 'c', + None, + 'd', + None, + 'ZWg/', + None, + {}, + None, + None, + datetime.date(2001, 8, 22), + None, + datetime.time(1, 23, 45, 123000), + None, + datetime.time(1, 23, 45), + None, + datetime.time(1, 23, 45, 123000), + None, + datetime.time(1, 23, 45, 123456), + None, + datetime.time(1, 23, 45, 123456), + None, + datetime.time(1, 23, 45, 123456), + None, + datetime.time(1, 23, 45, 123000), + None, + datetime.time(1, 23, 45), + None, + datetime.time(1, 23, 45, 123000), + None, + datetime.time(1, 23, 45, 123456), + None, + datetime.time(1, 23, 45, 123456), + None, + datetime.time(1, 23, 45, 123456), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 123000), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 123000), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 123456), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 189000), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 189123), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 123000, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 123000, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 123456, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 189000, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 189123, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + None, + '0-3', + None, + '2 00:00:00.000', + None, + ['a', 'b', None], + None, + {'a': 1, 'b': None}, + None, + [1, 2.0], + None, + '2001:db8::1', + None, + '12151fd2-7586-11e9-8f9e-2a86e4085a59', + None, + 'AgwBAIADRAA=', + None, + 'AwwAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==', + None, + 'AQgAAAACCwEAgANEAAAgAAABAAAASsQF+7cDRAABAA==', + None, + 'AHsUrkfheoQ/AAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAPA/AQAAAAAAAIA=', + None, + 'AAAAAAAAAPA/AAAAAAAA8D8AAAAAAABZQAAAAAAAAPA/AQAAAAAAAAAAAPA/AAAAAAAA8D8=', + None +] + +def test_types(): + t = TrinoStatus(id="id", stats={}, warnings=[], info_uri="", next_uri="", update_type="", rows=rows, columns=columns) + + assert len(t.rows) == 1 + result = t.rows[0] + + assert len(result) == len(EXPECTED_RESPONSE) + + for i in range(len(result)): + lval = result[i] + rval = EXPECTED_RESPONSE[i] + + if lval != rval: + if type(lval) == float and math.isnan(lval) and type(rval) == float and math.isnan(rval): + continue + + assert rval == lval diff --git a/trino/client.py b/trino/client.py index 3e198598..f56df4dd 100644 --- a/trino/client.py +++ b/trino/client.py @@ -37,6 +37,7 @@ import os import re import threading +import json import urllib.parse from datetime import datetime, timedelta, timezone from decimal import Decimal @@ -210,7 +211,7 @@ def __init__(self, id, stats, warnings, info_uri, next_uri, update_type, rows, c self.info_uri = info_uri self.next_uri = next_uri self.update_type = update_type - self.rows = rows + self.rows = self.__process_rows(rows, columns) self.columns = columns def __repr__(self): @@ -226,6 +227,66 @@ def __repr__(self): ) ) + def __process_rows(self, rows, columns): + if len(rows) == 0: + return [] + col_funcs = [self.__col_func(column) for column in columns] + + return [self.__process_row(row, col_funcs) for row in rows] + + def __process_row(self, row, col_funcs): + result = [] + for idx, val in enumerate(row): + if val is None: + result.append(None) + else: + result.append((col_funcs[idx])(val)) + return result + + def __col_func(self, column): + col_type = column['type'] + + if col_type.startswith('decimal') or col_type.startswith('double') or col_type.startswith('real'): + return lambda val : float('inf') if val == 'Infinity' else -float('inf') if val == '-Infinity' else float('nan') if val == 'NaN' else float(val) + elif col_type == 'timestamp' or col_type == 'timestamp(0)': + return lambda val : datetime.strptime(val, "%Y-%m-%d %H:%M:%S") + elif col_type.startswith('time'): + pattern = "%Y-%m-%d %H:%M:%S" if col_type.startswith('timestamp') else "%H:%M:%S" + ms_size, ms_to_trim = self.__get_number_of_digits(col_type) + if ms_size > 0: + pattern += ".%f" + + if col_type.startswith('timestamp'): + datetime_size = 21 + ms_size - ms_to_trim + if 'with time zone' in col_type: + pattern += ' %z' + + if ms_to_trim > 0: + return lambda val : datetime.strptime(val[:21] + val[datetime_size:], pattern) + else: + return lambda val : datetime.strptime(val, pattern) + + else: + time_size = 9 + ms_size - ms_to_trim + return lambda val : datetime.strptime(val[:time_size], pattern).time() + elif col_type == 'date': + return lambda val : datetime.strptime(val, '%Y-%m-%d').date() + elif col_type == 'json': + return lambda val : json.loads(json.loads(val)) + else: + return lambda val : val + + def __get_number_of_digits(self, col_type): + start_bracket_idx = col_type.find('(') + 1 + if start_bracket_idx == 0: + return -1, 0 + end_bracket_idx = col_type.find(')') + ms_size = int(col_type[start_bracket_idx:end_bracket_idx]) + if ms_size == 0: + return -1, 0 + ms_to_trim = ms_size - min(ms_size, 6) + return ms_size, ms_to_trim + class TrinoRequest(object): """ From 838cc2e28b303b7983152847f0cff5788fe744bd Mon Sep 17 00:00:00 2001 From: lpoulain Date: Tue, 19 Jul 2022 22:00:46 -0400 Subject: [PATCH 2/9] Fix failing integration tests --- tests/integration/test_types_integration.py | 309 ++++ tests/unit/test_types.py | 1852 ------------------- trino/client.py | 158 +- 3 files changed, 364 insertions(+), 1955 deletions(-) create mode 100644 tests/integration/test_types_integration.py delete mode 100644 tests/unit/test_types.py diff --git a/tests/integration/test_types_integration.py b/tests/integration/test_types_integration.py new file mode 100644 index 00000000..597ecfca --- /dev/null +++ b/tests/integration/test_types_integration.py @@ -0,0 +1,309 @@ +import math +import pytest +from decimal import Decimal +import datetime +from datetime import timezone, timedelta +import trino + +@pytest.fixture +def trino_connection(run_trino): + _, host, port = run_trino + + yield trino.dbapi.Connection( + host=host, port=port, user="test", source="test", max_attempts=1 + ) + +def test_int_types(trino_connection): + cur = trino_connection.cursor(experimental_python_types=True) + cur.execute(""" + SELECT false AS col_bool + , cast(null AS BOOLEAN) AS col_bool_null + , cast(127 AS TINYINT) AS col_tinyint + , cast(-128 AS TINYINT) AS col_tinyint_min + , cast(null AS TINYINT) AS col_tinyint_null + , cast(32767 AS SMALLINT) AS col_smallint + , cast(-32768 AS SMALLINT) AS col_smallint_min + , cast(null AS SMALLINT) AS col_smallint_null + , cast(2147483647 AS INTEGER) AS col_integer + , cast(-2147483648 AS INTEGER) AS col_integer_min + , cast(null AS INTEGER) AS col_integer_null + , cast(9223372036854775807 AS BIGINT) AS col_bigint + , cast(-9223372036854775808 AS BIGINT) AS col_bigint_min + , cast(null AS BIGINT) AS col_bigint_null + """) + result = cur.fetchall() + compare_results(result[0], [ + False, + None, + 127, + -128, + None, + 32767, + -32768, + None, + 2147483647, + -2147483648, + None, + 9223372036854775807, + -9223372036854775808, + None + ]) + +def test_float_types(trino_connection): + cur = trino_connection.cursor(experimental_python_types=True) + cur.execute(""" + SELECT cast(3.4028235E38 AS REAL) AS col_real + , cast(1.4E-45 AS REAL) as col_real_min + , cast('Infinity' AS REAL) AS col_real_inf + , cast('-Infinity' AS REAL) AS col_real_ninf + , cast('NaN' AS REAL) AS col_real_nan + , cast(null AS REAL) AS col_real_null + , cast(1.7976931348623157E308 AS DOUBLE) AS col_double + , cast(4.9E-324 AS DOUBLE) as col_double_min + , cast('Infinity' AS DOUBLE) AS col_double_inf + , cast('-Infinity' AS DOUBLE) AS col_double_ninf + , cast('NaN' AS DOUBLE) AS col_double_nan + , cast(null AS DOUBLE) AS col_double_null + , DECIMAL '10.3' AS col_decimal + , cast(null AS DECIMAL) AS col_decimal_null + , cast('0.123456789123456789' AS DECIMAL(18,18)) col_decimal18 + , cast(null AS DECIMAL(18,18)) AS col_decimal18_null + , cast('10.3' AS DECIMAL(38,0)) col_decimal38 + , cast(null AS DECIMAL(38,0)) AS col_decimal38_null + """) + + result = cur.fetchall() + compare_results(result[0], [ + 3.4028235e+38, + 1.4e-45, + math.inf, + -math.inf, + math.nan, + None, + 1.7976931348623157e+308, + 5e-324, + math.inf, + -math.inf, + math.nan, + None, + Decimal('10.3'), + None, + Decimal('0.123456789123456789'), + None, + 10.0, + None + ]) + +def test_string_types(trino_connection): + cur = trino_connection.cursor(experimental_python_types=True) + cur.execute(""" + SELECT 'aaa' AS col_varchar + , U&'Hello winter \2603 !' AS col_varchar_uni + , cast(null AS VARCHAR) AS col_varchar_null + , cast('bbb' AS VARCHAR(1)) AS col_varchar1 + , cast(null AS VARCHAR(1)) AS col_varchar1_null + , cast('ccc' AS CHAR) AS col_char + , cast(null AS CHAR) AS col_char_null + , cast('ddd' AS CHAR(1)) AS col_char1 + , cast(null AS CHAR(1)) AS col_char1_null + , X'65683F' AS col_varbinary + , cast(null AS VARBINARY) AS col_varbinary_null + , cast('{}' AS JSON) AS col_json + , cast('null' AS JSON) AS col_json_null2 + , cast(null AS JSON) AS col_json_null + """) + + result = cur.fetchall() + compare_results(result[0], [ + 'aaa', + 'Hello winter °3 !', + None, + 'b', + None, + 'c', + None, + 'd', + None, + 'ZWg/', + None, + {}, + None, + None + ]) + +def test_datetime_types(trino_connection): + cur = trino_connection.cursor(experimental_python_types=True) + cur.execute(""" + SELECT DATE '2001-08-22' AS col_date + , cast(null AS DATE) AS col_date_null + , TIME '01:23:45.123' AS col_time + , cast(null AS TIME) AS col_time_null + , cast('01:23:45' AS TIME(0)) AS col_time0 + , cast(null AS TIME(0)) AS col_time0_null + , cast('01:23:45.123' AS TIME(3)) AS col_time3 + , cast(null AS TIME(3)) AS col_time3_null + , cast('01:23:45.123456' AS TIME(6)) AS col_time6 + , cast(null AS TIME(6)) AS col_time6_null + , cast('01:23:45.123456789' AS TIME(9)) AS col_time9 + , cast(null AS TIME(9)) AS col_time9_null + , cast('01:23:45.123456789123' AS TIME(12)) AS col_time12 + , cast(null AS TIME(12)) AS col_time12_null + , TIME '01:23:45.123 -08:00' AS col_timetz + , cast(null AS TIME WITH TIME ZONE) AS col_timetz_null + , cast('01:23:45 -08:00' AS TIME(0) WITH TIME ZONE) AS col_timetz0 + , cast(null AS TIME(0) WITH TIME ZONE) AS col_timetz0_null + , cast('01:23:45.123 -08:00' AS TIME(3) WITH TIME ZONE) AS col_timetz3 + , cast(null AS TIME(3) WITH TIME ZONE) AS col_timetz3_null + , cast('01:23:45.123456 -08:00' AS TIME(6) WITH TIME ZONE) AS col_timetz6 + , cast(null AS TIME(6) WITH TIME ZONE) AS col_timetz6_null + , cast('01:23:45.123456789 -08:00' AS TIME(9) WITH TIME ZONE) AS col_timetz9 + , cast(null AS TIME(9) WITH TIME ZONE) AS col_timetz9_null + , cast('01:23:45.123456789123 -08:00' AS TIME(12) WITH TIME ZONE) AS col_timetz12 + , cast(null AS TIME(12) WITH TIME ZONE) AS col_timetz12_null + , TIMESTAMP '2001-08-22 01:23:45.123' AS col_ts + , cast(null AS TIMESTAMP) AS col_ts_null + , cast('2001-08-22 01:23:45' AS TIMESTAMP(0)) AS col_ts0 + , cast(null AS TIMESTAMP(0)) AS col_ts0_null + , cast('2001-08-22 01:23:45.123' AS TIMESTAMP(3)) AS col_ts3 + , cast(null AS TIMESTAMP(3)) AS col_ts3_null + , cast('2001-08-22 01:23:45.123456' AS TIMESTAMP(6)) AS col_ts6 + , cast(null AS TIMESTAMP(6)) AS col_ts6_null + , cast('2001-08-22 01:23:45.123456789' AS TIMESTAMP(9)) AS col_ts9 + , cast(null AS TIMESTAMP(9)) AS col_ts9_null + , cast('2001-08-22 01:23:45.123456789123' AS TIMESTAMP(12)) AS col_ts12 + , cast(null AS TIMESTAMP(12)) AS col_ts12_null + , TIMESTAMP '2001-08-22 01:23:45.123 -08:00' AS col_tstz + , cast(null AS TIMESTAMP WITH TIME ZONE) AS col_tstz_null + , cast('2001-08-22 01:23:45 -08:00' AS TIMESTAMP(0) WITH TIME ZONE) AS col_tstz0 + , cast(null AS TIMESTAMP(0) WITH TIME ZONE) AS col_tstz0_null + , cast('2001-08-22 01:23:45.123 -08:00' AS TIMESTAMP(3) WITH TIME ZONE) AS col_tstz3 + , cast(null AS TIMESTAMP(3) WITH TIME ZONE) AS col_tstz3_null + , cast('2001-08-22 01:23:45.123456 -08:00' AS TIMESTAMP(6) WITH TIME ZONE) AS col_tstz6 + , cast(null AS TIMESTAMP(6) WITH TIME ZONE) AS col_tstz6_null + , cast('2001-08-22 01:23:45.123456789 -08:00' AS TIMESTAMP(9) WITH TIME ZONE) AS col_tstz9 + , cast(null AS TIMESTAMP(9) WITH TIME ZONE) AS col_tstz9_null + , cast('2001-08-22 01:23:45.123456789123 -08:00' AS TIMESTAMP(12) WITH TIME ZONE) AS col_tstz12 + , cast(null AS TIMESTAMP(12) WITH TIME ZONE) AS col_tstz12_null + """) + + result = cur.fetchall() + compare_results(result[0], [ + datetime.date(2001, 8, 22), + None, + datetime.time(1, 23, 45, 123000), + None, + datetime.time(1, 23, 45), + None, + datetime.time(1, 23, 45, 123000), + None, + datetime.time(1, 23, 45, 123456), + None, + datetime.time(1, 23, 45, 123456), + None, + datetime.time(1, 23, 45, 123456), + None, + datetime.time(1, 23, 45, 123000).replace(tzinfo=timezone(-timedelta(hours=8))), + None, + datetime.time(1, 23, 45).replace(tzinfo=timezone(-timedelta(hours=8))), + None, + datetime.time(1, 23, 45, 123000).replace(tzinfo=timezone(-timedelta(hours=8))), + None, + datetime.time(1, 23, 45, 123456).replace(tzinfo=timezone(-timedelta(hours=8))), + None, + datetime.time(1, 23, 45, 123456).replace(tzinfo=timezone(-timedelta(hours=8))), + None, + datetime.time(1, 23, 45, 123456).replace(tzinfo=timezone(-timedelta(hours=8))), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 123000), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 123000), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 123456), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 189000), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 189123), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 123000, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 123000, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 123456, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 189000, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + None, + datetime.datetime(2001, 8, 22, 1, 23, 45, 189123, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + None + ]) + +def test_misc_types(trino_connection): + cur = trino_connection.cursor(experimental_python_types=True) + cur.execute(""" + SELECT INTERVAL '3' MONTH AS col_int_year + , cast(null AS INTERVAL YEAR TO MONTH) AS col_int_year_null + , INTERVAL '2' DAY AS col_int_day + , cast(null AS INTERVAL DAY TO SECOND) AS col_int_day_null + , ARRAY['a', 'b', null] AS col_array + , cast(null AS ARRAY(VARCHAR)) AS col_array_null + , MAP(ARRAY['a', 'b'], ARRAY[1, null]) AS col_map + , cast(null AS MAP(VARCHAR, INTEGER)) AS col_map_null + , cast(ROW(1, 2e0) AS ROW(x BIGINT, y DOUBLE)) AS col_row + , cast(null AS ROW(x BIGINT, y DOUBLE)) AS col_row_null + , IPADDRESS '2001:db8::1' AS col_ipaddr + , cast(null AS IPADDRESS) AS col_ipaddr_null + , UUID '12151fd2-7586-11e9-8f9e-2a86e4085a59' AS col_uuid + , cast(null AS UUID) AS col_uuid_null + , approx_set(1) AS col_hll + , cast(null AS HyperLogLog) AS col_hll_null + , cast(approx_set(1) AS P4HyperLogLog) AS col_p4hll + , cast(null AS P4HyperLogLog) AS col_p4hll_null + , make_set_digest(1) AS col_setdigest + , cast(null AS SetDigest) AS col_setdigest_null + , qdigest_agg(1) AS col_qdigest + , cast(null AS QDigest(BIGINT)) AS col_qdigest_null + , tdigest_agg(1) AS col_tdigest + , cast(null AS TDigest) AS col_tdigest_null + """) + + result = cur.fetchall() + compare_results(result[0], [ + '0-3', + None, + '2 00:00:00.000', + None, + ['a', 'b', None], + None, + {'a': 1, 'b': None}, + None, + (1, 2.0), + None, + '2001:db8::1', + None, + '12151fd2-7586-11e9-8f9e-2a86e4085a59', + None, + 'AgwBAIADRAA=', + None, + + 'AwwAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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wEAgANEAAAgAAABAAAASsQF+7cDRAABAA==', + None, + 'AHsUrkfheoQ/AAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAPA/AQAAAAAAAIA=', + None, + 'AAAAAAAAAPA/AAAAAAAA8D8AAAAAAABZQAAAAAAAAPA/AQAAAAAAAAAAAPA/AAAAAAAA8D8=', + None + ]) + +def compare_results(actual, expected): + assert len(actual) == len(expected) + + for idx, actual_val in enumerate(actual): + expected_val = expected[idx] + if type(actual_val) == float and math.isnan(actual_val) and type(expected_val) == float and math.isnan(expected_val): + continue + + assert actual_val == expected_val diff --git a/tests/unit/test_types.py b/tests/unit/test_types.py deleted file mode 100644 index c3d112d5..00000000 --- a/tests/unit/test_types.py +++ /dev/null @@ -1,1852 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import datetime -import math - -from trino.client import TrinoStatus - -""" -SQL query which generates the expected rows and columns: - -SELECT false AS col_bool, - cast(null AS BOOLEAN) AS col_bool_null, - cast(127 AS TINYINT) AS col_tinyint, - cast(-128 AS TINYINT) AS col_tinyint_min, - cast(null AS TINYINT) AS col_tinyint_null, - cast(32767 AS SMALLINT) AS col_smallint, - cast(-32768 AS SMALLINT) AS col_smallint_min, - cast(null AS SMALLINT) AS col_smallint_null, - cast(2147483647 AS INTEGER) AS col_integer, - cast(-2147483648 AS INTEGER) AS col_integer_min, - cast(null AS INTEGER) AS col_integer_null, - cast(9223372036854775807 AS BIGINT) AS col_bigint, - cast(-9223372036854775808 AS BIGINT) AS col_bigint_min, - cast(null AS BIGINT) AS col_bigint_null, - cast(3.4028235E38 AS REAL) AS col_real, - cast(1.4E-45 AS REAL) as col_real_min, - cast('Infinity' AS REAL) AS col_real_inf, - cast('-Infinity' AS REAL) AS col_real_ninf, - cast('NaN' AS REAL) AS col_real_nan, - cast(null AS REAL) AS col_real_null, - cast(1.7976931348623157E308 AS DOUBLE) AS col_double, - cast(4.9E-324 AS DOUBLE) as col_double_min, - cast('Infinity' AS DOUBLE) AS col_double_inf, - cast('-Infinity' AS DOUBLE) AS col_double_ninf, - cast('NaN' AS DOUBLE) AS col_double_nan, - cast(null AS DOUBLE) AS col_double_null, - DECIMAL '10.3' AS col_decimal, - cast(null AS DECIMAL) AS col_decimal_null, - cast('0.123456789123456789' AS DECIMAL(18,18)) col_decimal18, - cast(null AS DECIMAL(18,18)) AS col_decimal18_null, - cast('10.3' AS DECIMAL(38,0)) col_decimal38, - cast(null AS DECIMAL(38,0)) AS col_decimal38_null, - 'aaa' AS col_varchar, - U&'Hello winter \2603 !' AS col_varchar_uni, - cast(null AS VARCHAR) AS col_varchar_null, - cast('bbb' AS VARCHAR(1)) AS col_varchar1, - cast(null AS VARCHAR(1)) AS col_varchar1_null, - cast('ccc' AS CHAR) AS col_char, - cast(null AS CHAR) AS col_char_null, - cast('ddd' AS CHAR(1)) AS col_char1, - cast(null AS CHAR(1)) AS col_char1_null, - X'65683F' AS col_varbinary, - cast(null AS VARBINARY) AS col_varbinary_null, - cast('{}' AS JSON) AS col_json, - cast('null' AS JSON) AS col_json_null2, - cast(null AS JSON) AS col_json_null, - DATE '2001-08-22' AS col_date, - cast(null AS DATE) AS col_date_null, - TIME '01:23:45.123' AS col_time, - cast(null AS TIME) AS col_time_null, - cast('01:23:45' AS TIME(0)) AS col_time0, - cast(null AS TIME(0)) AS col_time0_null, - cast('01:23:45.123' AS TIME(3)) AS col_time3, - cast(null AS TIME(3)) AS col_time3_null, - cast('01:23:45.123456' AS TIME(6)) AS col_time6, - cast(null AS TIME(6)) AS col_time6_null, - cast('01:23:45.123456789' AS TIME(9)) AS col_time9, - cast(null AS TIME(9)) AS col_time9_null, - cast('01:23:45.123456789123' AS TIME(12)) AS col_time12, - cast(null AS TIME(12)) AS col_time12_null, - TIME '01:23:45.123 -08:00' AS col_timetz, - cast(null AS TIME WITH TIME ZONE) AS col_timetz_null, - cast('01:23:45 -08:00' AS TIME(0) WITH TIME ZONE) AS col_timetz0, - cast(null AS TIME(0) WITH TIME ZONE) AS col_timetz0_null, - cast('01:23:45.123 -08:00' AS TIME(3) WITH TIME ZONE) AS col_timetz3, - cast(null AS TIME(3) WITH TIME ZONE) AS col_timetz3_null, - cast('01:23:45.123456 -08:00' AS TIME(6) WITH TIME ZONE) AS col_timetz6, - cast(null AS TIME(6) WITH TIME ZONE) AS col_timetz6_null, - cast('01:23:45.123456789 -08:00' AS TIME(9) WITH TIME ZONE) AS col_timetz9, - cast(null AS TIME(9) WITH TIME ZONE) AS col_timetz9_null, - cast('01:23:45.123456789123 -08:00' AS TIME(12) WITH TIME ZONE) AS col_timetz12, - cast(null AS TIME(12) WITH TIME ZONE) AS col_timetz12_null, - TIMESTAMP '2001-08-22 01:23:45.123' AS col_ts, - cast(null AS TIMESTAMP) AS col_ts_null, - cast('2001-08-22 01:23:45' AS TIMESTAMP(0)) AS col_ts0, - cast(null AS TIMESTAMP(0)) AS col_ts0_null, - cast('2001-08-22 01:23:45.123' AS TIMESTAMP(3)) AS col_ts3, - cast(null AS TIMESTAMP(3)) AS col_ts3_null, - cast('2001-08-22 01:23:45.123456' AS TIMESTAMP(6)) AS col_ts6, - cast(null AS TIMESTAMP(6)) AS col_ts6_null, - cast('2001-08-22 01:23:45.123456789' AS TIMESTAMP(9)) AS col_ts9, - cast(null AS TIMESTAMP(9)) AS col_ts9_null, - cast('2001-08-22 01:23:45.123456789123' AS TIMESTAMP(12)) AS col_ts12, - cast(null AS TIMESTAMP(12)) AS col_ts12_null, - TIMESTAMP '2001-08-22 01:23:45.123 -08:00' AS col_tstz, - cast(null AS TIMESTAMP WITH TIME ZONE) AS col_tstz_null, - cast('2001-08-22 01:23:45 -08:00' AS TIMESTAMP(0) WITH TIME ZONE) AS col_tstz0, - cast(null AS TIMESTAMP(0) WITH TIME ZONE) AS col_tstz0_null, - cast('2001-08-22 01:23:45.123 -08:00' AS TIMESTAMP(3) WITH TIME ZONE) AS col_tstz3, - cast(null AS TIMESTAMP(3) WITH TIME ZONE) AS col_tstz3_null, - cast('2001-08-22 01:23:45.123456 -08:00' AS TIMESTAMP(6) WITH TIME ZONE) AS col_tstz6, - cast(null AS TIMESTAMP(6) WITH TIME ZONE) AS col_tstz6_null, - cast('2001-08-22 01:23:45.123456789 -08:00' AS TIMESTAMP(9) WITH TIME ZONE) AS col_tstz9, - cast(null AS TIMESTAMP(9) WITH TIME ZONE) AS col_tstz9_null, - cast('2001-08-22 01:23:45.123456789123 -08:00' AS TIMESTAMP(12) WITH TIME ZONE) AS col_tstz12, - cast(null AS TIMESTAMP(12) WITH TIME ZONE) AS col_tstz12_null, - INTERVAL '3' MONTH AS col_int_year, - cast(null AS INTERVAL YEAR TO MONTH) AS col_int_year_null, - INTERVAL '2' DAY AS col_int_day, - cast(null AS INTERVAL DAY TO SECOND) AS col_int_day_null, - ARRAY['a', 'b', null] AS col_array, - cast(null AS ARRAY(VARCHAR)) AS col_array_null, - MAP(ARRAY['a', 'b'], ARRAY[1, null]) AS col_map, - cast(null AS MAP(VARCHAR, INTEGER)) AS col_map_null, - cast(ROW(1, 2e0) AS ROW(x BIGINT, y DOUBLE)) AS col_row, - cast(null AS ROW(x BIGINT, y DOUBLE)) AS col_row_null, - IPADDRESS '2001:db8::1' AS col_ipaddr, - cast(null AS IPADDRESS) AS col_ipaddr_null, - UUID '12151fd2-7586-11e9-8f9e-2a86e4085a59' AS col_uuid, - cast(null AS UUID) AS col_uuid_null, - approx_set(1) AS col_hll, - cast(null AS HyperLogLog) AS col_hll_null, - cast(approx_set(1) AS P4HyperLogLog) AS col_p4hll, - cast(null AS P4HyperLogLog) AS col_p4hll_null, - make_set_digest(1) AS col_setdigest, - cast(null AS SetDigest) AS col_setdigest_null, - qdigest_agg(1) AS col_qdigest, - cast(null AS QDigest(BIGINT)) AS col_qdigest_null, - tdigest_agg(1) AS col_tdigest, - cast(null AS TDigest) AS col_tdigest_null - """ - -columns = [ - { - "name": "col_bool", - "type": "boolean", - "typeSignature": { - "rawType": "boolean", - "arguments": [] - } - }, - { - "name": "col_bool_null", - "type": "boolean", - "typeSignature": { - "rawType": "boolean", - "arguments": [] - } - }, - { - "name": "col_tinyint", - "type": "tinyint", - "typeSignature": { - "rawType": "tinyint", - "arguments": [] - } - }, - { - "name": "col_tinyint_min", - "type": "tinyint", - "typeSignature": { - "rawType": "tinyint", - "arguments": [] - } - }, - { - "name": "col_tinyint_null", - "type": "tinyint", - "typeSignature": { - "rawType": "tinyint", - "arguments": [] - } - }, - { - "name": "col_smallint", - "type": "smallint", - "typeSignature": { - "rawType": "smallint", - "arguments": [] - } - }, - { - "name": "col_smallint_min", - "type": "smallint", - "typeSignature": { - "rawType": "smallint", - "arguments": [] - } - }, - { - "name": "col_smallint_null", - "type": "smallint", - "typeSignature": { - "rawType": "smallint", - "arguments": [] - } - }, - { - "name": "col_integer", - "type": "integer", - "typeSignature": { - "rawType": "integer", - "arguments": [] - } - }, - { - "name": "col_integer_min", - "type": "integer", - "typeSignature": { - "rawType": "integer", - "arguments": [] - } - }, - { - "name": "col_integer_null", - "type": "integer", - "typeSignature": { - "rawType": "integer", - "arguments": [] - } - }, - { - "name": "col_bigint", - "type": "bigint", - "typeSignature": { - "rawType": "bigint", - "arguments": [] - } - }, - { - "name": "col_bigint_min", - "type": "bigint", - "typeSignature": { - "rawType": "bigint", - "arguments": [] - } - }, - { - "name": "col_bigint_null", - "type": "bigint", - "typeSignature": { - "rawType": "bigint", - "arguments": [] - } - }, - { - "name": "col_real", - "type": "real", - "typeSignature": { - "rawType": "real", - "arguments": [] - } - }, - { - "name": "col_real_min", - "type": "real", - "typeSignature": { - "rawType": "real", - "arguments": [] - } - }, - { - "name": "col_real_inf", - "type": "real", - "typeSignature": { - "rawType": "real", - "arguments": [] - } - }, - { - "name": "col_real_ninf", - "type": "real", - "typeSignature": { - "rawType": "real", - "arguments": [] - } - }, - { - "name": "col_real_nan", - "type": "real", - "typeSignature": { - "rawType": "real", - "arguments": [] - } - }, - { - "name": "col_real_null", - "type": "real", - "typeSignature": { - "rawType": "real", - "arguments": [] - } - }, - { - "name": "col_double", - "type": "double", - "typeSignature": { - "rawType": "double", - "arguments": [] - } - }, - { - "name": "col_double_min", - "type": "double", - "typeSignature": { - "rawType": "double", - "arguments": [] - } - }, - { - "name": "col_double_inf", - "type": "double", - "typeSignature": { - "rawType": "double", - "arguments": [] - } - }, - { - "name": "col_double_ninf", - "type": "double", - "typeSignature": { - "rawType": "double", - "arguments": [] - } - }, - { - "name": "col_double_nan", - "type": "double", - "typeSignature": { - "rawType": "double", - "arguments": [] - } - }, - { - "name": "col_double_null", - "type": "double", - "typeSignature": { - "rawType": "double", - "arguments": [] - } - }, - { - "name": "col_decimal", - "type": "decimal(3, 1)", - "typeSignature": { - "rawType": "decimal", - "arguments": [ - { - "kind": "LONG", - "value": 3 - }, - { - "kind": "LONG", - "value": 1 - } - ] - } - }, - { - "name": "col_decimal_null", - "type": "decimal(38, 0)", - "typeSignature": { - "rawType": "decimal", - "arguments": [ - { - "kind": "LONG", - "value": 38 - }, - { - "kind": "LONG", - "value": 0 - } - ] - } - }, - { - "name": "col_decimal18", - "type": "decimal(18, 18)", - "typeSignature": { - "rawType": "decimal", - "arguments": [ - { - "kind": "LONG", - "value": 18 - }, - { - "kind": "LONG", - "value": 18 - } - ] - } - }, - { - "name": "col_decimal18_null", - "type": "decimal(18, 18)", - "typeSignature": { - "rawType": "decimal", - "arguments": [ - { - "kind": "LONG", - "value": 18 - }, - { - "kind": "LONG", - "value": 18 - } - ] - } - }, - { - "name": "col_decimal38", - "type": "decimal(38, 0)", - "typeSignature": { - "rawType": "decimal", - "arguments": [ - { - "kind": "LONG", - "value": 38 - }, - { - "kind": "LONG", - "value": 0 - } - ] - } - }, - { - "name": "col_decimal38_null", - "type": "decimal(38, 0)", - "typeSignature": { - "rawType": "decimal", - "arguments": [ - { - "kind": "LONG", - "value": 38 - }, - { - "kind": "LONG", - "value": 0 - } - ] - } - }, - { - "name": "col_varchar", - "type": "varchar(3)", - "typeSignature": { - "rawType": "varchar", - "arguments": [ - { - "kind": "LONG", - "value": 3 - } - ] - } - }, - { - "name": "col_varchar_uni", - "type": "varchar(16)", - "typeSignature": { - "rawType": "varchar", - "arguments": [ - { - "kind": "LONG", - "value": 16 - } - ] - } - }, - { - "name": "col_varchar_null", - "type": "varchar", - "typeSignature": { - "rawType": "varchar", - "arguments": [ - { - "kind": "LONG", - "value": 2147483647 - } - ] - } - }, - { - "name": "col_varchar1", - "type": "varchar(1)", - "typeSignature": { - "rawType": "varchar", - "arguments": [ - { - "kind": "LONG", - "value": 1 - } - ] - } - }, - { - "name": "col_varchar1_null", - "type": "varchar(1)", - "typeSignature": { - "rawType": "varchar", - "arguments": [ - { - "kind": "LONG", - "value": 1 - } - ] - } - }, - { - "name": "col_char", - "type": "char(1)", - "typeSignature": { - "rawType": "char", - "arguments": [ - { - "kind": "LONG", - "value": 1 - } - ] - } - }, - { - "name": "col_char_null", - "type": "char(1)", - "typeSignature": { - "rawType": "char", - "arguments": [ - { - "kind": "LONG", - "value": 1 - } - ] - } - }, - { - "name": "col_char1", - "type": "char(1)", - "typeSignature": { - "rawType": "char", - "arguments": [ - { - "kind": "LONG", - "value": 1 - } - ] - } - }, - { - "name": "col_char1_null", - "type": "char(1)", - "typeSignature": { - "rawType": "char", - "arguments": [ - { - "kind": "LONG", - "value": 1 - } - ] - } - }, - { - "name": "col_varbinary", - "type": "varbinary", - "typeSignature": { - "rawType": "varbinary", - "arguments": [] - } - }, - { - "name": "col_varbinary_null", - "type": "varbinary", - "typeSignature": { - "rawType": "varbinary", - "arguments": [] - } - }, - { - "name": "col_json", - "type": "json", - "typeSignature": { - "rawType": "json", - "arguments": [] - } - }, - { - "name": "col_json_null2", - "type": "json", - "typeSignature": { - "rawType": "json", - "arguments": [] - } - }, - { - "name": "col_json_null", - "type": "json", - "typeSignature": { - "rawType": "json", - "arguments": [] - } - }, - { - "name": "col_date", - "type": "date", - "typeSignature": { - "rawType": "date", - "arguments": [] - } - }, - { - "name": "col_date_null", - "type": "date", - "typeSignature": { - "rawType": "date", - "arguments": [] - } - }, - { - "name": "col_time", - "type": "time(3)", - "typeSignature": { - "rawType": "time", - "arguments": [ - { - "kind": "LONG", - "value": 3 - } - ] - } - }, - { - "name": "col_time_null", - "type": "time(3)", - "typeSignature": { - "rawType": "time", - "arguments": [ - { - "kind": "LONG", - "value": 3 - } - ] - } - }, - { - "name": "col_time0", - "type": "time(0)", - "typeSignature": { - "rawType": "time", - "arguments": [ - { - "kind": "LONG", - "value": 0 - } - ] - } - }, - { - "name": "col_time0_null", - "type": "time(0)", - "typeSignature": { - "rawType": "time", - "arguments": [ - { - "kind": "LONG", - "value": 0 - } - ] - } - }, - { - "name": "col_time3", - "type": "time(3)", - "typeSignature": { - "rawType": "time", - "arguments": [ - { - "kind": "LONG", - "value": 3 - } - ] - } - }, - { - "name": "col_time3_null", - "type": "time(3)", - "typeSignature": { - "rawType": "time", - "arguments": [ - { - "kind": "LONG", - "value": 3 - } - ] - } - }, - { - "name": "col_time6", - "type": "time(6)", - "typeSignature": { - "rawType": "time", - "arguments": [ - { - "kind": "LONG", - "value": 6 - } - ] - } - }, - { - "name": "col_time6_null", - "type": "time(6)", - "typeSignature": { - "rawType": "time", - "arguments": [ - { - "kind": "LONG", - "value": 6 - } - ] - } - }, - { - "name": "col_time9", - "type": "time(9)", - "typeSignature": { - "rawType": "time", - "arguments": [ - { - "kind": "LONG", - "value": 9 - } - ] - } - }, - { - "name": "col_time9_null", - "type": "time(9)", - "typeSignature": { - "rawType": "time", - "arguments": [ - { - "kind": "LONG", - "value": 9 - } - ] - } - }, - { - "name": "col_time12", - "type": "time(12)", - "typeSignature": { - "rawType": "time", - "arguments": [ - { - "kind": "LONG", - "value": 12 - } - ] - } - }, - { - "name": "col_time12_null", - "type": "time(12)", - "typeSignature": { - "rawType": "time", - "arguments": [ - { - "kind": "LONG", - "value": 12 - } - ] - } - }, - { - "name": "col_timetz", - "type": "time(3) with time zone", - "typeSignature": { - "rawType": "time with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 3 - } - ] - } - }, - { - "name": "col_timetz_null", - "type": "time(3) with time zone", - "typeSignature": { - "rawType": "time with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 3 - } - ] - } - }, - { - "name": "col_timetz0", - "type": "time(0) with time zone", - "typeSignature": { - "rawType": "time with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 0 - } - ] - } - }, - { - "name": "col_timetz0_null", - "type": "time(0) with time zone", - "typeSignature": { - "rawType": "time with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 0 - } - ] - } - }, - { - "name": "col_timetz3", - "type": "time(3) with time zone", - "typeSignature": { - "rawType": "time with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 3 - } - ] - } - }, - { - "name": "col_timetz3_null", - "type": "time(3) with time zone", - "typeSignature": { - "rawType": "time with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 3 - } - ] - } - }, - { - "name": "col_timetz6", - "type": "time(6) with time zone", - "typeSignature": { - "rawType": "time with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 6 - } - ] - } - }, - { - "name": "col_timetz6_null", - "type": "time(6) with time zone", - "typeSignature": { - "rawType": "time with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 6 - } - ] - } - }, - { - "name": "col_timetz9", - "type": "time(9) with time zone", - "typeSignature": { - "rawType": "time with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 9 - } - ] - } - }, - { - "name": "col_timetz9_null", - "type": "time(9) with time zone", - "typeSignature": { - "rawType": "time with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 9 - } - ] - } - }, - { - "name": "col_timetz12", - "type": "time(12) with time zone", - "typeSignature": { - "rawType": "time with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 12 - } - ] - } - }, - { - "name": "col_timetz12_null", - "type": "time(12) with time zone", - "typeSignature": { - "rawType": "time with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 12 - } - ] - } - }, - { - "name": "col_ts", - "type": "timestamp(3)", - "typeSignature": { - "rawType": "timestamp", - "arguments": [ - { - "kind": "LONG", - "value": 3 - } - ] - } - }, - { - "name": "col_ts_null", - "type": "timestamp(3)", - "typeSignature": { - "rawType": "timestamp", - "arguments": [ - { - "kind": "LONG", - "value": 3 - } - ] - } - }, - { - "name": "col_ts0", - "type": "timestamp(0)", - "typeSignature": { - "rawType": "timestamp", - "arguments": [ - { - "kind": "LONG", - "value": 0 - } - ] - } - }, - { - "name": "col_ts0_null", - "type": "timestamp(0)", - "typeSignature": { - "rawType": "timestamp", - "arguments": [ - { - "kind": "LONG", - "value": 0 - } - ] - } - }, - { - "name": "col_ts3", - "type": "timestamp(3)", - "typeSignature": { - "rawType": "timestamp", - "arguments": [ - { - "kind": "LONG", - "value": 3 - } - ] - } - }, - { - "name": "col_ts3_null", - "type": "timestamp(3)", - "typeSignature": { - "rawType": "timestamp", - "arguments": [ - { - "kind": "LONG", - "value": 3 - } - ] - } - }, - { - "name": "col_ts6", - "type": "timestamp(6)", - "typeSignature": { - "rawType": "timestamp", - "arguments": [ - { - "kind": "LONG", - "value": 6 - } - ] - } - }, - { - "name": "col_ts6_null", - "type": "timestamp(6)", - "typeSignature": { - "rawType": "timestamp", - "arguments": [ - { - "kind": "LONG", - "value": 6 - } - ] - } - }, - { - "name": "col_ts9", - "type": "timestamp(9)", - "typeSignature": { - "rawType": "timestamp", - "arguments": [ - { - "kind": "LONG", - "value": 9 - } - ] - } - }, - { - "name": "col_ts9_null", - "type": "timestamp(9)", - "typeSignature": { - "rawType": "timestamp", - "arguments": [ - { - "kind": "LONG", - "value": 9 - } - ] - } - }, - { - "name": "col_ts12", - "type": "timestamp(12)", - "typeSignature": { - "rawType": "timestamp", - "arguments": [ - { - "kind": "LONG", - "value": 12 - } - ] - } - }, - { - "name": "col_ts12_null", - "type": "timestamp(12)", - "typeSignature": { - "rawType": "timestamp", - "arguments": [ - { - "kind": "LONG", - "value": 12 - } - ] - } - }, - { - "name": "col_tstz", - "type": "timestamp(3) with time zone", - "typeSignature": { - "rawType": "timestamp with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 3 - } - ] - } - }, - { - "name": "col_tstz_null", - "type": "timestamp(3) with time zone", - "typeSignature": { - "rawType": "timestamp with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 3 - } - ] - } - }, - { - "name": "col_tstz0", - "type": "timestamp(0) with time zone", - "typeSignature": { - "rawType": "timestamp with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 0 - } - ] - } - }, - { - "name": "col_tstz0_null", - "type": "timestamp(0) with time zone", - "typeSignature": { - "rawType": "timestamp with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 0 - } - ] - } - }, - { - "name": "col_tstz3", - "type": "timestamp(3) with time zone", - "typeSignature": { - "rawType": "timestamp with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 3 - } - ] - } - }, - { - "name": "col_tstz3_null", - "type": "timestamp(3) with time zone", - "typeSignature": { - "rawType": "timestamp with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 3 - } - ] - } - }, - { - "name": "col_tstz6", - "type": "timestamp(6) with time zone", - "typeSignature": { - "rawType": "timestamp with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 6 - } - ] - } - }, - { - "name": "col_tstz6_null", - "type": "timestamp(6) with time zone", - "typeSignature": { - "rawType": "timestamp with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 6 - } - ] - } - }, - { - "name": "col_tstz9", - "type": "timestamp(9) with time zone", - "typeSignature": { - "rawType": "timestamp with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 9 - } - ] - } - }, - { - "name": "col_tstz9_null", - "type": "timestamp(9) with time zone", - "typeSignature": { - "rawType": "timestamp with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 9 - } - ] - } - }, - { - "name": "col_tstz12", - "type": "timestamp(12) with time zone", - "typeSignature": { - "rawType": "timestamp with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 12 - } - ] - } - }, - { - "name": "col_tstz12_null", - "type": "timestamp(12) with time zone", - "typeSignature": { - "rawType": "timestamp with time zone", - "arguments": [ - { - "kind": "LONG", - "value": 12 - } - ] - } - }, - { - "name": "col_int_year", - "type": "INTERVAL YEAR TO MONTH", - "typeSignature": { - "rawType": "interval year to month", - "arguments": [] - } - }, - { - "name": "col_int_year_null", - "type": "INTERVAL YEAR TO MONTH", - "typeSignature": { - "rawType": "interval year to month", - "arguments": [] - } - }, - { - "name": "col_int_day", - "type": "INTERVAL DAY TO SECOND", - "typeSignature": { - "rawType": "interval day to second", - "arguments": [] - } - }, - { - "name": "col_int_day_null", - "type": "INTERVAL DAY TO SECOND", - "typeSignature": { - "rawType": "interval day to second", - "arguments": [] - } - }, - { - "name": "col_array", - "type": "array(varchar(1))", - "typeSignature": { - "rawType": "array", - "arguments": [ - { - "kind": "TYPE", - "value": { - "rawType": "varchar", - "arguments": [ - { - "kind": "LONG", - "value": 1 - } - ] - } - } - ] - } - }, - { - "name": "col_array_null", - "type": "array(varchar)", - "typeSignature": { - "rawType": "array", - "arguments": [ - { - "kind": "TYPE", - "value": { - "rawType": "varchar", - "arguments": [ - { - "kind": "LONG", - "value": 2147483647 - } - ] - } - } - ] - } - }, - { - "name": "col_map", - "type": "map(varchar(1), integer)", - "typeSignature": { - "rawType": "map", - "arguments": [ - { - "kind": "TYPE", - "value": { - "rawType": "varchar", - "arguments": [ - { - "kind": "LONG", - "value": 1 - } - ] - } - }, - { - "kind": "TYPE", - "value": { - "rawType": "integer", - "arguments": [] - } - } - ] - } - }, - { - "name": "col_map_null", - "type": "map(varchar, integer)", - "typeSignature": { - "rawType": "map", - "arguments": [ - { - "kind": "TYPE", - "value": { - "rawType": "varchar", - "arguments": [ - { - "kind": "LONG", - "value": 2147483647 - } - ] - } - }, - { - "kind": "TYPE", - "value": { - "rawType": "integer", - "arguments": [] - } - } - ] - } - }, - { - "name": "col_row", - "type": "row(x bigint, y double)", - "typeSignature": { - "rawType": "row", - "arguments": [ - { - "kind": "NAMED_TYPE", - "value": { - "fieldName": { - "name": "x" - }, - "typeSignature": { - "rawType": "bigint", - "arguments": [] - } - } - }, - { - "kind": "NAMED_TYPE", - "value": { - "fieldName": { - "name": "y" - }, - "typeSignature": { - "rawType": "double", - "arguments": [] - } - } - } - ] - } - }, - { - "name": "col_row_null", - "type": "row(x bigint, y double)", - "typeSignature": { - "rawType": "row", - "arguments": [ - { - "kind": "NAMED_TYPE", - "value": { - "fieldName": { - "name": "x" - }, - "typeSignature": { - "rawType": "bigint", - "arguments": [] - } - } - }, - { - "kind": "NAMED_TYPE", - "value": { - "fieldName": { - "name": "y" - }, - "typeSignature": { - "rawType": "double", - "arguments": [] - } - } - } - ] - } - }, - { - "name": "col_ipaddr", - "type": "ipaddress", - "typeSignature": { - "rawType": "ipaddress", - "arguments": [] - } - }, - { - "name": "col_ipaddr_null", - "type": "ipaddress", - "typeSignature": { - "rawType": "ipaddress", - "arguments": [] - } - }, - { - "name": "col_uuid", - "type": "uuid", - "typeSignature": { - "rawType": "uuid", - "arguments": [] - } - }, - { - "name": "col_uuid_null", - "type": "uuid", - "typeSignature": { - "rawType": "uuid", - "arguments": [] - } - }, - { - "name": "col_hll", - "type": "HyperLogLog", - "typeSignature": { - "rawType": "HyperLogLog", - "arguments": [] - } - }, - { - "name": "col_hll_null", - "type": "HyperLogLog", - "typeSignature": { - "rawType": "HyperLogLog", - "arguments": [] - } - }, - { - "name": "col_p4hll", - "type": "P4HyperLogLog", - "typeSignature": { - "rawType": "P4HyperLogLog", - "arguments": [] - } - }, - { - "name": "col_p4hll_null", - "type": "P4HyperLogLog", - "typeSignature": { - "rawType": "P4HyperLogLog", - "arguments": [] - } - }, - { - "name": "col_setdigest", - "type": "SetDigest", - "typeSignature": { - "rawType": "SetDigest", - "arguments": [] - } - }, - { - "name": "col_setdigest_null", - "type": "SetDigest", - "typeSignature": { - "rawType": "SetDigest", - "arguments": [] - } - }, - { - "name": "col_qdigest", - "type": "qdigest(bigint)", - "typeSignature": { - "rawType": "qdigest", - "arguments": [ - { - "kind": "TYPE", - "value": { - "rawType": "bigint", - "arguments": [] - } - } - ] - } - }, - { - "name": "col_qdigest_null", - "type": "qdigest(bigint)", - "typeSignature": { - "rawType": "qdigest", - "arguments": [ - { - "kind": "TYPE", - "value": { - "rawType": "bigint", - "arguments": [] - } - } - ] - } - }, - { - "name": "col_tdigest", - "type": "tdigest", - "typeSignature": { - "rawType": "tdigest", - "arguments": [] - } - }, - { - "name": "col_tdigest_null", - "type": "tdigest", - "typeSignature": { - "rawType": "tdigest", - "arguments": [] - } - } - ] - -rows = [ - [ - False, - None, - 127, - -128, - None, - 32767, - -32768, - None, - 2147483647, - -2147483648, - None, - 9223372036854775807, - -9223372036854775808, - None, - 3.4028235E38, - 1.4E-45, - "Infinity", - "-Infinity", - "NaN", - None, - 1.7976931348623157E308, - 4.9E-324, - "Infinity", - "-Infinity", - "NaN", - None, - "10.3", - None, - "0.123456789123456789", - None, - "10", - None, - "aaa", - "Hello winter °3 !", - None, - "b", - None, - "c", - None, - "d", - None, - "ZWg/", - None, - "\"{}\"", - "\"null\"", - None, - "2001-08-22", - None, - "01:23:45.123", - None, - "01:23:45", - None, - "01:23:45.123", - None, - "01:23:45.123456", - None, - "01:23:45.123456789", - None, - "01:23:45.123456789123", - None, - "01:23:45.123-08:00", - None, - "01:23:45-08:00", - None, - "01:23:45.123-08:00", - None, - "01:23:45.123456-08:00", - None, - "01:23:45.123456789-08:00", - None, - "01:23:45.123456789123-08:00", - None, - "2001-08-22 01:23:45.123", - None, - "2001-08-22 01:23:45", - None, - "2001-08-22 01:23:45.123", - None, - "2001-08-22 01:23:45.123456", - None, - "2001-08-22 01:23:45.123456789", - None, - "2001-08-22 01:23:45.123456789123", - None, - "2001-08-22 01:23:45.123 -08:00", - None, - "2001-08-22 01:23:45 -08:00", - None, - "2001-08-22 01:23:45.123 -08:00", - None, - "2001-08-22 01:23:45.123456 -08:00", - None, - "2001-08-22 01:23:45.123456789 -08:00", - None, - "2001-08-22 01:23:45.123456789123 -08:00", - None, - "0-3", - None, - "2 00:00:00.000", - None, - [ - "a", - "b", - None - ], - None, - { - "a": 1, - "b": None - }, - None, - [ - 1, - 2.0 - ], - None, - "2001:db8::1", - None, - "12151fd2-7586-11e9-8f9e-2a86e4085a59", - None, - "AgwBAIADRAA=", - None, - "AwwAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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gAAABAAAASsQF+7cDRAABAA==", - None, - "AHsUrkfheoQ/AAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAPA/AQAAAAAAAIA=", - None, - "AAAAAAAAAPA/AAAAAAAA8D8AAAAAAABZQAAAAAAAAPA/AQAAAAAAAAAAAPA/AAAAAAAA8D8=", - None - ] - ] - - -EXPECTED_RESPONSE = [ - False, - None, - 127, - -128, - None, - 32767, - -32768, - None, - 2147483647, - -2147483648, - None, - 9223372036854775807, - -9223372036854775808, - None, - 3.4028235e+38, - 1.4e-45, - math.inf, - -math.inf, - math.nan, - None, - 1.7976931348623157e+308, - 5e-324, - math.inf, - -math.inf, - math.nan, - None, - 10.3, - None, - 0.12345678912345678, - None, - 10.0, - None, - 'aaa', - 'Hello winter \2603 !', - None, - 'b', - None, - 'c', - None, - 'd', - None, - 'ZWg/', - None, - {}, - None, - None, - datetime.date(2001, 8, 22), - None, - datetime.time(1, 23, 45, 123000), - None, - datetime.time(1, 23, 45), - None, - datetime.time(1, 23, 45, 123000), - None, - datetime.time(1, 23, 45, 123456), - None, - datetime.time(1, 23, 45, 123456), - None, - datetime.time(1, 23, 45, 123456), - None, - datetime.time(1, 23, 45, 123000), - None, - datetime.time(1, 23, 45), - None, - datetime.time(1, 23, 45, 123000), - None, - datetime.time(1, 23, 45, 123456), - None, - datetime.time(1, 23, 45, 123456), - None, - datetime.time(1, 23, 45, 123456), - None, - datetime.datetime(2001, 8, 22, 1, 23, 45, 123000), - None, - datetime.datetime(2001, 8, 22, 1, 23, 45), - None, - datetime.datetime(2001, 8, 22, 1, 23, 45, 123000), - None, - datetime.datetime(2001, 8, 22, 1, 23, 45, 123456), - None, - datetime.datetime(2001, 8, 22, 1, 23, 45, 189000), - None, - datetime.datetime(2001, 8, 22, 1, 23, 45, 189123), - None, - datetime.datetime(2001, 8, 22, 1, 23, 45, 123000, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), - None, - datetime.datetime(2001, 8, 22, 1, 23, 45, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), - None, - datetime.datetime(2001, 8, 22, 1, 23, 45, 123000, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), - None, - datetime.datetime(2001, 8, 22, 1, 23, 45, 123456, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), - None, - datetime.datetime(2001, 8, 22, 1, 23, 45, 189000, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), - None, - datetime.datetime(2001, 8, 22, 1, 23, 45, 189123, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), - None, - '0-3', - None, - '2 00:00:00.000', - None, - ['a', 'b', None], - None, - {'a': 1, 'b': None}, - None, - [1, 2.0], - None, - '2001:db8::1', - None, - '12151fd2-7586-11e9-8f9e-2a86e4085a59', - None, - 'AgwBAIADRAA=', - None, - 'AwwAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==', - None, - 'AQgAAAACCwEAgANEAAAgAAABAAAASsQF+7cDRAABAA==', - None, - 'AHsUrkfheoQ/AAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAPA/AQAAAAAAAIA=', - None, - 'AAAAAAAAAPA/AAAAAAAA8D8AAAAAAABZQAAAAAAAAPA/AQAAAAAAAAAAAPA/AAAAAAAA8D8=', - None -] - -def test_types(): - t = TrinoStatus(id="id", stats={}, warnings=[], info_uri="", next_uri="", update_type="", rows=rows, columns=columns) - - assert len(t.rows) == 1 - result = t.rows[0] - - assert len(result) == len(EXPECTED_RESPONSE) - - for i in range(len(result)): - lval = result[i] - rval = EXPECTED_RESPONSE[i] - - if lval != rval: - if type(lval) == float and math.isnan(lval) and type(rval) == float and math.isnan(rval): - continue - - assert rval == lval diff --git a/trino/client.py b/trino/client.py index f56df4dd..ae8f1831 100644 --- a/trino/client.py +++ b/trino/client.py @@ -211,8 +211,9 @@ def __init__(self, id, stats, warnings, info_uri, next_uri, update_type, rows, c self.info_uri = info_uri self.next_uri = next_uri self.update_type = update_type - self.rows = self.__process_rows(rows, columns) + self.rows = rows self.columns = columns + self.col_mapping_funcs = [] if columns is None else [self._col_func(column['typeSignature']) for column in columns] def __repr__(self): return ( @@ -227,48 +228,48 @@ def __repr__(self): ) ) - def __process_rows(self, rows, columns): - if len(rows) == 0: - return [] - col_funcs = [self.__col_func(column) for column in columns] - - return [self.__process_row(row, col_funcs) for row in rows] - - def __process_row(self, row, col_funcs): - result = [] - for idx, val in enumerate(row): - if val is None: - result.append(None) - else: - result.append((col_funcs[idx])(val)) - return result - - def __col_func(self, column): - col_type = column['type'] - - if col_type.startswith('decimal') or col_type.startswith('double') or col_type.startswith('real'): + def _col_func(self, column): + col_type = column['rawType'] + + if col_type == 'array': + return lambda values : [self._col_func(column['arguments'][0]['value'])(value) for value in values] + elif col_type == 'row': + return lambda values : tuple(self._col_func(column['arguments'][idx]['value']['typeSignature'])(value) for idx, value in enumerate(values)) + elif col_type == 'map': + return lambda values : {self._col_func(column['arguments'][0]['value'])(key) : self._col_func(column['arguments'][1]['value'])(value) for key, value in values.items()} + elif col_type.startswith('decimal'): + return lambda val : Decimal(val) + elif col_type.startswith('double') or col_type.startswith('real'): return lambda val : float('inf') if val == 'Infinity' else -float('inf') if val == '-Infinity' else float('nan') if val == 'NaN' else float(val) - elif col_type == 'timestamp' or col_type == 'timestamp(0)': - return lambda val : datetime.strptime(val, "%Y-%m-%d %H:%M:%S") elif col_type.startswith('time'): pattern = "%Y-%m-%d %H:%M:%S" if col_type.startswith('timestamp') else "%H:%M:%S" - ms_size, ms_to_trim = self.__get_number_of_digits(col_type) + ms_size, ms_to_trim = self._get_number_of_digits(column) if ms_size > 0: pattern += ".%f" if col_type.startswith('timestamp'): datetime_size = 21 + ms_size - ms_to_trim if 'with time zone' in col_type: - pattern += ' %z' + + if ms_to_trim > 0: + return lambda val: [datetime.strptime(val[:21] + val[datetime_size:], pattern + ' %z') if tz.startswith('+') or tz.startswith('-') else datetime.strptime(dt[:21] + dt[datetime_size:], pattern).replace(tzinfo=pytz.timezone(tz)) for dt, tz in [val.rsplit(' ', 1)]][0] + else: + return lambda val: [datetime.strptime(val, pattern + ' %z') if tz.startswith('+') or tz.startswith('-') else datetime.strptime(dt, pattern).replace(tzinfo=pytz.timezone(tz)) for dt, tz in [val.rsplit(' ', 1)]][0] if ms_to_trim > 0: return lambda val : datetime.strptime(val[:21] + val[datetime_size:], pattern) else: return lambda val : datetime.strptime(val, pattern) + # Time else: time_size = 9 + ms_size - ms_to_trim - return lambda val : datetime.strptime(val[:time_size], pattern).time() + + if 'with time zone' in col_type: + return lambda val : self._get_time_with_timezome(val, time_size, pattern) + else: + return lambda val : datetime.strptime(val[:time_size], pattern).time() + elif col_type == 'date': return lambda val : datetime.strptime(val, '%Y-%m-%d').date() elif col_type == 'json': @@ -276,12 +277,18 @@ def __col_func(self, column): else: return lambda val : val - def __get_number_of_digits(self, col_type): - start_bracket_idx = col_type.find('(') + 1 - if start_bracket_idx == 0: - return -1, 0 - end_bracket_idx = col_type.find(')') - ms_size = int(col_type[start_bracket_idx:end_bracket_idx]) + def _get_time_with_timezome(self, value, time_size, pattern): + matches = re.match(r'^(.*)([\+\-])(\d{2}):(\d{2})$', value) + assert matches is not None + assert len(matches.groups()) == 4 + if matches.group(2) == '-': + tz = -timedelta(hours=int(matches.group(3)), minutes=int(matches.group(4))) + else: + tz = timedelta(hours=int(matches.group(3)), minutes=int(matches.group(4))) + return datetime.strptime(matches.group(1)[:time_size], pattern).time().replace(tzinfo=timezone(tz)) + + def _get_number_of_digits(self, column): + ms_size = column['arguments'][0]['value'] if ms_size == 0: return -1, 0 ms_to_trim = ms_size - min(ms_size, 6) @@ -369,6 +376,7 @@ def __init__( self._http_session = self.http.Session() self._http_session.verify = verify self._http_session.headers.update(self.http_headers) + self._http_session.headers['x-trino-client-capabilities'] = 'PARAMETRIC_DATETIME' self._exceptions = self.HTTP_EXCEPTIONS self._auth = auth if self._auth: @@ -604,9 +612,10 @@ class TrinoResult(object): https://docs.python.org/3/library/stdtypes.html#generator-types """ - def __init__(self, query, rows=None, experimental_python_types: bool = False): + def __init__(self, query, rows=None, col_mapping_funcs=None, experimental_python_types: bool = False): self._query = query self._rows = rows or [] + self._col_mapping_funcs = col_mapping_funcs or [] self._rownumber = 0 self._experimental_python_types = experimental_python_types @@ -618,100 +627,42 @@ def __iter__(self): # Initial fetch from the first POST request for row in self._rows: self._rownumber += 1 - yield self._map_row(self._experimental_python_types, row, self._query.columns) + yield self._map_row(self._experimental_python_types, row, self._col_mapping_funcs) self._rows = None # Subsequent fetches from GET requests until next_uri is empty. while not self._query.finished: - rows = self._query.fetch() + rows, col_mapping_funcs = self._query.fetch() for row in rows: self._rownumber += 1 logger.debug("row %s", row) - yield self._map_row(self._experimental_python_types, row, self._query.columns) + yield self._map_row(self._experimental_python_types, row, col_mapping_funcs) @property def response_headers(self): return self._query.response_headers @classmethod - def _map_row(cls, experimental_python_types, row, columns): + def _map_row(cls, experimental_python_types, row, col_mapping_func): if not experimental_python_types: return row else: - return cls._map_to_python_types(cls, row, columns) + return cls._map_to_python_types(cls, row, col_mapping_func) @classmethod def _map_to_python_type(cls, item: Tuple[Any, Dict]) -> Any: - (value, data_type) = item + (value, col_mapping_func) = item if value is None: return None - raw_type = data_type["typeSignature"]["rawType"] - try: - if isinstance(value, list): - if raw_type == "array": - raw_type = { - "typeSignature": data_type["typeSignature"]["arguments"][0]["value"] - } - return [cls._map_to_python_type((array_item, raw_type)) for array_item in value] - if raw_type == "row": - raw_types = map(lambda arg: arg["value"], data_type["typeSignature"]["arguments"]) - return tuple( - cls._map_to_python_type((array_item, raw_type)) - for (array_item, raw_type) in zip(value, raw_types) - ) - return value - if isinstance(value, dict): - raw_key_type = { - "typeSignature": data_type["typeSignature"]["arguments"][0]["value"] - } - raw_value_type = { - "typeSignature": data_type["typeSignature"]["arguments"][1]["value"] - } - return { - cls._map_to_python_type((key, raw_key_type)): - cls._map_to_python_type((value[key], raw_value_type)) - for key in value - } - elif "decimal" in raw_type: - return Decimal(value) - elif raw_type == "double": - if value == 'Infinity': - return INF - elif value == '-Infinity': - return NEGATIVE_INF - elif value == 'NaN': - return NAN - return value - elif raw_type == "date": - return datetime.strptime(value, "%Y-%m-%d").date() - elif raw_type == "timestamp with time zone": - dt, tz = value.rsplit(' ', 1) - if tz.startswith('+') or tz.startswith('-'): - return datetime.strptime(value, "%Y-%m-%d %H:%M:%S.%f %z") - return datetime.strptime(dt, "%Y-%m-%d %H:%M:%S.%f").replace(tzinfo=pytz.timezone(tz)) - elif "timestamp" in raw_type: - return datetime.strptime(value, "%Y-%m-%d %H:%M:%S.%f") - elif "time with time zone" in raw_type: - matches = re.match(r'^(.*)([\+\-])(\d{2}):(\d{2})$', value) - assert matches is not None - assert len(matches.groups()) == 4 - if matches.group(2) == '-': - tz = -timedelta(hours=int(matches.group(3)), minutes=int(matches.group(4))) - else: - tz = timedelta(hours=int(matches.group(3)), minutes=int(matches.group(4))) - return datetime.strptime(matches.group(1), "%H:%M:%S.%f").time().replace(tzinfo=timezone(tz)) - elif "time" in raw_type: - return datetime.strptime(value, "%H:%M:%S.%f").time() - else: - return value + return col_mapping_func(value) except ValueError as e: - error_str = f"Could not convert '{value}' into the associated python type for '{raw_type}'" + error_str = f"Could not convert '{value}' into the associated python type" raise trino.exceptions.TrinoDataError(error_str) from e - def _map_to_python_types(self, row: List[Any], columns: List[Dict[str, Any]]) -> List[Any]: + def _map_to_python_types(self, row: List[Any], columns) -> List[Any]: return list(map(self._map_to_python_type, zip(row, columns))) @@ -745,7 +696,8 @@ def columns(self): while not self._columns and not self.finished and not self.cancelled: # Columns don't return immediate after query is summited. # Continue fetching data until columns are available and push fetched rows into buffer. - self._result._rows += self.fetch() + rows, _ = self.fetch() + self._result._rows += rows return self._columns @property @@ -788,7 +740,7 @@ def execute(self, additional_http_headers=None) -> TrinoResult: self._warnings = getattr(status, "warnings", []) if status.next_uri is None: self._finished = True - self._result = TrinoResult(self, status.rows, self._experimental_python_types) + self._result = TrinoResult(self, rows=status.rows, col_mapping_funcs=status.col_mapping_funcs, experimental_python_types=self._experimental_python_types) return self._result def _update_state(self, status): @@ -806,7 +758,7 @@ def fetch(self) -> List[List[Any]]: self._response_headers = response.headers if status.next_uri is None: self._finished = True - return status.rows + return status.rows, status.col_mapping_funcs def cancel(self) -> None: """Cancel the current query""" From 403f5b7143e9ca862acbb08f2f8e28f56b5115df Mon Sep 17 00:00:00 2001 From: lpoulain Date: Tue, 19 Jul 2022 22:03:45 -0400 Subject: [PATCH 3/9] Fixed dbapi integration tests --- tests/integration/test_dbapi_integration.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_dbapi_integration.py b/tests/integration/test_dbapi_integration.py index ab5b1f49..72c45db6 100644 --- a/tests/integration/test_dbapi_integration.py +++ b/tests/integration/test_dbapi_integration.py @@ -282,7 +282,7 @@ def test_datetime_query_param(trino_connection): rows = cur.fetchall() assert rows[0][0] == params - assert cur.description[0][1] == "timestamp" + assert cur.description[0][1] == "timestamp(6)" def test_datetime_with_utc_time_zone_query_param(trino_connection): @@ -294,7 +294,7 @@ def test_datetime_with_utc_time_zone_query_param(trino_connection): rows = cur.fetchall() assert rows[0][0] == params - assert cur.description[0][1] == "timestamp with time zone" + assert cur.description[0][1] == "timestamp(6) with time zone" def test_datetime_with_numeric_offset_time_zone_query_param(trino_connection): @@ -308,7 +308,7 @@ def test_datetime_with_numeric_offset_time_zone_query_param(trino_connection): rows = cur.fetchall() assert rows[0][0] == params - assert cur.description[0][1] == "timestamp with time zone" + assert cur.description[0][1] == "timestamp(6) with time zone" def test_datetime_with_named_time_zone_query_param(trino_connection): @@ -320,7 +320,7 @@ def test_datetime_with_named_time_zone_query_param(trino_connection): rows = cur.fetchall() assert rows[0][0] == params - assert cur.description[0][1] == "timestamp with time zone" + assert cur.description[0][1] == "timestamp(6) with time zone" def test_datetime_with_trailing_zeros(trino_connection): @@ -1034,3 +1034,4 @@ def test_use_catalog(run_trino): result = cur.fetchall() assert result[0][0] == 'tpch' assert result[0][1] == 'sf1' + From 222d388a4e2a7b94e0a3cc895afd91edf32a2e3b Mon Sep 17 00:00:00 2001 From: lpoulain Date: Wed, 20 Jul 2022 08:27:21 -0400 Subject: [PATCH 4/9] Slight optimization for array/map/row types --- tests/integration/test_dbapi_integration.py | 1 - trino/client.py | 10 +++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_dbapi_integration.py b/tests/integration/test_dbapi_integration.py index 72c45db6..924744b9 100644 --- a/tests/integration/test_dbapi_integration.py +++ b/tests/integration/test_dbapi_integration.py @@ -1034,4 +1034,3 @@ def test_use_catalog(run_trino): result = cur.fetchall() assert result[0][0] == 'tpch' assert result[0][1] == 'sf1' - diff --git a/trino/client.py b/trino/client.py index ae8f1831..cda260c8 100644 --- a/trino/client.py +++ b/trino/client.py @@ -232,11 +232,15 @@ def _col_func(self, column): col_type = column['rawType'] if col_type == 'array': - return lambda values : [self._col_func(column['arguments'][0]['value'])(value) for value in values] + elt_mapping_func = self._col_func(column['arguments'][0]['value']) + return lambda values : [elt_mapping_func(value) for value in values] elif col_type == 'row': - return lambda values : tuple(self._col_func(column['arguments'][idx]['value']['typeSignature'])(value) for idx, value in enumerate(values)) + elt_mapping_funcs = [self._col_func(arg['value']['typeSignature']) for arg in column['arguments']] + return lambda values : tuple(elt_mapping_funcs[idx](value) for idx, value in enumerate(values)) elif col_type == 'map': - return lambda values : {self._col_func(column['arguments'][0]['value'])(key) : self._col_func(column['arguments'][1]['value'])(value) for key, value in values.items()} + key_mapping_func = self._col_func(column['arguments'][0]['value']) + value_mapping_func = self._col_func(column['arguments'][1]['value']) + return lambda values : {key_mapping_func(key) : value_mapping_func(value) for key, value in values.items()} elif col_type.startswith('decimal'): return lambda val : Decimal(val) elif col_type.startswith('double') or col_type.startswith('real'): From 2d377902c14505386146ff0c99e978b0611c3b56 Mon Sep 17 00:00:00 2001 From: lpoulain Date: Wed, 20 Jul 2022 10:37:43 -0400 Subject: [PATCH 5/9] Code change to fix code check errors --- tests/integration/test_types_integration.py | 7 ++-- trino/client.py | 43 +++++++++++++-------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/tests/integration/test_types_integration.py b/tests/integration/test_types_integration.py index 597ecfca..b0caac3c 100644 --- a/tests/integration/test_types_integration.py +++ b/tests/integration/test_types_integration.py @@ -287,8 +287,7 @@ def test_misc_types(trino_connection): None, 'AgwBAIADRAA=', None, - - 'AwwAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==', + 'AwwAAAAg' + 'A'*2730 + '==', None, 'AQgAAAACCwEAgANEAAAgAAABAAAASsQF+7cDRAABAA==', None, @@ -298,12 +297,14 @@ def test_misc_types(trino_connection): None ]) + def compare_results(actual, expected): assert len(actual) == len(expected) for idx, actual_val in enumerate(actual): expected_val = expected[idx] - if type(actual_val) == float and math.isnan(actual_val) and type(expected_val) == float and math.isnan(expected_val): + if type(actual_val) == float and math.isnan(actual_val) \ + and type(expected_val) == float and math.isnan(expected_val): continue assert actual_val == expected_val diff --git a/trino/client.py b/trino/client.py index 480e6fd4..e9d460e5 100644 --- a/trino/client.py +++ b/trino/client.py @@ -216,7 +216,7 @@ def __init__(self, id, stats, warnings, info_uri, next_uri, update_type, rows, c self.update_type = update_type self.rows = rows self.columns = columns - self.col_mapping_funcs = [] if columns is None else [self._col_func(column['typeSignature']) for column in columns] + self.col_mapping_funcs = [] if columns is None else [self._col_func(col['typeSignature']) for col in columns] def __repr__(self): return ( @@ -236,18 +236,19 @@ def _col_func(self, column): if col_type == 'array': elt_mapping_func = self._col_func(column['arguments'][0]['value']) - return lambda values : [elt_mapping_func(value) for value in values] + return lambda values: [elt_mapping_func(value) for value in values] elif col_type == 'row': elt_mapping_funcs = [self._col_func(arg['value']['typeSignature']) for arg in column['arguments']] - return lambda values : tuple(elt_mapping_funcs[idx](value) for idx, value in enumerate(values)) + return lambda values: tuple(elt_mapping_funcs[idx](value) for idx, value in enumerate(values)) elif col_type == 'map': key_mapping_func = self._col_func(column['arguments'][0]['value']) value_mapping_func = self._col_func(column['arguments'][1]['value']) - return lambda values : {key_mapping_func(key) : value_mapping_func(value) for key, value in values.items()} + return lambda values: {key_mapping_func(key): value_mapping_func(value) for key, value in values.items()} elif col_type.startswith('decimal'): - return lambda val : Decimal(val) + return lambda val: Decimal(val) elif col_type.startswith('double') or col_type.startswith('real'): - return lambda val : float('inf') if val == 'Infinity' else -float('inf') if val == '-Infinity' else float('nan') if val == 'NaN' else float(val) + return lambda val: float('inf') if val == 'Infinity' else -float('inf') if val == '-Infinity' \ + else float('nan') if val == 'NaN' else float(val) elif col_type.startswith('time'): pattern = "%Y-%m-%d %H:%M:%S" if col_type.startswith('timestamp') else "%H:%M:%S" ms_size, ms_to_trim = self._get_number_of_digits(column) @@ -255,34 +256,41 @@ def _col_func(self, column): pattern += ".%f" if col_type.startswith('timestamp'): - datetime_size = 21 + ms_size - ms_to_trim + dt_size = 21 + ms_size - ms_to_trim if 'with time zone' in col_type: if ms_to_trim > 0: - return lambda val: [datetime.strptime(val[:21] + val[datetime_size:], pattern + ' %z') if tz.startswith('+') or tz.startswith('-') else datetime.strptime(dt[:21] + dt[datetime_size:], pattern).replace(tzinfo=pytz.timezone(tz)) for dt, tz in [val.rsplit(' ', 1)]][0] + return lambda val: \ + [datetime.strptime(val[:21] + val[dt_size:], pattern + ' %z') + if tz.startswith('+') or tz.startswith('-') + else datetime.strptime(dt[:21] + dt[dt_size:], pattern).replace(tzinfo=pytz.timezone(tz)) + for dt, tz in [val.rsplit(' ', 1)]][0] else: - return lambda val: [datetime.strptime(val, pattern + ' %z') if tz.startswith('+') or tz.startswith('-') else datetime.strptime(dt, pattern).replace(tzinfo=pytz.timezone(tz)) for dt, tz in [val.rsplit(' ', 1)]][0] + return lambda val: [datetime.strptime(val, pattern + ' %z') + if tz.startswith('+') or tz.startswith('-') + else datetime.strptime(dt, pattern).replace(tzinfo=pytz.timezone(tz)) + for dt, tz in [val.rsplit(' ', 1)]][0] if ms_to_trim > 0: - return lambda val : datetime.strptime(val[:21] + val[datetime_size:], pattern) + return lambda val: datetime.strptime(val[:21] + val[dt_size:], pattern) else: - return lambda val : datetime.strptime(val, pattern) + return lambda val: datetime.strptime(val, pattern) # Time else: time_size = 9 + ms_size - ms_to_trim if 'with time zone' in col_type: - return lambda val : self._get_time_with_timezome(val, time_size, pattern) + return lambda val: self._get_time_with_timezome(val, time_size, pattern) else: - return lambda val : datetime.strptime(val[:time_size], pattern).time() + return lambda val: datetime.strptime(val[:time_size], pattern).time() elif col_type == 'date': return lambda val : datetime.strptime(val, '%Y-%m-%d').date() elif col_type == 'json': - return lambda val : json.loads(json.loads(val)) + return lambda val: json.loads(json.loads(val)) else: - return lambda val : val + return lambda val: val def _get_time_with_timezome(self, value, time_size, pattern): matches = re.match(r'^(.*)([\+\-])(\d{2}):(\d{2})$', value) @@ -775,7 +783,10 @@ def execute(self, additional_http_headers=None) -> TrinoResult: self._warnings = getattr(status, "warnings", []) if status.next_uri is None: self._finished = True - self._result = TrinoResult(self, rows=status.rows, col_mapping_funcs=status.col_mapping_funcs, experimental_python_types=self._experimental_python_types) + self._result = TrinoResult(self, + rows=status.rows, + col_mapping_funcs=status.col_mapping_funcs, + experimental_python_types=self._experimental_python_types) return self._result def _update_state(self, status): From c438a77e0b681f0dfed903c9efbeea582b436fe5 Mon Sep 17 00:00:00 2001 From: lpoulain Date: Wed, 20 Jul 2022 10:59:01 -0400 Subject: [PATCH 6/9] Code change to fix code check errors --- tests/integration/test_types_integration.py | 24 ++++++++++++++------- trino/client.py | 10 ++++----- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/tests/integration/test_types_integration.py b/tests/integration/test_types_integration.py index b0caac3c..81cef1f7 100644 --- a/tests/integration/test_types_integration.py +++ b/tests/integration/test_types_integration.py @@ -5,6 +5,7 @@ from datetime import timezone, timedelta import trino + @pytest.fixture def trino_connection(run_trino): _, host, port = run_trino @@ -13,6 +14,7 @@ def trino_connection(run_trino): host=host, port=port, user="test", source="test", max_attempts=1 ) + def test_int_types(trino_connection): cur = trino_connection.cursor(experimental_python_types=True) cur.execute(""" @@ -49,6 +51,7 @@ def test_int_types(trino_connection): None ]) + def test_float_types(trino_connection): cur = trino_connection.cursor(experimental_python_types=True) cur.execute(""" @@ -94,6 +97,7 @@ def test_float_types(trino_connection): None ]) + def test_string_types(trino_connection): cur = trino_connection.cursor(experimental_python_types=True) cur.execute(""" @@ -131,6 +135,7 @@ def test_string_types(trino_connection): None ]) + def test_datetime_types(trino_connection): cur = trino_connection.cursor(experimental_python_types=True) cur.execute(""" @@ -187,6 +192,8 @@ def test_datetime_types(trino_connection): """) result = cur.fetchall() + the_tz = datetime.timezone(datetime.timedelta(days=-1, seconds=57600)) + compare_results(result[0], [ datetime.date(2001, 8, 22), None, @@ -226,20 +233,21 @@ def test_datetime_types(trino_connection): None, datetime.datetime(2001, 8, 22, 1, 23, 45, 189123), None, - datetime.datetime(2001, 8, 22, 1, 23, 45, 123000, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + datetime.datetime(2001, 8, 22, 1, 23, 45, 123000, tzinfo=the_tz), None, - datetime.datetime(2001, 8, 22, 1, 23, 45, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + datetime.datetime(2001, 8, 22, 1, 23, 45, tzinfo=the_tz), None, - datetime.datetime(2001, 8, 22, 1, 23, 45, 123000, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + datetime.datetime(2001, 8, 22, 1, 23, 45, 123000, the_tz), None, - datetime.datetime(2001, 8, 22, 1, 23, 45, 123456, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + datetime.datetime(2001, 8, 22, 1, 23, 45, 123456, the_tz), None, - datetime.datetime(2001, 8, 22, 1, 23, 45, 189000, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + datetime.datetime(2001, 8, 22, 1, 23, 45, 189000, the_tz), None, - datetime.datetime(2001, 8, 22, 1, 23, 45, 189123, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), + datetime.datetime(2001, 8, 22, 1, 23, 45, 189123, the_tz), None ]) + def test_misc_types(trino_connection): cur = trino_connection.cursor(experimental_python_types=True) cur.execute(""" @@ -287,7 +295,7 @@ def test_misc_types(trino_connection): None, 'AgwBAIADRAA=', None, - 'AwwAAAAg' + 'A'*2730 + '==', + 'AwwAAAAg' + 'A' * 2730 + '==', None, 'AQgAAAACCwEAgANEAAAgAAABAAAASsQF+7cDRAABAA==', None, @@ -304,7 +312,7 @@ def compare_results(actual, expected): for idx, actual_val in enumerate(actual): expected_val = expected[idx] if type(actual_val) == float and math.isnan(actual_val) \ - and type(expected_val) == float and math.isnan(expected_val): + and type(expected_val) == float and math.isnan(expected_val): continue assert actual_val == expected_val diff --git a/trino/client.py b/trino/client.py index e9d460e5..b97fd79a 100644 --- a/trino/client.py +++ b/trino/client.py @@ -248,7 +248,7 @@ def _col_func(self, column): return lambda val: Decimal(val) elif col_type.startswith('double') or col_type.startswith('real'): return lambda val: float('inf') if val == 'Infinity' else -float('inf') if val == '-Infinity' \ - else float('nan') if val == 'NaN' else float(val) + else float('nan') if val == 'NaN' else float(val) elif col_type.startswith('time'): pattern = "%Y-%m-%d %H:%M:%S" if col_type.startswith('timestamp') else "%H:%M:%S" ms_size, ms_to_trim = self._get_number_of_digits(column) @@ -262,9 +262,9 @@ def _col_func(self, column): if ms_to_trim > 0: return lambda val: \ [datetime.strptime(val[:21] + val[dt_size:], pattern + ' %z') - if tz.startswith('+') or tz.startswith('-') - else datetime.strptime(dt[:21] + dt[dt_size:], pattern).replace(tzinfo=pytz.timezone(tz)) - for dt, tz in [val.rsplit(' ', 1)]][0] + if tz.startswith('+') or tz.startswith('-') + else datetime.strptime(dt[:21] + dt[dt_size:], pattern).replace(tzinfo=pytz.timezone(tz)) + for dt, tz in [val.rsplit(' ', 1)]][0] else: return lambda val: [datetime.strptime(val, pattern + ' %z') if tz.startswith('+') or tz.startswith('-') @@ -286,7 +286,7 @@ def _col_func(self, column): return lambda val: datetime.strptime(val[:time_size], pattern).time() elif col_type == 'date': - return lambda val : datetime.strptime(val, '%Y-%m-%d').date() + return lambda val: datetime.strptime(val, '%Y-%m-%d').date() elif col_type == 'json': return lambda val: json.loads(json.loads(val)) else: From 379a29266eb5a31b980bf91e2e809605466db9bf Mon Sep 17 00:00:00 2001 From: lpoulain Date: Wed, 20 Jul 2022 15:57:17 -0400 Subject: [PATCH 7/9] Fix last failing tests --- tests/integration/test_types_integration.py | 2 -- trino/client.py | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_types_integration.py b/tests/integration/test_types_integration.py index 81cef1f7..fcc89cbd 100644 --- a/tests/integration/test_types_integration.py +++ b/tests/integration/test_types_integration.py @@ -271,7 +271,6 @@ def test_misc_types(trino_connection): , cast(null AS P4HyperLogLog) AS col_p4hll_null , make_set_digest(1) AS col_setdigest , cast(null AS SetDigest) AS col_setdigest_null - , qdigest_agg(1) AS col_qdigest , cast(null AS QDigest(BIGINT)) AS col_qdigest_null , tdigest_agg(1) AS col_tdigest , cast(null AS TDigest) AS col_tdigest_null @@ -297,7 +296,6 @@ def test_misc_types(trino_connection): None, 'AwwAAAAg' + 'A' * 2730 + '==', None, - 'AQgAAAACCwEAgANEAAAgAAABAAAASsQF+7cDRAABAA==', None, 'AHsUrkfheoQ/AAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAPA/AQAAAAAAAIA=', None, diff --git a/trino/client.py b/trino/client.py index b97fd79a..da3a9f77 100644 --- a/trino/client.py +++ b/trino/client.py @@ -247,8 +247,10 @@ def _col_func(self, column): elif col_type.startswith('decimal'): return lambda val: Decimal(val) elif col_type.startswith('double') or col_type.startswith('real'): - return lambda val: float('inf') if val == 'Infinity' else -float('inf') if val == '-Infinity' \ - else float('nan') if val == 'NaN' else float(val) + return lambda val: float('inf') if val == 'Infinity' \ + else -float('inf') if val == '-Infinity' \ + else float('nan') if val == 'NaN' \ + else float(val) elif col_type.startswith('time'): pattern = "%Y-%m-%d %H:%M:%S" if col_type.startswith('timestamp') else "%H:%M:%S" ms_size, ms_to_trim = self._get_number_of_digits(column) From 080714994ab44f0522c8ab81b62d6330bbc73eae Mon Sep 17 00:00:00 2001 From: lpoulain Date: Wed, 20 Jul 2022 16:27:18 -0400 Subject: [PATCH 8/9] Fix last failing tests --- tests/integration/test_types_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_types_integration.py b/tests/integration/test_types_integration.py index fcc89cbd..54a9d8af 100644 --- a/tests/integration/test_types_integration.py +++ b/tests/integration/test_types_integration.py @@ -296,8 +296,8 @@ def test_misc_types(trino_connection): None, 'AwwAAAAg' + 'A' * 2730 + '==', None, + 'AQgAAAACCwEAgANEAAAgAAABAAAASsQF+7cDRAABAA==', None, - 'AHsUrkfheoQ/AAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAPA/AQAAAAAAAIA=', None, 'AAAAAAAAAPA/AAAAAAAA8D8AAAAAAABZQAAAAAAAAPA/AQAAAAAAAAAAAPA/AAAAAAAA8D8=', None From 6ef363d5647dcffd47669fc6bb1d9a74675c8e94 Mon Sep 17 00:00:00 2001 From: lpoulain Date: Wed, 20 Jul 2022 18:02:08 -0400 Subject: [PATCH 9/9] Fix wrong type declared in functions --- trino/client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/trino/client.py b/trino/client.py index da3a9f77..76b5559b 100644 --- a/trino/client.py +++ b/trino/client.py @@ -695,7 +695,7 @@ def _map_row(cls, experimental_python_types, row, col_mapping_func): return cls._map_to_python_types(cls, row, col_mapping_func) @classmethod - def _map_to_python_type(cls, item: Tuple[Any, Dict]) -> Any: + def _map_to_python_type(cls, item: Tuple[Any, Any]) -> Any: (value, col_mapping_func) = item if value is None: @@ -707,8 +707,8 @@ def _map_to_python_type(cls, item: Tuple[Any, Dict]) -> Any: error_str = f"Could not convert '{value}' into the associated python type" raise trino.exceptions.TrinoDataError(error_str) from e - def _map_to_python_types(self, row: List[Any], columns) -> List[Any]: - return list(map(self._map_to_python_type, zip(row, columns))) + def _map_to_python_types(self, row: List[Any], col_mapping_func) -> List[Any]: + return list(map(self._map_to_python_type, zip(row, col_mapping_func))) class TrinoQuery(object): @@ -797,7 +797,7 @@ def _update_state(self, status): if status.columns: self._columns = status.columns - def fetch(self) -> List[List[Any]]: + def fetch(self) -> Tuple[List[List[Any]], List[Any]]: """Continue fetching data for the current query_id""" response = self._request.get(self._request.next_uri) status = self._request.process(response)