Skip to content

Commit

Permalink
add comment + a unit test for None values
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed May 30, 2023
1 parent 1249654 commit 261baf4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 6 additions & 3 deletions superset/db_engine_specs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,10 @@ def fetch_data(
return cursor.fetchmany(limit)
data = cursor.fetchall()
description = cursor.description or []
column_type_mutators = {
# Create a mapping between column name and a mutator function to normalize
# values with. The first two items in the description row are
# the column name and type.
column_mutators = {
row[0]: func
for row in description
if (
Expand All @@ -752,11 +755,11 @@ def fetch_data(
)
)
}
if column_type_mutators:
if column_mutators:
indexes = {row[0]: idx for idx, row in enumerate(description)}
for row_idx, row in enumerate(data):
new_row = list(row)
for col, func in column_type_mutators.items():
for col, func in column_mutators.items():
col_idx = indexes[col]
new_row[col_idx] = func(row[col_idx])
data[row_idx] = tuple(new_row)
Expand Down
5 changes: 5 additions & 0 deletions tests/unit_tests/db_engine_specs/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ def test_get_schema_from_engine_params() -> None:
[("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)")],
Expand Down
5 changes: 5 additions & 0 deletions tests/unit_tests/db_engine_specs/test_trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ def test_handle_cursor_early_cancel(
[("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)")],
Expand Down

0 comments on commit 261baf4

Please sign in to comment.