mirror of
https://github.com/apache/superset.git
synced 2026-04-19 16:14:52 +00:00
fix(mysql): handle string typed decimal results (#24241)
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
# under the License.
|
||||
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from typing import Any, Optional
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
@@ -220,3 +221,42 @@ def test_get_schema_from_engine_params() -> None:
|
||||
)
|
||||
== "db1"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"data,description,expected_result",
|
||||
[
|
||||
(
|
||||
[("1.23456", "abc")],
|
||||
[("dec", "decimal(12,6)"), ("str", "varchar(3)")],
|
||||
[(Decimal("1.23456"), "abc")],
|
||||
),
|
||||
(
|
||||
[(Decimal("1.23456"), "abc")],
|
||||
[("dec", "decimal(12,6)"), ("str", "varchar(3)")],
|
||||
[(Decimal("1.23456"), "abc")],
|
||||
),
|
||||
(
|
||||
[(None, "abc")],
|
||||
[("dec", "decimal(12,6)"), ("str", "varchar(3)")],
|
||||
[(None, "abc")],
|
||||
),
|
||||
(
|
||||
[("1.23456", "abc")],
|
||||
[("dec", "varchar(255)"), ("str", "varchar(3)")],
|
||||
[("1.23456", "abc")],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_column_type_mutator(
|
||||
data: list[tuple[Any, ...]],
|
||||
description: list[Any],
|
||||
expected_result: list[tuple[Any, ...]],
|
||||
):
|
||||
from superset.db_engine_specs.mysql import MySQLEngineSpec as spec
|
||||
|
||||
mock_cursor = Mock()
|
||||
mock_cursor.fetchall.return_value = data
|
||||
mock_cursor.description = description
|
||||
|
||||
assert spec.fetch_data(mock_cursor) == expected_result
|
||||
|
||||
Reference in New Issue
Block a user