MCPcopy Create free account
hub / github.com/apache/arrow / test_order_by

Function test_order_by

python/pyarrow/tests/test_acero.py:357–403  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

355
356
357def test_order_by():
358 table = pa.table({'a': [1, 2, 3, 4], 'b': [1, 3, None, 2]})
359 table_source = Declaration("table_source", TableSourceNodeOptions(table))
360
361 ord_opts = OrderByNodeOptions([("b", "ascending", "at_end")])
362 decl = Declaration.from_sequence([table_source, Declaration("order_by", ord_opts)])
363 result = decl.to_table()
364 expected = pa.table({"a": [1, 4, 2, 3], "b": [1, 2, 3, None]})
365 assert result.equals(expected)
366
367 ord_opts = OrderByNodeOptions([("b", "ascending")])
368 decl = Declaration.from_sequence([table_source, Declaration("order_by", ord_opts)])
369 result = decl.to_table()
370 expected = pa.table({"a": [1, 4, 2, 3], "b": [1, 2, 3, None]})
371 assert result.equals(expected)
372
373 ord_opts = OrderByNodeOptions([(field("b"), "descending", "at_end")])
374 decl = Declaration.from_sequence([table_source, Declaration("order_by", ord_opts)])
375 result = decl.to_table()
376 expected = pa.table({"a": [2, 4, 1, 3], "b": [3, 2, 1, None]})
377 assert result.equals(expected)
378
379 ord_opts = OrderByNodeOptions([(field("b"), "descending")])
380 decl = Declaration.from_sequence([table_source, Declaration("order_by", ord_opts)])
381 result = decl.to_table()
382 expected = pa.table({"a": [2, 4, 1, 3], "b": [3, 2, 1, None]})
383 assert result.equals(expected)
384
385 ord_opts = OrderByNodeOptions([(1, "descending", "at_start")])
386 decl = Declaration.from_sequence([table_source, Declaration("order_by", ord_opts)])
387 result = decl.to_table()
388 expected = pa.table({"a": [3, 2, 4, 1], "b": [None, 3, 2, 1]})
389 assert result.equals(expected)
390
391 # empty ordering
392 ord_opts = OrderByNodeOptions([])
393 decl = Declaration.from_sequence([table_source, Declaration("order_by", ord_opts)])
394 with pytest.raises(
395 ValueError, match="`ordering` must be an explicit non-empty ordering"
396 ):
397 _ = decl.to_table()
398
399 with pytest.raises(ValueError, match="\"decreasing\" is not a valid sort order"):
400 _ = OrderByNodeOptions([("b", "decreasing", "at_end")])
401
402 with pytest.raises(ValueError, match="\"start\" is not a valid null placement"):
403 _ = OrderByNodeOptions([("b", "ascending", "start")])
404
405
406def test_hash_join():

Callers

nothing calls this directly

Calls 6

DeclarationClass · 0.90
TableSourceNodeOptionsFunction · 0.90
OrderByNodeOptionsFunction · 0.90
fieldFunction · 0.90
equalsMethod · 0.80
to_tableMethod · 0.45

Tested by

no test coverage detected