Skip to content

Commit

Permalink
feat(oracle): change parsing of Oracle NUMBER data type
Browse files Browse the repository at this point in the history
  • Loading branch information
kangshung authored and cpcloud committed Nov 2, 2023
1 parent e3d14b3 commit 649ab86
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions ibis/backends/oracle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,26 @@ def _metadata(self, query: str) -> Iterable[tuple[str, dt.DataType]]:
con.execute(drop_view)

for name, type_string, precision, scale, nullable in results:
if precision is not None and scale is not None and precision != 0:
# NUMBER(null, null) --> FLOAT
# (null, null) --> from_string()
if type_string == "NUMBER" and precision is None and scale is None:
typ = dt.Float64(nullable=nullable)

# (null, 0) --> INT
# (null, 3), (null, 6), (null, 9) --> from_string() - TIMESTAMP(3)/(6)/(9)
elif precision is None and (scale is not None and scale == 0):
typ = dt.Int64(nullable=nullable)

# NUMBER(*, 0) --> INT
# (*, 0) --> from_string() - INTERVAL DAY(3) TO SECOND(0)
elif type_string == "NUMBER" and precision is not None and (scale is not None and scale == 0):
typ = dt.Int64(nullable=nullable)

# NUMBER(*, > 0) --> DECIMAL
# (*, > 0) --> from_string() - INTERVAL DAY(3) TO SECOND(2)
elif type_string == "NUMBER" and precision is not None and (scale is not None and scale > 0):
typ = dt.Decimal(precision=precision, scale=scale, nullable=nullable)
elif precision == 0:
# TODO: how to disambiguate between int and float here without inspecting the value?
typ = dt.float

else:
typ = OracleType.from_string(type_string, nullable=nullable)
yield name, typ
Expand Down

0 comments on commit 649ab86

Please sign in to comment.