From 55e41c395dd52ab67cbc995ecca635a9e6d0dd06 Mon Sep 17 00:00:00 2001 From: Shaun Patterson Date: Sat, 21 Nov 2026 11:28:20 -0500 Subject: [PATCH 1/2] fix(#426): insert_arrow and insert_dataframe check a uint64 column before the first batch is written The range check ran as each batch was converted, so a bad value in a later batch left the earlier ones committed, and on the JVM wheel a batch with nulls raised OverflowError instead of ValueError. The whole table is checked up front, dictionary-encoded columns included. --- src/arcadedb/dataframe.py | 34 ++++++++++++++----- tests/test_dataframe_columns_behavior.py | 42 ++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/src/arcadedb/dataframe.py b/src/arcadedb/dataframe.py index 6fa3de5c..e7f0d1f3 100644 --- a/src/arcadedb/dataframe.py +++ b/src/arcadedb/dataframe.py @@ -414,15 +414,6 @@ def _column_values( ): # uint64 keeps the range check below return chunk if kind in ("integer", "floating", "bool"): - if native and types.is_uint64(chunk.type) and len(chunk) > chunk.null_count: - import pyarrow.compute as pc - - if ( - pc.max(chunk).as_py() > 2**63 - 1 - ): # insert_columns refuses it on the JPype path, with this text - raise ValueError( - f"column {name!r} holds a value beyond the 64-bit signed range" - ) if chunk.null_count == 0: values = chunk.to_numpy(zero_copy_only=False) if values.dtype.kind == "f" and values.dtype.itemsize < 8: @@ -448,6 +439,30 @@ def _column_values( return chunk.to_pylist() +def _check_uint64_range(pa, table) -> None: + """Raise ``ValueError`` when a uint64 column of ``table`` (a dictionary-encoded one included) holds a value beyond the 64-bit signed range. + + The engine stores integers as signed 64-bit longs. The whole table is checked before the first batch is written: a check + made as each batch is converted would leave the batches before the bad value committed, and a batch with nulls reaches the + JPype build as Python ints, where the value raised ``OverflowError`` instead. + """ + import pyarrow.compute as pc + + for field, column in zip(table.schema, table.columns): + value_type = ( + field.type.value_type if pa.types.is_dictionary(field.type) else field.type + ) + if not pa.types.is_uint64(value_type): + continue + if value_type is not field.type: + column = column.cast(value_type) + largest = pc.max(column).as_py() # None when every value is null + if largest is not None and largest > 2**63 - 1: + raise ValueError( + f"column {field.name!r} holds a value beyond the 64-bit signed range" + ) + + def insert_table( db, type_name: str, @@ -491,6 +506,7 @@ def insert_table( ) if table.num_rows == 0: return 0 + _check_uint64_range(pa, table) native = _is_native(db) written = 0 diff --git a/tests/test_dataframe_columns_behavior.py b/tests/test_dataframe_columns_behavior.py index fb602a7f..aa6459f6 100644 --- a/tests/test_dataframe_columns_behavior.py +++ b/tests/test_dataframe_columns_behavior.py @@ -153,6 +153,48 @@ def test_a_uint64_value_past_the_signed_range_is_refused(temp_db): assert _count(temp_db, "Big") == 0 +@pytest.mark.parametrize( + "values", + [[1, 2, 3, 2**63 + 5], [1, 2, None, 2**63 + 5]], + ids=["no_null", "with_null"], +) +def test_a_uint64_past_the_signed_range_in_a_late_batch_is_refused_before_any_row_is_written( + temp_db, values +): + """The range check read each batch as it was written, so the batches before the bad value were + committed when the ValueError came (and on the JVM build a column with nulls raised OverflowError). + """ + temp_db.command("sql", "CREATE DOCUMENT TYPE Big") + table = pa.table({"v": pa.array(values, pa.uint64())}) + with pytest.raises(ValueError, match="64-bit signed"): + temp_db.insert_arrow("Big", table, batch_size=2) + assert _count(temp_db, "Big") == 0 + + +def test_a_uint64_dictionary_column_past_the_signed_range_is_refused(temp_db): + temp_db.command("sql", "CREATE DOCUMENT TYPE Big") + column = pa.array([1, 2**63, 1], pa.uint64()).dictionary_encode() + with pytest.raises(ValueError, match="64-bit signed"): + temp_db.insert_arrow("Big", pa.table({"v": column}), batch_size=2) + assert _count(temp_db, "Big") == 0 + + +def test_a_uint64_column_at_the_signed_limit_loads(temp_db): + temp_db.command("sql", "CREATE DOCUMENT TYPE Big") + values = [1, None, 2**63 - 1] + assert ( + temp_db.insert_arrow( + "Big", pa.table({"v": pa.array(values, pa.uint64())}), batch_size=2 + ) + == 3 + ) + rows = temp_db.query("sql", "SELECT v FROM Big").to_list() + assert sorted(r.get("v") for r in rows if r.get("v") is not None) == [ + 1, + 2**63 - 1, + ] + + def test_a_type_with_no_mapping_is_refused_before_a_row_is_written(temp_db): temp_db.command("sql", "CREATE DOCUMENT TYPE NoMap") with pytest.raises(TypeError, match="no ArcadeDB mapping"): From c465b43f92abb78756113afd3f6a900245f89261 Mon Sep 17 00:00:00 2001 From: Shaun Patterson Date: Sat, 21 Nov 2026 11:48:18 -0500 Subject: [PATCH 2/2] docs(#426): insert_dataframe lists the uint64 range among the ValueErrors raised before a write --- src/arcadedb/core.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/arcadedb/core.py b/src/arcadedb/core.py index 29ef6574..ef473f3b 100644 --- a/src/arcadedb/core.py +++ b/src/arcadedb/core.py @@ -1301,8 +1301,9 @@ def insert_dataframe( Raises: ImportError: If pyarrow is not installed. ValueError: If the frame has no columns, duplicate or non-string - column names, ``batch_size`` is not a positive integer, or - ``parallel`` is used with a vertex type. + column names, ``batch_size`` is not a positive integer, + ``parallel`` is used with a vertex type, or a ``uint64`` column + holds a value above 2**63 - 1. Raised before anything is written. TypeError: If a column has a type with no ArcadeDB mapping (time of day, duration, map), or one that does not load into the property type ``type_name`` declares for it (a float column into an