Skip to content

Support Cast node in pushdown logic#298

Open
evertlammerts wants to merge 2 commits intov1.5-variegatafrom
cast-node-support
Open

Support Cast node in pushdown logic#298
evertlammerts wants to merge 2 commits intov1.5-variegatafrom
cast-node-support

Conversation

@evertlammerts
Copy link
Collaborator

@evertlammerts evertlammerts commented Feb 6, 2026

Related: #98

When the decimal precision is anything other than 38, Polars wraps the expression in a Cast node. _pl_tree_to_sql didn't handle Cast nodes, causing silent pushdown failure. This fix makes sure these nodes get pushed down as well.

import duckdb
import polars as pl
import json

# Create a decimal column with precision != 38
con = duckdb.connect()
rel = con.sql("SELECT a::DECIMAL(20,0) AS a FROM range(10) AS t(a)")

lazy_df = rel.pl(lazy=True)

# This filter works but pushdown silently fails
result = lazy_df.filter(pl.col("a") == 1).collect()
print(f"Result: {len(result)} rows")  # Returns 1 row (correct)

# Polars serialized it as follows
expr = pl.col("a") == 1
tree = json.loads(expr.meta.serialize(format="json"))
print(json.dumps(tree, indent=2))
# Contains: "Cast": {"expr": ..., "dtype": {"Decimal": [20, 0]}, ...}

Note that we have to also check for the strictness of the cast node:

@evertlammerts evertlammerts marked this pull request as ready for review February 6, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant