mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
fix: save columns reference from sqllab save datasets flow (#24248)
This commit is contained in:
@@ -22,6 +22,7 @@ from typing import Any, Optional
|
||||
import pytest
|
||||
from sqlalchemy import types
|
||||
|
||||
from superset.superset_typing import ResultSetColumnType, SQLAColumnType
|
||||
from superset.utils.core import GenericDataType
|
||||
from tests.unit_tests.db_engine_specs.utils import assert_column_spec
|
||||
|
||||
@@ -138,3 +139,32 @@ def test_get_column_spec(
|
||||
from superset.db_engine_specs.databricks import DatabricksNativeEngineSpec as spec
|
||||
|
||||
assert_column_spec(spec, native_type, sqla_type, attrs, generic_type, is_dttm)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"cols, expected_result",
|
||||
[
|
||||
(
|
||||
[SQLAColumnType(name="John", type="integer", is_dttm=False)],
|
||||
[
|
||||
ResultSetColumnType(
|
||||
column_name="John", name="John", type="integer", is_dttm=False
|
||||
)
|
||||
],
|
||||
),
|
||||
(
|
||||
[SQLAColumnType(name="hugh", type="integer", is_dttm=False)],
|
||||
[
|
||||
ResultSetColumnType(
|
||||
column_name="hugh", name="hugh", type="integer", is_dttm=False
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_convert_inspector_columns(
|
||||
cols: list[SQLAColumnType], expected_result: list[ResultSetColumnType]
|
||||
):
|
||||
from superset.db_engine_specs.base import convert_inspector_columns
|
||||
|
||||
assert convert_inspector_columns(cols) == expected_result
|
||||
|
||||
@@ -27,6 +27,7 @@ from sqlalchemy import select
|
||||
from sqlalchemy.sql import sqltypes
|
||||
from sqlalchemy_bigquery import BigQueryDialect
|
||||
|
||||
from superset.superset_typing import ResultSetColumnType
|
||||
from tests.unit_tests.db_engine_specs.utils import assert_convert_dttm
|
||||
from tests.unit_tests.fixtures.common import dttm
|
||||
|
||||
@@ -64,7 +65,16 @@ def test_get_fields() -> None:
|
||||
"""
|
||||
from superset.db_engine_specs.bigquery import BigQueryEngineSpec
|
||||
|
||||
columns = [{"name": "limit"}, {"name": "name"}, {"name": "project.name"}]
|
||||
columns: list[ResultSetColumnType] = [
|
||||
{"column_name": "limit", "name": "limit", "type": "STRING", "is_dttm": False},
|
||||
{"column_name": "name", "name": "name", "type": "STRING", "is_dttm": False},
|
||||
{
|
||||
"column_name": "project.name",
|
||||
"name": "project.name",
|
||||
"type": "STRING",
|
||||
"is_dttm": False,
|
||||
},
|
||||
]
|
||||
fields = BigQueryEngineSpec._get_fields(columns)
|
||||
|
||||
query = select(fields)
|
||||
@@ -84,8 +94,9 @@ def test_select_star(mocker: MockFixture) -> None:
|
||||
"""
|
||||
from superset.db_engine_specs.bigquery import BigQueryEngineSpec
|
||||
|
||||
cols = [
|
||||
cols: list[ResultSetColumnType] = [
|
||||
{
|
||||
"column_name": "trailer",
|
||||
"name": "trailer",
|
||||
"type": sqltypes.ARRAY(sqltypes.JSON()),
|
||||
"nullable": True,
|
||||
@@ -94,8 +105,10 @@ def test_select_star(mocker: MockFixture) -> None:
|
||||
"precision": None,
|
||||
"scale": None,
|
||||
"max_length": None,
|
||||
"is_dttm": False,
|
||||
},
|
||||
{
|
||||
"column_name": "trailer.key",
|
||||
"name": "trailer.key",
|
||||
"type": sqltypes.String(),
|
||||
"nullable": True,
|
||||
@@ -104,8 +117,10 @@ def test_select_star(mocker: MockFixture) -> None:
|
||||
"precision": None,
|
||||
"scale": None,
|
||||
"max_length": None,
|
||||
"is_dttm": False,
|
||||
},
|
||||
{
|
||||
"column_name": "trailer.value",
|
||||
"name": "trailer.value",
|
||||
"type": sqltypes.String(),
|
||||
"nullable": True,
|
||||
@@ -114,8 +129,10 @@ def test_select_star(mocker: MockFixture) -> None:
|
||||
"precision": None,
|
||||
"scale": None,
|
||||
"max_length": None,
|
||||
"is_dttm": False,
|
||||
},
|
||||
{
|
||||
"column_name": "trailer.email",
|
||||
"name": "trailer.email",
|
||||
"type": sqltypes.String(),
|
||||
"nullable": True,
|
||||
@@ -124,6 +141,7 @@ def test_select_star(mocker: MockFixture) -> None:
|
||||
"precision": None,
|
||||
"scale": None,
|
||||
"max_length": None,
|
||||
"is_dttm": False,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ from pyhive.sqlalchemy_presto import PrestoDialect
|
||||
from sqlalchemy import sql, text, types
|
||||
from sqlalchemy.engine.url import make_url
|
||||
|
||||
from superset.superset_typing import ResultSetColumnType
|
||||
from superset.utils.core import GenericDataType
|
||||
from tests.unit_tests.db_engine_specs.utils import (
|
||||
assert_column_spec,
|
||||
@@ -131,7 +132,14 @@ def test_where_latest_partition(
|
||||
mock_latest_partition.return_value = (["partition_key"], [column_value])
|
||||
|
||||
query = sql.select(text("* FROM table"))
|
||||
columns = [{"name": "partition_key", "type": column_type}]
|
||||
columns: list[ResultSetColumnType] = [
|
||||
{
|
||||
"column_name": "partition_key",
|
||||
"name": "partition_key",
|
||||
"type": column_type,
|
||||
"is_dttm": False,
|
||||
}
|
||||
]
|
||||
|
||||
expected = f"""SELECT * FROM table \nWHERE "partition_key" = {expected_value}"""
|
||||
result = spec.where_latest_partition(
|
||||
|
||||
Reference in New Issue
Block a user