You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2023/06/21 19:35:56 UTC
[superset] branch master updated: fix(oracle): denormalize column names where applicable (#24471)
This is an automated email from the ASF dual-hosted git repository.
villebro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new ea89949118 fix(oracle): denormalize column names where applicable (#24471)
ea89949118 is described below
commit ea89949118a95b75eb47613280d31624c3cee618
Author: Ville Brofeldt <33...@users.noreply.github.com>
AuthorDate: Wed Jun 21 22:35:46 2023 +0300
fix(oracle): denormalize column names where applicable (#24471)
---
superset/connectors/sqla/utils.py | 3 +++
superset/db_engine_specs/base.py | 10 ++++++++++
tests/unit_tests/db_engine_specs/test_mssql.py | 14 ++++++++++++++
tests/unit_tests/db_engine_specs/test_oracle.py | 14 ++++++++++++++
4 files changed, 41 insertions(+)
diff --git a/superset/connectors/sqla/utils.py b/superset/connectors/sqla/utils.py
index f761b2dca1..82d8f90f22 100644
--- a/superset/connectors/sqla/utils.py
+++ b/superset/connectors/sqla/utils.py
@@ -67,6 +67,7 @@ def get_physical_table_metadata(
for col in cols:
try:
if isinstance(col["type"], TypeEngine):
+ name = db_engine_spec.denormalize_name(db_dialect, col["column_name"])
db_type = db_engine_spec.column_datatype_to_string(
col["type"], db_dialect
)
@@ -75,6 +76,8 @@ def get_physical_table_metadata(
)
col.update(
{
+ "name": name,
+ "column_name": name,
"type": db_type,
"type_generic": type_spec.generic_type if type_spec else None,
"is_dttm": type_spec.is_dttm if type_spec else None,
diff --git a/superset/db_engine_specs/base.py b/superset/db_engine_specs/base.py
index 766f17e7e1..f4b75c50b1 100644
--- a/superset/db_engine_specs/base.py
+++ b/superset/db_engine_specs/base.py
@@ -1852,6 +1852,16 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
).intersection(sqlalchemy_uri.query):
raise ValueError(f"Forbidden query parameter(s): {existing_disallowed}")
+ @classmethod
+ def denormalize_name(cls, dialect: Dialect, name: str) -> str:
+ if (
+ hasattr(dialect, "requires_name_normalize")
+ and dialect.requires_name_normalize
+ ):
+ return dialect.denormalize_name(name)
+
+ return name
+
# schema for adding a database by providing parameters instead of the
# full SQLAlchemy URI
diff --git a/tests/unit_tests/db_engine_specs/test_mssql.py b/tests/unit_tests/db_engine_specs/test_mssql.py
index 673f4817be..8149e60cd8 100644
--- a/tests/unit_tests/db_engine_specs/test_mssql.py
+++ b/tests/unit_tests/db_engine_specs/test_mssql.py
@@ -431,3 +431,17 @@ Adaptive Server connection failed (mssqldb.cxiotftzsypc.us-west-2.rds.amazonaws.
},
)
]
+
+
+@pytest.mark.parametrize(
+ "name,expected_result",
+ [
+ ("col", "col"),
+ ("Col", "Col"),
+ ("COL", "COL"),
+ ],
+)
+def test_denormalize_name(name: str, expected_result: str):
+ from superset.db_engine_specs.mssql import MssqlEngineSpec as spec
+
+ assert spec.denormalize_name(mssql.dialect(), name) == expected_result
diff --git a/tests/unit_tests/db_engine_specs/test_oracle.py b/tests/unit_tests/db_engine_specs/test_oracle.py
index 0dce956970..210dff99d4 100644
--- a/tests/unit_tests/db_engine_specs/test_oracle.py
+++ b/tests/unit_tests/db_engine_specs/test_oracle.py
@@ -111,3 +111,17 @@ def test_convert_dttm(
from superset.db_engine_specs.oracle import OracleEngineSpec as spec
assert_convert_dttm(spec, target_type, expected_result, dttm)
+
+
+@pytest.mark.parametrize(
+ "name,expected_result",
+ [
+ ("col", "COL"),
+ ("Col", "Col"),
+ ("COL", "COL"),
+ ],
+)
+def test_denormalize_name(name: str, expected_result: str):
+ from superset.db_engine_specs.oracle import OracleEngineSpec as spec
+
+ assert spec.denormalize_name(oracle.dialect(), name) == expected_result