()
| 264 | |
| 265 | |
| 266 | def test_order_by(): |
| 267 | table = pa.table({'a': [1, 2, 3, 4], 'b': [1, 3, None, 2]}) |
| 268 | table_source = Declaration("table_source", TableSourceNodeOptions(table)) |
| 269 | |
| 270 | ord_opts = OrderByNodeOptions([("b", "ascending")]) |
| 271 | decl = Declaration.from_sequence([table_source, Declaration("order_by", ord_opts)]) |
| 272 | result = decl.to_table() |
| 273 | expected = pa.table({"a": [1, 4, 2, 3], "b": [1, 2, 3, None]}) |
| 274 | assert result.equals(expected) |
| 275 | |
| 276 | ord_opts = OrderByNodeOptions([(field("b"), "descending")]) |
| 277 | decl = Declaration.from_sequence([table_source, Declaration("order_by", ord_opts)]) |
| 278 | result = decl.to_table() |
| 279 | expected = pa.table({"a": [2, 4, 1, 3], "b": [3, 2, 1, None]}) |
| 280 | assert result.equals(expected) |
| 281 | |
| 282 | ord_opts = OrderByNodeOptions([(1, "descending")], null_placement="at_start") |
| 283 | decl = Declaration.from_sequence([table_source, Declaration("order_by", ord_opts)]) |
| 284 | result = decl.to_table() |
| 285 | expected = pa.table({"a": [3, 2, 4, 1], "b": [None, 3, 2, 1]}) |
| 286 | assert result.equals(expected) |
| 287 | |
| 288 | # empty ordering |
| 289 | ord_opts = OrderByNodeOptions([]) |
| 290 | decl = Declaration.from_sequence([table_source, Declaration("order_by", ord_opts)]) |
| 291 | with pytest.raises( |
| 292 | ValueError, match="`ordering` must be an explicit non-empty ordering" |
| 293 | ): |
| 294 | _ = decl.to_table() |
| 295 | |
| 296 | with pytest.raises(ValueError, match="\"decreasing\" is not a valid sort order"): |
| 297 | _ = OrderByNodeOptions([("b", "decreasing")]) |
| 298 | |
| 299 | with pytest.raises(ValueError, match="\"start\" is not a valid null placement"): |
| 300 | _ = OrderByNodeOptions([("b", "ascending")], null_placement="start") |
| 301 | |
| 302 | |
| 303 | def test_hash_join(): |
nothing calls this directly
no test coverage detected