()
| 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", "at_end")]) |
| 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([("b", "ascending")]) |
| 277 | decl = Declaration.from_sequence([table_source, Declaration("order_by", ord_opts)]) |
| 278 | result = decl.to_table() |
| 279 | expected = pa.table({"a": [1, 4, 2, 3], "b": [1, 2, 3, None]}) |
| 280 | assert result.equals(expected) |
| 281 | |
| 282 | ord_opts = OrderByNodeOptions([(field("b"), "descending", "at_end")]) |
| 283 | decl = Declaration.from_sequence([table_source, Declaration("order_by", ord_opts)]) |
| 284 | result = decl.to_table() |
| 285 | expected = pa.table({"a": [2, 4, 1, 3], "b": [3, 2, 1, None]}) |
| 286 | assert result.equals(expected) |
| 287 | |
| 288 | ord_opts = OrderByNodeOptions([(field("b"), "descending")]) |
| 289 | decl = Declaration.from_sequence([table_source, Declaration("order_by", ord_opts)]) |
| 290 | result = decl.to_table() |
| 291 | expected = pa.table({"a": [2, 4, 1, 3], "b": [3, 2, 1, None]}) |
| 292 | assert result.equals(expected) |
| 293 | |
| 294 | ord_opts = OrderByNodeOptions([(1, "descending", "at_start")]) |
| 295 | decl = Declaration.from_sequence([table_source, Declaration("order_by", ord_opts)]) |
| 296 | result = decl.to_table() |
| 297 | expected = pa.table({"a": [3, 2, 4, 1], "b": [None, 3, 2, 1]}) |
| 298 | assert result.equals(expected) |
| 299 | |
| 300 | # empty ordering |
| 301 | ord_opts = OrderByNodeOptions([]) |
| 302 | decl = Declaration.from_sequence([table_source, Declaration("order_by", ord_opts)]) |
| 303 | with pytest.raises( |
| 304 | ValueError, match="`ordering` must be an explicit non-empty ordering" |
| 305 | ): |
| 306 | _ = decl.to_table() |
| 307 | |
| 308 | with pytest.raises(ValueError, match="\"decreasing\" is not a valid sort order"): |
| 309 | _ = OrderByNodeOptions([("b", "decreasing", "at_end")]) |
| 310 | |
| 311 | with pytest.raises(ValueError, match="\"start\" is not a valid null placement"): |
| 312 | _ = OrderByNodeOptions([("b", "ascending", "start")]) |
| 313 | |
| 314 | |
| 315 | def test_hash_join(): |
nothing calls this directly
no test coverage detected