Skip to content

Commit

Permalink
Add tests for iceberg table structured types metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-yixie committed Mar 19, 2024
1 parent 23eda6e commit 6f51219
Showing 1 changed file with 78 additions and 1 deletion.
79 changes: 78 additions & 1 deletion test/integ/test_structured_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
from textwrap import dedent

import pytest
try:
from snowflake.connector.util_text import random_string
except ImportError:
from ..randomize import random_string

pytestmark = pytest.mark.skipolddriver # old test driver tests won't run this module

Expand Down Expand Up @@ -45,7 +49,7 @@ def test_structured_map_types(conn_cnx):
cur = cnx.cursor()
sql = dedent(
"""select
{'a': 1}::map(string, variant),
{'a': 1}::map(string, int),
{'a': 1.1::float}::map(string, float),
{'a': 'b'}::map(string, string),
{'a': current_timestamp()}::map(string, timestamp),
Expand All @@ -64,3 +68,76 @@ def test_structured_map_types(conn_cnx):
assert metadata.type_code == 9 # same as a regular object
for metadata in cur.describe(sql):
assert metadata.type_code == 9


def test_structured_array_types_iceberg(conn_cnx):
with conn_cnx() as cnx:
cur = cnx.cursor()

table_name = f"iceberg_test_array_{random_string(5)}"
# Geography and geometry are not supported in an array
# [TO_GEOGRAPHY('POINT(-122.35 37.55)'), TO_GEOGRAPHY('POINT(-123.35 37.55)')]::array(GEOGRAPHY),
# [TO_GEOMETRY('POINT(1820.12 890.56)'), TO_GEOMETRY('POINT(1820.12 890.56)')]::array(GEOMETRY),
cur.execute(f"""create iceberg table if not exists {table_name} (
c1 array(int),
c2 array(float),
-- c3 array(string not null),
c4 array(timestamp),
c5 array(timestamp_ltz),
-- c6 array(timestamp_tz),
c7 array(timestamp_ntz),
c8 array(date),
c9 array(time),
c10 array(boolean)
-- c11 array(variant not null),
-- c12 array(object)
)
CATALOG = 'SNOWFLAKE'
EXTERNAL_VOLUME = 'python_connector_iceberg_exvol'
BASE_LOCATION = 'python_connector_merge_gate';
""")
sql = f"select * from {table_name}"
try:
cur.execute(sql)
for metadata in cur.description:
assert metadata.type_code == 10 # same as a regular array
for metadata in cur.describe(sql):
assert metadata.type_code == 10
finally:
cur.execute(f"drop iceberg table if exists {table_name}")


def test_structured_map_types_iceberg(conn_cnx):
with conn_cnx() as cnx:
cur = cnx.cursor()
table_name = f"iceberg_test_array_{random_string(5)}"
# Geography and geometry are not supported in an array
# [TO_GEOGRAPHY('POINT(-122.35 37.55)'), TO_GEOGRAPHY('POINT(-123.35 37.55)')]::array(GEOGRAPHY),
# [TO_GEOMETRY('POINT(1820.12 890.56)'), TO_GEOMETRY('POINT(1820.12 890.56)')]::array(GEOMETRY),
cur.execute(f"""create iceberg table if not exists {table_name} (
c1 map(string, int),
c2 map(string, float),
-- c3 map(string, string not null),
c4 map(string, timestamp),
c5 map(string, timestamp_ltz),
c6 map(string, timestamp_ntz),
-- c7 map(string, timestamp_tz),
c8 map(string, date),
c9 map(string, time),
c10 map(string, boolean)
-- c11 map(string, variant not null),
-- c12 map(string, object)
)
CATALOG = 'SNOWFLAKE'
EXTERNAL_VOLUME = 'python_connector_iceberg_exvol'
BASE_LOCATION = 'python_connector_merge_gate';
""")
sql = f"select * from {table_name}"
try:
cur.execute(sql)
for metadata in cur.description:
assert metadata.type_code == 9 # same as a regular object
for metadata in cur.describe(sql):
assert metadata.type_code == 9
finally:
cur.execute(f"drop iceberg table if exists {table_name}")

0 comments on commit 6f51219

Please sign in to comment.