Skip to content

Commit 003fc2e

Browse files
Ensure that a helpful error message is raised when using Apache Arrow
fixed width binary with data that doesn't conform to the fixed width.
1 parent 0a978ad commit 003fc2e

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

src/oracledb/errors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ def _raise_not_supported(feature: str) -> None:
372372
ERR_CANNOT_CONVERT_TO_ARROW_DOUBLE = 4037
373373
ERR_INVALID_INTEGER = 4038
374374
ERR_CANNOT_CONVERT_TO_ARROW_FLOAT = 4039
375+
ERR_ARROW_FIXED_SIZE_BINARY_VIOLATED = 4040
375376

376377
# error numbers that result in InternalError
377378
ERR_MESSAGE_TYPE_UNKNOWN = 5000
@@ -575,6 +576,10 @@ def _raise_not_supported(feature: str) -> None:
575576
"Apache Arrow C Data structure overflow detected. A larger structure "
576577
"is needed."
577578
),
579+
ERR_ARROW_FIXED_SIZE_BINARY_VIOLATED: (
580+
"value of length {actual_len} does not match the Apache Arrow fixed "
581+
"size binary length of {fixed_size_len}"
582+
),
578583
ERR_ARROW_SPARSE_VECTOR_NOT_ALLOWED: (
579584
"Apache Arrow format does not support sparse vectors with flexible "
580585
"dimensions"

src/oracledb/impl/arrow/array.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ cdef class ArrowArrayImpl:
108108
cdef ArrowBufferView data
109109
data.data.data = ptr
110110
data.size_bytes = num_bytes
111+
if self.schema_impl.fixed_size > 0 \
112+
and num_bytes != self.schema_impl.fixed_size:
113+
errors._raise_err(errors.ERR_ARROW_FIXED_SIZE_BINARY_VIOLATED,
114+
actual_len=num_bytes,
115+
fixed_size_len=self.schema_impl.fixed_size)
111116
_check_nanoarrow(ArrowArrayAppendBytes(self.arrow_array, data))
112117

113118
cdef int append_decimal(self, void* ptr, int64_t num_bytes) except -1:

tests/test_9300_dataframe_requested_schema.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,3 +745,13 @@ def test_9326(dtype, value, conn, test_env):
745745
conn.fetch_df_all(
746746
"select :1 from dual", [value], requested_schema=requested_schema
747747
)
748+
749+
750+
@pytest.mark.parametrize("value", [b"Too short", b"Much too long"])
751+
def test_9327(value, conn, test_env):
752+
"9327 - fetch_df_all() with fixed width binary violations"
753+
requested_schema = pyarrow.schema([("VALUE", pyarrow.binary(length=10))])
754+
with test_env.assert_raises_full_code("DPY-4040"):
755+
conn.fetch_df_all(
756+
"select :1 from dual", [value], requested_schema=requested_schema
757+
)

tests/test_9400_dataframe_requested_schema_async.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,3 +768,13 @@ async def test_9426(dtype, value, async_conn, test_env):
768768
await async_conn.fetch_df_all(
769769
"select :1 from dual", [value], requested_schema=requested_schema
770770
)
771+
772+
773+
@pytest.mark.parametrize("value", [b"Too short", b"Much too long"])
774+
async def test_9427(value, async_conn, test_env):
775+
"9427 - fetch_df_all() with fixed width binary violations"
776+
requested_schema = pyarrow.schema([("VALUE", pyarrow.binary(length=10))])
777+
with test_env.assert_raises_full_code("DPY-4040"):
778+
await async_conn.fetch_df_all(
779+
"select :1 from dual", [value], requested_schema=requested_schema
780+
)

0 commit comments

Comments
 (0)