Skip to content

Commit ff2a785

Browse files
SNOW-1871582 Fix support for SA array (#568)
* Fix drop support for SA array * Update DESCRIPTION.md
1 parent 75376ff commit ff2a785

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

DESCRIPTION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Source code is also available at:
99

1010
# Release Notes
1111
- (Unreleased)
12+
- Fix support for SqlAlchemy ARRAY.
1213
- Fix return value of snowflake get_table_names.
1314
- Fix incorrect quoting of identifiers with `_` as initial character.
1415
- Added `force_div_is_floordiv` flag to override `div_is_floordiv` new default value `False` in `SnowflakeDialect`.

src/snowflake/sqlalchemy/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,9 @@ def visit_MAP(self, type_, **kw):
11331133
)
11341134

11351135
def visit_ARRAY(self, type_, **kw):
1136+
return "ARRAY"
1137+
1138+
def visit_SNOWFLAKE_ARRAY(self, type_, **kw):
11361139
if type_.is_semi_structured:
11371140
return "ARRAY"
11381141
not_null = f" {NOT_NULL}" if type_.not_null else ""

src/snowflake/sqlalchemy/custom_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __repr__(self):
8383

8484

8585
class ARRAY(StructuredType):
86-
__visit_name__ = "ARRAY"
86+
__visit_name__ = "SNOWFLAKE_ARRAY"
8787

8888
def __init__(
8989
self,

tests/__snapshots__/test_structured_datatypes.ambr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# name: test_compile_table_with_double_map
66
'CREATE TABLE clustered_user (\t"Id" INTEGER NOT NULL AUTOINCREMENT, \tname MAP(DECIMAL, MAP(DECIMAL, VARCHAR)), \tPRIMARY KEY ("Id"))'
77
# ---
8+
# name: test_compile_table_with_sqlalchemy_array
9+
'CREATE TABLE clustered_user (\t"Id" INTEGER NOT NULL AUTOINCREMENT, \tname ARRAY, \tPRIMARY KEY ("Id"))'
10+
# ---
811
# name: test_compile_table_with_structured_data_type[structured_type0]
912
'CREATE TABLE clustered_user (\t"Id" INTEGER NOT NULL AUTOINCREMENT, \tname MAP(DECIMAL(10, 0), MAP(DECIMAL(10, 0), VARCHAR(16777216))), \tPRIMARY KEY ("Id"))'
1013
# ---

tests/test_structured_datatypes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
33
#
44
import pytest
5+
import sqlalchemy as sa
56
from sqlalchemy import (
67
Column,
78
Integer,
@@ -47,6 +48,20 @@ def test_compile_table_with_structured_data_type(
4748
assert sql_compiler(create_table) == snapshot
4849

4950

51+
def test_compile_table_with_sqlalchemy_array(sql_compiler, snapshot):
52+
metadata = MetaData()
53+
user_table = Table(
54+
"clustered_user",
55+
metadata,
56+
Column("Id", Integer, primary_key=True),
57+
Column("name", sa.ARRAY(sa.String)),
58+
)
59+
60+
create_table = CreateTable(user_table)
61+
62+
assert sql_compiler(create_table) == snapshot
63+
64+
5065
@pytest.mark.requires_external_volume
5166
def test_insert_map(engine_testaccount, external_volume, base_location, snapshot):
5267
metadata = MetaData()

0 commit comments

Comments
 (0)