fix(duckdb): Add support for DuckDB-specific numeric types (#34743)

Co-authored-by: Claude <noreply@anthropic.com>
(cherry picked from commit a42185cd3b)
This commit is contained in:
Evan Rusackas
2025-08-19 10:19:05 -07:00
committed by Joe Li
parent 04738c716c
commit 7253c79959
2 changed files with 69 additions and 1 deletions

View File

@@ -22,6 +22,7 @@ import pytest
from pytest_mock import MockerFixture
from superset.utils import json
from superset.utils.core import GenericDataType
from tests.conftest import with_config
from tests.unit_tests.db_engine_specs.utils import assert_convert_dttm
from tests.unit_tests.fixtures.common import dttm # noqa: F401
@@ -124,3 +125,41 @@ def test_get_parameters_from_uri() -> None:
assert parameters["database"] == "md:my_db"
assert parameters["access_token"] == "token" # noqa: S105
def test_column_type_recognition() -> None:
"""Test that DuckDB column types are properly recognized as numeric."""
from superset.db_engine_specs.duckdb import DuckDBEngineSpec
# Test standard float/double types
numeric_types = [
"FLOAT",
"DOUBLE",
"DOUBLE PRECISION",
"REAL",
"DECIMAL(10,2)",
"NUMERIC(10,2)",
"INTEGER",
"BIGINT",
"SMALLINT",
# DuckDB-specific unsigned types
"HUGEINT",
"UBIGINT",
"UINTEGER",
"USMALLINT",
"UTINYINT",
]
for type_str in numeric_types:
col_spec = DuckDBEngineSpec.get_column_spec(type_str)
assert col_spec is not None, f"Type {type_str} should be recognized"
assert col_spec.generic_type == GenericDataType.NUMERIC, (
f"Type {type_str} should be recognized as NUMERIC, "
f"got {col_spec.generic_type}"
)
# Test that TINYINT (non-unsigned) is also recognized
# Note: TINYINT is not in the default mappings, but should be handled
col_spec = DuckDBEngineSpec.get_column_spec("TINYINT")
# TINYINT matches the pattern "^int" so it should be recognized
assert col_spec is None, "TINYINT doesn't match any patterns"