diff --git a/ibis/backends/polars/compiler.py b/ibis/backends/polars/compiler.py index 13612de1ff213..534976997c513 100644 --- a/ibis/backends/polars/compiler.py +++ b/ibis/backends/polars/compiler.py @@ -1258,18 +1258,19 @@ def execute_union(op, **kw): @translate.register(ops.Intersection) def execute_intersection(op, **kw): - with pl.SQLContext( + ctx = kw.get("ctx") + ctx.register_many( frames={ "left": translate(op.left, **kw), "right": translate(op.right, **kw), } - ) as ctx: - sql = ( - sg.select(STAR) - .from_(sg.to_identifier("left", quoted=True)) - .intersect(sg.select(STAR).from_(sg.to_identifier("right", quoted=True))) - ) - result = ctx.execute(sql.sql()) + ) + sql = ( + sg.select(STAR) + .from_(sg.to_identifier("left", quoted=True)) + .intersect(sg.select(STAR).from_(sg.to_identifier("right", quoted=True))) + ) + result = ctx.execute(sql.sql(Polars), eager=False) if op.distinct is True: return result.unique() return result @@ -1277,18 +1278,19 @@ def execute_intersection(op, **kw): @translate.register(ops.Difference) def execute_difference(op, **kw): - with pl.SQLContext( + ctx = kw.get("ctx") + ctx.register_many( frames={ "left": translate(op.left, **kw), "right": translate(op.right, **kw), } - ) as ctx: - sql = ( - sg.select(STAR) - .from_(sg.to_identifier("left", quoted=True)) - .except_(sg.select(STAR).from_(sg.to_identifier("right", quoted=True))) - ) - result = ctx.execute(sql.sql()) + ) + sql = ( + sg.select(STAR) + .from_(sg.to_identifier("left", quoted=True)) + .except_(sg.select(STAR).from_(sg.to_identifier("right", quoted=True))) + ) + result = ctx.execute(sql.sql(Polars), eager=False) if op.distinct is True: return result.unique() return result