Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add structured type support for hybrid tables #572

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Source code is also available at:
- Fix support for SqlAlchemy ARRAY.
- Fix return value of snowflake get_table_names.
- Fix incorrect quoting of identifiers with `_` as initial character.
- Fix ARRAY type not supported in HYBRID tables.
- Added `force_div_is_floordiv` flag to override `div_is_floordiv` new default value `False` in `SnowflakeDialect`.
- With the flag in `False`, the `/` division operator will be treated as a float division and `//` as a floor division.
- This flag is added to maintain backward compatibility with the previous behavior of Snowflake Dialect division.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class HybridTable(CustomTableBase):

__table_prefixes__ = [CustomTablePrefix.HYBRID]
_enforce_primary_keys: bool = True
_support_structured_types = True

def __init__(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
# name: test_compile_hybrid_table_orm
'CREATE HYBRID TABLE test_hybrid_table_orm (\tid INTEGER NOT NULL AUTOINCREMENT, \tname VARCHAR, \tPRIMARY KEY (id))'
# ---
# name: test_compile_hybrid_table_with_array
'CREATE HYBRID TABLE test_hybrid_table (\tid INTEGER NOT NULL AUTOINCREMENT, \tname VARCHAR, \tgeom GEOMETRY, \tarray ARRAY, \tPRIMARY KEY (id))'
# ---
25 changes: 21 additions & 4 deletions tests/custom_tables/test_compile_hybrid_table.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
#
import pytest

from sqlalchemy import Column, Integer, MetaData, String
from sqlalchemy.orm import declarative_base
from sqlalchemy.sql.ddl import CreateTable

from snowflake.sqlalchemy import GEOMETRY, HybridTable
from snowflake.sqlalchemy import ARRAY, GEOMETRY, HybridTable


@pytest.mark.aws
def test_compile_hybrid_table(sql_compiler, snapshot):
metadata = MetaData()
table_name = "test_hybrid_table"
Expand All @@ -28,7 +27,25 @@ def test_compile_hybrid_table(sql_compiler, snapshot):
assert actual == snapshot


@pytest.mark.aws
def test_compile_hybrid_table_with_array(sql_compiler, snapshot):
metadata = MetaData()
table_name = "test_hybrid_table"
test_geometry = HybridTable(
table_name,
metadata,
Column("id", Integer, primary_key=True),
Column("name", String),
Column("geom", GEOMETRY),
Column("array", ARRAY),
)

value = CreateTable(test_geometry)

actual = sql_compiler(value)

assert actual == snapshot


def test_compile_hybrid_table_orm(sql_compiler, snapshot):
Base = declarative_base()

Expand Down
Loading