|
| 1 | +#!/usr/bin/env python |
| 2 | +# |
| 3 | +# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved. |
| 4 | +# |
| 5 | +from __future__ import annotations |
| 6 | + |
| 7 | +from textwrap import dedent |
| 8 | + |
| 9 | +import pytest |
| 10 | + |
| 11 | +pytestmark = pytest.mark.skipolddriver # old test driver tests won't run this module |
| 12 | + |
| 13 | + |
| 14 | +def test_structured_array_types(conn_cnx): |
| 15 | + with conn_cnx() as cnx: |
| 16 | + cur = cnx.cursor() |
| 17 | + sql = dedent( |
| 18 | + """select |
| 19 | + [1, 2]::array(int), |
| 20 | + [1.1::float, 1.2::float]::array(float), |
| 21 | + ['a', 'b']::array(string not null), |
| 22 | + [current_timestamp(), current_timestamp()]::array(timestamp), |
| 23 | + [current_timestamp()::timestamp_ltz, current_timestamp()::timestamp_ltz]::array(timestamp_ltz), |
| 24 | + [current_timestamp()::timestamp_tz, current_timestamp()::timestamp_tz]::array(timestamp_tz), |
| 25 | + [current_timestamp()::timestamp_ntz, current_timestamp()::timestamp_ntz]::array(timestamp_ntz), |
| 26 | + [current_date(), current_date()]::array(date), |
| 27 | + [current_time(), current_time()]::array(time), |
| 28 | + [True, False]::array(boolean), |
| 29 | + [1::variant, 'b'::variant]::array(variant not null), |
| 30 | + [{'a': 'b'}, {'c': 1}]::array(object) |
| 31 | + """ |
| 32 | + ) |
| 33 | + # Geography and geometry are not supported in an array |
| 34 | + # [TO_GEOGRAPHY('POINT(-122.35 37.55)'), TO_GEOGRAPHY('POINT(-123.35 37.55)')]::array(GEOGRAPHY), |
| 35 | + # [TO_GEOMETRY('POINT(1820.12 890.56)'), TO_GEOMETRY('POINT(1820.12 890.56)')]::array(GEOMETRY), |
| 36 | + cur.execute(sql) |
| 37 | + for metadata in cur.description: |
| 38 | + assert metadata.type_code == 10 # same as a regular array |
| 39 | + for metadata in cur.describe(sql): |
| 40 | + assert metadata.type_code == 10 |
| 41 | + |
| 42 | + |
| 43 | +def test_structured_map_types(conn_cnx): |
| 44 | + with conn_cnx() as cnx: |
| 45 | + cur = cnx.cursor() |
| 46 | + sql = dedent( |
| 47 | + """select |
| 48 | + {'a': 1}::map(string, variant), |
| 49 | + {'a': 1.1::float}::map(string, float), |
| 50 | + {'a': 'b'}::map(string, string), |
| 51 | + {'a': current_timestamp()}::map(string, timestamp), |
| 52 | + {'a': current_timestamp()::timestamp_ltz}::map(string, timestamp_ltz), |
| 53 | + {'a': current_timestamp()::timestamp_ntz}::map(string, timestamp_ntz), |
| 54 | + {'a': current_timestamp()::timestamp_tz}::map(string, timestamp_tz), |
| 55 | + {'a': current_date()}::map(string, date), |
| 56 | + {'a': current_time()}::map(string, time), |
| 57 | + {'a': False}::map(string, boolean), |
| 58 | + {'a': 'b'::variant}::map(string, variant not null), |
| 59 | + {'a': {'c': 1}}::map(string, object) |
| 60 | + """ |
| 61 | + ) |
| 62 | + cur.execute(sql) |
| 63 | + for metadata in cur.description: |
| 64 | + assert metadata.type_code == 9 # same as a regular object |
| 65 | + for metadata in cur.describe(sql): |
| 66 | + assert metadata.type_code == 9 |
0 commit comments