Skip to content

Commit

Permalink
fix: oracle decimal type error
Browse files Browse the repository at this point in the history
  • Loading branch information
kukushking committed Feb 26, 2025
1 parent 439882c commit 988b853
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions awswrangler/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,12 @@ def detect_oracle_decimal_datatype(cursor: Any) -> dict[str, pa.DataType]:
_logger.debug("cursor type: %s", type(cursor))
if isinstance(cursor, oracledb.Cursor):
# Oracle stores DECIMAL as the NUMBER type
for row in cursor.description:
if row[1] == oracledb.DB_TYPE_NUMBER and row[5] > 0:
dtype[row[0]] = pa.decimal128(row[4], row[5])

for name, db_type, display_size, internal_size, precision, scale, null_ok in cursor.description:
_logger.debug((name, db_type, display_size, internal_size, precision, scale, null_ok))

if db_type == oracledb.DB_TYPE_NUMBER and scale is not None and scale > 0:
dtype[name] = pa.decimal128(precision, scale)

_logger.debug("decimal dtypes: %s", dtype)
return dtype
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,15 @@ def test_dfs_are_equal_for_different_chunksizes(
df["c1"] = df["c1"].astype("string")

assert df.equals(df2)


def test_decimal_columns_none(oracle_table: str, oracle_con: "oracledb.Connection") -> None:
create_table_sql = (
f'CREATE TABLE "TEST"."{oracle_table}"("VARCOL" VARCHAR2(200),"INTCOL" INTEGER,"NUMCOL" NUMERIC(38, 10))'
)

with oracle_con.cursor() as cursor:
cursor.execute(create_table_sql)
oracle_con.commit()

wr.oracle.read_sql_query(f"SELECT * FROM all_tab_columns WHERE table_name = '{oracle_table}'", oracle_con)

0 comments on commit 988b853

Please sign in to comment.