From 988b853fa0b53fdd81a07c65dbbe5094348fa44a Mon Sep 17 00:00:00 2001 From: kukushking Date: Wed, 26 Feb 2025 17:54:35 +0000 Subject: [PATCH] fix: oracle decimal type error --- awswrangler/oracle.py | 9 ++++++--- tests/unit/test_oracle.py | 12 ++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/awswrangler/oracle.py b/awswrangler/oracle.py index 996a9452a..703a00ee5 100644 --- a/awswrangler/oracle.py +++ b/awswrangler/oracle.py @@ -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 diff --git a/tests/unit/test_oracle.py b/tests/unit/test_oracle.py index 0264be94a..47b6ad0aa 100644 --- a/tests/unit/test_oracle.py +++ b/tests/unit/test_oracle.py @@ -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)