Skip to content

Commit

Permalink
feat(common): match and replace graph nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
kszucs authored and cpcloud committed Aug 7, 2023
1 parent cbb9b2f commit 78865c0
Show file tree
Hide file tree
Showing 7 changed files with 988 additions and 168 deletions.
13 changes: 8 additions & 5 deletions ibis/backends/polars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ibis.backends.base import BaseBackend, Database
from ibis.backends.polars.compiler import translate
from ibis.backends.polars.datatypes import dtype_to_polars, schema_from_polars
from ibis.common.patterns import Replace
from ibis.util import gen_name, normalize_filename

if TYPE_CHECKING:
Expand Down Expand Up @@ -347,12 +348,14 @@ def compile(
):
node = expr.op()
ctx = self._context

if params:
replacements = {}
for p, v in params.items():
op = p.op() if isinstance(p, ir.Expr) else p
replacements[op] = ibis.literal(v, type=op.dtype).op()
node = node.replace(replacements)
params = {param.op(): value for param, value in params.items()}
rule = Replace(
ops.ScalarParameter,
lambda op, ctx: ops.Literal(value=params[op], dtype=op.dtype),
)
node = node.replace(rule)
expr = node.to_expr()

node = expr.as_table().op()
Expand Down
Loading

0 comments on commit 78865c0

Please sign in to comment.