Skip to content

Commit

Permalink
Fix exception when retrieving mixed data types (#111)
Browse files Browse the repository at this point in the history
If the first row of a column returned from Exasol was a decimal type
then the adapter would expect all subsequent rows to be decimal and if
one of them happened to be NULL it would throw an exception:

"conversion from NoneType to Decimal is not supported"

This commit fixes that.

Co-authored-by: Peter Kioko <kioko@grantstreet.com>
  • Loading branch information
2 people authored and tglunde committed Nov 15, 2023
1 parent c359d10 commit ceb7dda
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dbt/adapters/exasol/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,13 @@ def get_result_from_cursor(cls, cursor: Any, limit: Optional[int]) -> agate.Tabl
if len(rows) > 0 and isinstance(rows[0][idx], str):
if col[1] in ["DECIMAL", "BIGINT"]:
for rownum, row in enumerate(rows):
if row[idx] is None: continue
tmp = list(row)
tmp[idx] = decimal.Decimal(row[idx])
rows[rownum] = tmp
elif col[1].startswith("TIMESTAMP"):
for rownum, row in enumerate(rows):
if row[idx] is None: continue
tmp = list(row)
tmp[idx] = parser.parse(row[idx])
rows[rownum] = tmp
Expand Down
12 changes: 12 additions & 0 deletions tests/functional/adapter/utils/test_mixed_type_retrieval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest
import decimal
from dbt.tests.util import get_connection

class TestMixedTypeRetrieval:
# A Decimal followed by a NULL used to raise an exception.
# Verify that it no longer does.
def test_decimal_followed_by_null(self,project):
sql = "select * from values 1.2, null"
with get_connection(project.adapter) as conn:
_, res = project.adapter.execute(sql, fetch=True)
assert res.rows.values() == ( ( decimal.Decimal('1.2'), ),( None, ) )

0 comments on commit ceb7dda

Please sign in to comment.