fix(mysql): handle string typed decimal results (#24241)

This commit is contained in:
Ville Brofeldt
2023-09-29 10:48:08 -07:00
committed by GitHub
parent 0735680674
commit 7eab59af51
3 changed files with 73 additions and 2 deletions

View File

@@ -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