Skip to content

Commit

Permalink
fix(duckdb): map hugeint to decimal to avoid information loss
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Jul 23, 2023
1 parent f167caa commit 4fe91d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 2 additions & 4 deletions ibis/backends/duckdb/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def parse(text: str, default_decimal_parameters=(18, 3)) -> dt.DataType:
"""Parse a DuckDB type into an ibis data type."""
primitive = (
spaceless_string("interval").result(dt.Interval('us'))
| spaceless_string("hugeint", "int128").result(dt.Decimal(38, 0))
| spaceless_string("bigint", "int8", "long").result(dt.int64)
| spaceless_string("boolean", "bool", "logical").result(dt.boolean)
| spaceless_string("blob", "bytea", "binary", "varbinary").result(dt.binary)
Expand Down Expand Up @@ -101,10 +102,7 @@ def parse(text: str, default_decimal_parameters=(18, 3)) -> dt.DataType:
ducktypes.SmallInteger: dt.Int16,
ducktypes.Integer: dt.Int32,
ducktypes.BigInteger: dt.Int64,
ducktypes.HugeInteger: dt.Int64,
# The following dtypes are present in duckdb_engine and will show up
# in _some_ tables, but it isn't clear _why_.
# Please don't remove them.
ducktypes.HugeInteger: dt.Decimal(38, 0),
ducktypes.UInt8: dt.UInt8,
ducktypes.UTinyInteger: dt.UInt8,
ducktypes.UInt16: dt.UInt16,
Expand Down
2 changes: 2 additions & 0 deletions ibis/backends/duckdb/tests/test_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
("TIMESTAMP_US", dt.Timestamp("UTC", scale=6)),
("TIMESTAMP_NS", dt.Timestamp("UTC", scale=9)),
("JSON", dt.json),
("HUGEINT", dt.Decimal(38, 0)),
("INT128", dt.Decimal(38, 0)),
]
],
)
Expand Down

0 comments on commit 4fe91d4

Please sign in to comment.