Skip to content

Commit 988b853

Browse files
committed
fix: oracle decimal type error
1 parent 439882c commit 988b853

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

awswrangler/oracle.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,12 @@ def detect_oracle_decimal_datatype(cursor: Any) -> dict[str, pa.DataType]:
606606
_logger.debug("cursor type: %s", type(cursor))
607607
if isinstance(cursor, oracledb.Cursor):
608608
# Oracle stores DECIMAL as the NUMBER type
609-
for row in cursor.description:
610-
if row[1] == oracledb.DB_TYPE_NUMBER and row[5] > 0:
611-
dtype[row[0]] = pa.decimal128(row[4], row[5])
609+
610+
for name, db_type, display_size, internal_size, precision, scale, null_ok in cursor.description:
611+
_logger.debug((name, db_type, display_size, internal_size, precision, scale, null_ok))
612+
613+
if db_type == oracledb.DB_TYPE_NUMBER and scale is not None and scale > 0:
614+
dtype[name] = pa.decimal128(precision, scale)
612615

613616
_logger.debug("decimal dtypes: %s", dtype)
614617
return dtype

tests/unit/test_oracle.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,15 @@ def test_dfs_are_equal_for_different_chunksizes(
254254
df["c1"] = df["c1"].astype("string")
255255

256256
assert df.equals(df2)
257+
258+
259+
def test_decimal_columns_none(oracle_table: str, oracle_con: "oracledb.Connection") -> None:
260+
create_table_sql = (
261+
f'CREATE TABLE "TEST"."{oracle_table}"("VARCOL" VARCHAR2(200),"INTCOL" INTEGER,"NUMCOL" NUMERIC(38, 10))'
262+
)
263+
264+
with oracle_con.cursor() as cursor:
265+
cursor.execute(create_table_sql)
266+
oracle_con.commit()
267+
268+
wr.oracle.read_sql_query(f"SELECT * FROM all_tab_columns WHERE table_name = '{oracle_table}'", oracle_con)

0 commit comments

Comments
 (0)