File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -162,6 +162,9 @@ def _pl_tree_to_sql(tree: _ExpressionTree) -> str:
162162 if node_type == "Cast" :
163163 cast_tree = tree [node_type ]
164164 assert isinstance (cast_tree , dict ), f"A { node_type } should be a dict but got { type (cast_tree )} "
165+ if cast_tree .get ("options" ) != "NonStrict" :
166+ msg = f"Only NonStrict casts can be safely unwrapped, got { cast_tree .get ('options' )!r} "
167+ raise NotImplementedError (msg )
165168 cast_expr = cast_tree ["expr" ]
166169 assert isinstance (cast_expr , dict ), f"A { node_type } should be a dict but got { type (cast_expr )} "
167170 return _pl_tree_to_sql (cast_expr )
Original file line number Diff line number Diff line change @@ -739,3 +739,9 @@ def test_polars_lazy_pushdown_decimal_with_cast(self):
739739
740740 assert lazy_df .filter (pl .col ("a" ) == 1 ).collect ().to_dicts () == [{"a" : 1 }]
741741 assert lazy_df .filter (pl .col ("a" ) > 1 ).collect ().to_dicts () == [{"a" : 10 }, {"a" : 100 }]
742+
743+ def test_explicit_cast_not_pushed_down (self ):
744+ """Explicit user .cast() (Strict) should not be pushed down - falls back to Polars."""
745+ # pl.col("a").cast(pl.Int64) produces a Strict Cast node
746+ expr = pl .col ("a" ).cast (pl .Int64 ) > 5
747+ invalid_filter (expr )
You can’t perform that action at this time.
0 commit comments