fix(redshift): normalize table names to lowercase for CSV uploads (#37019)

This commit is contained in:
Jean Massucatto
2026-01-23 17:40:38 -03:00
committed by GitHub
parent 5747fb1e85
commit e8363cf606
4 changed files with 74 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ from typing import Optional
import pytest
from superset.db_engine_specs.redshift import RedshiftEngineSpec
from tests.unit_tests.db_engine_specs.utils import assert_convert_dttm
from tests.unit_tests.fixtures.common import dttm # noqa: F401
@@ -49,3 +50,32 @@ def test_convert_dttm(
)
assert_convert_dttm(spec, target_type, expected_result, dttm)
@pytest.mark.parametrize(
"table_name,schema_name,expected_table,expected_schema",
[
("BPO_mytest_2", "MySchema", "bpo_mytest_2", "myschema"),
("MY_TABLE", None, "my_table", None),
("already_lower", "lower_schema", "already_lower", "lower_schema"),
],
)
def test_normalize_table_name_for_upload(
table_name: str,
schema_name: Optional[str],
expected_table: str,
expected_schema: Optional[str],
) -> None:
"""
Test that table and schema names are normalized to lowercase for Redshift.
Redshift folds unquoted identifiers to lowercase, so we need to normalize
table names to ensure consistent behavior when checking table existence
and performing replace operations.
"""
normalized_table, normalized_schema = (
RedshiftEngineSpec.normalize_table_name_for_upload(table_name, schema_name)
)
assert normalized_table == expected_table
assert normalized_schema == expected_schema