From 18c296e4723f78e9718c47c1540f456dd58b8ff5 Mon Sep 17 00:00:00 2001 From: Jorge Vasquez Rojas Date: Mon, 25 Nov 2024 06:52:40 -0600 Subject: [PATCH 1/3] Fix import BOOLEAN error --- DESCRIPTION.md | 1 + src/snowflake/sqlalchemy/snowdialect.py | 1 + tests/test_imports.py | 26 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 tests/test_imports.py diff --git a/DESCRIPTION.md b/DESCRIPTION.md index 82ddebc9..bbb33fb8 100644 --- a/DESCRIPTION.md +++ b/DESCRIPTION.md @@ -11,6 +11,7 @@ Source code is also available at: - (Unreleased) - Add support for partition by to copy into + - Fix BOOLEAN type not found in snowdialect - v1.7.0(November 22, 2024) diff --git a/src/snowflake/sqlalchemy/snowdialect.py b/src/snowflake/sqlalchemy/snowdialect.py index f9e2e4c8..9858f835 100644 --- a/src/snowflake/sqlalchemy/snowdialect.py +++ b/src/snowflake/sqlalchemy/snowdialect.py @@ -39,6 +39,7 @@ _CUSTOM_Float, _CUSTOM_Time, ) +from .parser.custom_type_parser import * # noqa from .parser.custom_type_parser import ischema_names, parse_type from .sql.custom_schema.custom_table_prefix import CustomTablePrefix from .util import ( diff --git a/tests/test_imports.py b/tests/test_imports.py new file mode 100644 index 00000000..474ab62c --- /dev/null +++ b/tests/test_imports.py @@ -0,0 +1,26 @@ +# +# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved. +# + +import importlib +import inspect + + +def get_classes_from_module(module_name): + """Returns a set of class names from a given module.""" + try: + module = importlib.import_module(module_name) + members = inspect.getmembers(module) + return {name for name, obj in members if inspect.isclass(obj)} + + except ImportError: + print(f"Module '{module_name}' could not be imported.") + return set() + + +def test_types_in_snowdialect(): + classes_a = get_classes_from_module( + "snowflake.sqlalchemy.parser.custom_type_parser" + ) + classes_b = get_classes_from_module("snowflake.sqlalchemy.snowdialect") + return classes_a.issubset(classes_b), classes_a - classes_b From 2fc990a09188137f2cd244f85b68bd15bfec0c6b Mon Sep 17 00:00:00 2001 From: Jorge Vasquez Rojas Date: Mon, 25 Nov 2024 07:09:52 -0600 Subject: [PATCH 2/3] Update imports --- src/snowflake/sqlalchemy/snowdialect.py | 1 + tests/test_imports.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/snowflake/sqlalchemy/snowdialect.py b/src/snowflake/sqlalchemy/snowdialect.py index 9858f835..e6baadf7 100644 --- a/src/snowflake/sqlalchemy/snowdialect.py +++ b/src/snowflake/sqlalchemy/snowdialect.py @@ -40,6 +40,7 @@ _CUSTOM_Time, ) from .parser.custom_type_parser import * # noqa +from .parser.custom_type_parser import _CUSTOM_DECIMAL # noqa from .parser.custom_type_parser import ischema_names, parse_type from .sql.custom_schema.custom_table_prefix import CustomTablePrefix from .util import ( diff --git a/tests/test_imports.py b/tests/test_imports.py index 474ab62c..802cf9e2 100644 --- a/tests/test_imports.py +++ b/tests/test_imports.py @@ -23,4 +23,4 @@ def test_types_in_snowdialect(): "snowflake.sqlalchemy.parser.custom_type_parser" ) classes_b = get_classes_from_module("snowflake.sqlalchemy.snowdialect") - return classes_a.issubset(classes_b), classes_a - classes_b + assert classes_a.issubset(classes_b), str(classes_a - classes_b) From ac4f12ce7b8270723d1ffaf9dee1d9e460613bde Mon Sep 17 00:00:00 2001 From: Jorge Vasquez Rojas Date: Mon, 25 Nov 2024 08:57:57 -0600 Subject: [PATCH 3/3] Add test for explicit imports --- tests/test_imports.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/test_imports.py b/tests/test_imports.py index 802cf9e2..0cfe5931 100644 --- a/tests/test_imports.py +++ b/tests/test_imports.py @@ -5,6 +5,8 @@ import importlib import inspect +import pytest + def get_classes_from_module(module_name): """Returns a set of class names from a given module.""" @@ -24,3 +26,39 @@ def test_types_in_snowdialect(): ) classes_b = get_classes_from_module("snowflake.sqlalchemy.snowdialect") assert classes_a.issubset(classes_b), str(classes_a - classes_b) + + +@pytest.mark.parametrize( + "type_class_name", + [ + "BIGINT", + "BINARY", + "BOOLEAN", + "CHAR", + "DATE", + "DATETIME", + "DECIMAL", + "FLOAT", + "INTEGER", + "REAL", + "SMALLINT", + "TIME", + "TIMESTAMP", + "VARCHAR", + "NullType", + "_CUSTOM_DECIMAL", + "ARRAY", + "DOUBLE", + "GEOGRAPHY", + "GEOMETRY", + "MAP", + "OBJECT", + "TIMESTAMP_LTZ", + "TIMESTAMP_NTZ", + "TIMESTAMP_TZ", + "VARIANT", + ], +) +def test_snowflake_data_types_instance(type_class_name): + classes_b = get_classes_from_module("snowflake.sqlalchemy.snowdialect") + assert type_class_name in classes_b, type_class_name