Skip to content

Commit 1e083a8

Browse files
authored
Merge pull request #2973 from mabel-dev/copilot/fix-cannot-negate-operator
Fix NOT operator with array containment operators (@>, @>>)
2 parents c4d2eb9 + 09e35b6 commit 1e083a8

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

opteryx/managers/expression/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,13 @@ def _inner_evaluate(root: Node, table: Table):
267267
if root.centre
268268
else pyarrow.nulls(1, type=pyarrow.bool_())
269269
)
270+
# Convert to numpy array if it's not already a PyArrow array
271+
# This handles memoryviews, Cython memoryviewslices, and other array-like objects
272+
if not isinstance(centre, pyarrow.Array):
273+
centre = numpy.asarray(centre)
274+
# Convert numeric types (e.g., uint8 from list_contains_any) to boolean
275+
if numpy.issubdtype(centre.dtype, numpy.integer):
276+
centre = centre.astype(numpy.bool_)
270277
centre = pyarrow.array(centre, type=pyarrow.bool_())
271278
return pyarrow.compute.invert(centre)
272279

tests/integration/sql_battery/test_shapes_aliases_distinct.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229
("SELECT missions FROM $astronauts WHERE ARRAY_CONTAINS_ALL(missions, ('Apollo 8', 'Gemini 7'))", 2, 1, None),
230230
("SELECT missions FROM $astronauts WHERE ARRAY_CONTAINS_ALL(missions, ('Gemini 7', 'Apollo 8'))", 2, 1, None),
231231
("SELECT missions FROM $astronauts WHERE missions @> ('Apollo 8', 'Apollo 13')", 5, 1, None),
232+
("SELECT * FROM (SELECT name, IFNULL(missions, []) AS missions FROM $astronauts) WHERE NOT missions @> ['Apollo 11']", 354, 2, None),
232233
("SELECT * FROM $astronauts WHERE missions @>> ('Apollo 11', 'Gemini 12')", 1, 19, None),
233234
("SELECT * FROM $astronauts WHERE missions @>> ('Gemini 7', 'Apollo 8')", 2, 19, None),
234235

0 commit comments

Comments
 (0)