Skip to content

Commit

Permalink
Add test to test primary_key reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jvasquezrojas committed Nov 12, 2024
1 parent b0e23a7 commit 4544024
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tests/__snapshots__/test_structured_datatypes.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
])
# ---
# name: test_reflect_structured_data_types[MAP(NUMBER(10, 0), MAP(NUMBER(10, 0), VARCHAR))]
"CREATE ICEBERG TABLE test_reflect_st_types (\tid DECIMAL(38, 0), \tmap_id MAP(DECIMAL(10, 0), MAP(DECIMAL(10, 0), VARCHAR(16777216))) NOT NULL)\tCATALOG = 'SNOWFLAKE'"
'CREATE ICEBERG TABLE test_reflect_st_types (\tid DECIMAL(38, 0) NOT NULL, \tmap_id MAP(DECIMAL(10, 0), MAP(DECIMAL(10, 0), VARCHAR(16777216))) NOT NULL, \tCONSTRAINT "SYS_CONSTRAINT_98dc7df8-0a51-4b69-a974-55c656fb6543" PRIMARY KEY (id))\tCATALOG = \'SNOWFLAKE\''
# ---
# name: test_reflect_structured_data_types[MAP(NUMBER(10, 0), VARCHAR)]
"CREATE ICEBERG TABLE test_reflect_st_types (\tid DECIMAL(38, 0), \tmap_id MAP(DECIMAL(10, 0), VARCHAR(16777216)) NOT NULL)\tCATALOG = 'SNOWFLAKE'"
'CREATE ICEBERG TABLE test_reflect_st_types (\tid DECIMAL(38, 0) NOT NULL, \tmap_id MAP(DECIMAL(10, 0), VARCHAR(16777216)) NOT NULL, \tCONSTRAINT "SYS_CONSTRAINT_2b003f01-6ab6-4c30-a12d-191973a1cf14" PRIMARY KEY (id))\tCATALOG = \'SNOWFLAKE\''
# ---
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
# serializer version: 1
# name: test_inspect_snowflake_table
list([
dict({
'autoincrement': False,
'comment': None,
'default': None,
'name': 'id',
'nullable': False,
'primary_key': True,
'type': _CUSTOM_DECIMAL(precision=38, scale=0),
}),
dict({
'autoincrement': False,
'comment': None,
'default': None,
'name': 'name',
'nullable': True,
'primary_key': False,
'type': VARCHAR(length=16777216),
}),
])
# ---
# name: test_simple_reflection_of_table_as_snowflake_table
'CREATE TABLE test_snowflake_table_reflection (\tid DECIMAL(38, 0) NOT NULL, \tname VARCHAR(16777216), \tCONSTRAINT demo_name PRIMARY KEY (id))'
# ---
Expand Down
25 changes: 24 additions & 1 deletion tests/custom_tables/test_reflect_snowflake_table.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
#
from sqlalchemy import MetaData, Table
from sqlalchemy import MetaData, Table, inspect
from sqlalchemy.sql.ddl import CreateTable

from snowflake.sqlalchemy import SnowflakeTable
Expand Down Expand Up @@ -67,3 +67,26 @@ def test_simple_reflection_of_table_as_snowflake_table(

finally:
metadata.drop_all(engine_testaccount)


def test_inspect_snowflake_table(
engine_testaccount, db_parameters, sql_compiler, snapshot
):
metadata = MetaData()
table_name = "test_snowflake_table_inspect"

create_table_sql = f"""
CREATE TABLE {table_name} (id INT primary key, name VARCHAR);
"""

with engine_testaccount.connect() as connection:
connection.exec_driver_sql(create_table_sql)

try:
with engine_testaccount.connect() as conn:
insp = inspect(conn)
table = insp.get_columns(table_name)
assert table == snapshot

finally:
metadata.drop_all(engine_testaccount)
2 changes: 1 addition & 1 deletion tests/test_structured_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def test_reflect_structured_data_types(
table_name = "test_reflect_st_types"
create_table_sql = f"""
CREATE OR REPLACE ICEBERG TABLE {table_name} (
id number(38,0),
id number(38,0) primary key,
map_id {structured_type})
CATALOG = 'SNOWFLAKE'
EXTERNAL_VOLUME = '{external_volume}'
Expand Down

0 comments on commit 4544024

Please sign in to comment.