Skip to content

Commit 6a9ac4d

Browse files
Add structured type support for hybrid tables (#572)
1 parent ff2a785 commit 6a9ac4d

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

DESCRIPTION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Source code is also available at:
1212
- Fix support for SqlAlchemy ARRAY.
1313
- Fix return value of snowflake get_table_names.
1414
- Fix incorrect quoting of identifiers with `_` as initial character.
15+
- Fix ARRAY type not supported in HYBRID tables.
1516
- Added `force_div_is_floordiv` flag to override `div_is_floordiv` new default value `False` in `SnowflakeDialect`.
1617
- With the flag in `False`, the `/` division operator will be treated as a float division and `//` as a floor division.
1718
- This flag is added to maintain backward compatibility with the previous behavior of Snowflake Dialect division.

src/snowflake/sqlalchemy/sql/custom_schema/hybrid_table.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class HybridTable(CustomTableBase):
3232

3333
__table_prefixes__ = [CustomTablePrefix.HYBRID]
3434
_enforce_primary_keys: bool = True
35+
_support_structured_types = True
3536

3637
def __init__(
3738
self,

tests/custom_tables/__snapshots__/test_compile_hybrid_table.ambr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
# name: test_compile_hybrid_table_orm
66
'CREATE HYBRID TABLE test_hybrid_table_orm (\tid INTEGER NOT NULL AUTOINCREMENT, \tname VARCHAR, \tPRIMARY KEY (id))'
77
# ---
8+
# name: test_compile_hybrid_table_with_array
9+
'CREATE HYBRID TABLE test_hybrid_table (\tid INTEGER NOT NULL AUTOINCREMENT, \tname VARCHAR, \tgeom GEOMETRY, \tarray ARRAY, \tPRIMARY KEY (id))'
10+
# ---

tests/custom_tables/test_compile_hybrid_table.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#
22
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
33
#
4-
import pytest
4+
55
from sqlalchemy import Column, Integer, MetaData, String
66
from sqlalchemy.orm import declarative_base
77
from sqlalchemy.sql.ddl import CreateTable
88

9-
from snowflake.sqlalchemy import GEOMETRY, HybridTable
9+
from snowflake.sqlalchemy import ARRAY, GEOMETRY, HybridTable
1010

1111

12-
@pytest.mark.aws
1312
def test_compile_hybrid_table(sql_compiler, snapshot):
1413
metadata = MetaData()
1514
table_name = "test_hybrid_table"
@@ -28,7 +27,25 @@ def test_compile_hybrid_table(sql_compiler, snapshot):
2827
assert actual == snapshot
2928

3029

31-
@pytest.mark.aws
30+
def test_compile_hybrid_table_with_array(sql_compiler, snapshot):
31+
metadata = MetaData()
32+
table_name = "test_hybrid_table"
33+
test_geometry = HybridTable(
34+
table_name,
35+
metadata,
36+
Column("id", Integer, primary_key=True),
37+
Column("name", String),
38+
Column("geom", GEOMETRY),
39+
Column("array", ARRAY),
40+
)
41+
42+
value = CreateTable(test_geometry)
43+
44+
actual = sql_compiler(value)
45+
46+
assert actual == snapshot
47+
48+
3249
def test_compile_hybrid_table_orm(sql_compiler, snapshot):
3350
Base = declarative_base()
3451

0 commit comments

Comments
 (0)