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

fix(table_metadata): longType truncate the ROW/MAP structure #31587

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion superset/databases/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_indexes_metadata(

def get_col_type(col: dict[Any, Any]) -> str:
try:
dtype = f"{col['type']}"
dtype = repr(col["type"])
except Exception: # pylint: disable=broad-except
# sqla.types.JSON __str__ has a bug, so using __class__.
dtype = col["type"].__class__.__name__
Expand Down
37 changes: 36 additions & 1 deletion tests/unit_tests/databases/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

from sqlalchemy.engine.url import make_url
from sqlalchemy.orm.session import Session
from sqlalchemy.sql import sqltypes
from trino.sqlalchemy import datatype

from superset.databases.utils import make_url_safe
from superset.databases.utils import get_col_type, make_url_safe


def test_make_url_safe_string(session: Session) -> None:
Expand All @@ -38,3 +40,36 @@ def test_make_url_safe_url(session: Session) -> None:
uri = make_url("postgresql+psycopg2://superset:***@127.0.0.1:5432/superset")
uri_safe = make_url_safe(uri)
assert uri_safe == uri


def test_get_col_type_primary(session: Session) -> None:
"""
Test getting a column type
"""
col = {
"name": "id",
"type": sqltypes.INTEGER(),
"nullable": False,
"default": None,
"comment": None,
}
assert get_col_type(col) == "INTEGER()"


def test_get_col_type_row_and_map(session: Session) -> None:
"""
Test getting a column type
"""
col = {
"name": "id",
"type": datatype.ROW(
[
("name", sqltypes.VARCHAR()),
("age", sqltypes.INTEGER()),
]
),
"nullable": False,
"default": None,
"comment": None,
}
assert get_col_type(col) == "ROW([('name', VARCHAR()), ('age', INTEGER())])"
Loading