|
1 | 1 | import datetime |
| 2 | +import json |
2 | 3 |
|
3 | 4 | import pytest |
4 | 5 |
|
|
8 | 9 | arrow = pytest.importorskip("pyarrow") |
9 | 10 | pl_testing = pytest.importorskip("polars.testing") |
10 | 11 |
|
11 | | -from duckdb.polars_io import _predicate_to_expression # noqa: E402 |
| 12 | +from duckdb.polars_io import _pl_tree_to_sql, _predicate_to_expression # noqa: E402 |
12 | 13 |
|
13 | 14 |
|
14 | 15 | def valid_filter(filter): |
@@ -605,3 +606,53 @@ def test_polars_lazy_many_batches(self, duckdb_cursor): |
605 | 606 | correct = duckdb_cursor.execute("FROM t").fetchall() |
606 | 607 |
|
607 | 608 | assert res == correct |
| 609 | + |
| 610 | + def test_invalid_expr_json(self): |
| 611 | + bad_key_expr = """ |
| 612 | + { |
| 613 | + "BinaryExpr": { |
| 614 | + "left": { "Column": "foo" }, |
| 615 | + "middle": "Gt", |
| 616 | + "right": { "Literal": { "Int": 5 } } |
| 617 | + } |
| 618 | + } |
| 619 | + """ |
| 620 | + with pytest.raises(KeyError, match="'op'"): |
| 621 | + _pl_tree_to_sql(json.loads(bad_key_expr)) |
| 622 | + |
| 623 | + bad_type_expr = """ |
| 624 | + { |
| 625 | + "BinaryExpr": { |
| 626 | + "left": { "Column": [ "foo" ] }, |
| 627 | + "op": "Gt", |
| 628 | + "right": { "Literal": { "Int": 5 } } |
| 629 | + } |
| 630 | + } |
| 631 | + """ |
| 632 | + with pytest.raises(AssertionError, match="The col name of a Column should be a str but got"): |
| 633 | + _pl_tree_to_sql(json.loads(bad_type_expr)) |
| 634 | + |
| 635 | + def test_old_dec(self): |
| 636 | + bad_key_expr = """ |
| 637 | + { |
| 638 | + "BinaryExpr": { |
| 639 | + "left": { "Column": "foo" }, |
| 640 | + "middle": "Gt", |
| 641 | + "right": { "Literal": { "Int": 5 } } |
| 642 | + } |
| 643 | + } |
| 644 | + """ |
| 645 | + with pytest.raises(KeyError, match="'op'"): |
| 646 | + _pl_tree_to_sql(json.loads(bad_key_expr)) |
| 647 | + |
| 648 | + bad_type_expr = """ |
| 649 | + { |
| 650 | + "BinaryExpr": { |
| 651 | + "left": { "Column": [ "foo" ] }, |
| 652 | + "op": "Gt", |
| 653 | + "right": { "Literal": { "Int": 5 } } |
| 654 | + } |
| 655 | + } |
| 656 | + """ |
| 657 | + with pytest.raises(AssertionError, match="The col name of a Column should be a str but got"): |
| 658 | + _pl_tree_to_sql(json.loads(bad_type_expr)) |
0 commit comments