Skip to content

Commit 9845a3c

Browse files
committed
feat(pyspark): implement Intersection and Difference
1 parent 2bc0b69 commit 9845a3c

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

ibis/backends/pyspark/compiler.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,28 @@ def compile_aggregation(t, expr, scope, timecontext, **kwargs):
423423
@compiles(ops.Union)
424424
def compile_union(t, expr, scope, timecontext, **kwargs):
425425
op = expr.op()
426-
result = t.translate(op.left, scope, timecontext).union(
427-
t.translate(op.right, scope, timecontext)
428-
)
426+
left = t.translate(op.left, scope, timecontext, **kwargs)
427+
right = t.translate(op.right, scope, timecontext, **kwargs)
428+
result = left.union(right)
429429
return result.distinct() if op.distinct else result
430430

431431

432+
@compiles(ops.Intersection)
433+
def compile_intersection(t, expr, scope, timecontext, **kwargs):
434+
op = expr.op()
435+
left = t.translate(op.left, scope, timecontext, **kwargs)
436+
right = t.translate(op.right, scope, timecontext, **kwargs)
437+
return left.intersect(right) if op.distinct else left.intersectAll(right)
438+
439+
440+
@compiles(ops.Difference)
441+
def compile_difference(t, expr, scope, timecontext, **kwargs):
442+
op = expr.op()
443+
left = t.translate(op.left, scope, timecontext, **kwargs)
444+
right = t.translate(op.right, scope, timecontext, **kwargs)
445+
return left.subtract(right) if op.distinct else left.exceptAll(right)
446+
447+
432448
@compiles(ops.Contains)
433449
def compile_contains(t, expr, scope, timecontext, **kwargs):
434450
op = expr.op()

0 commit comments

Comments
 (0)