Skip to content

Commit

Permalink
feat: add left,right,outer join module examples
Browse files Browse the repository at this point in the history
  • Loading branch information
zzlk committed Nov 3, 2023
1 parent f89d11a commit f327b02
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
23 changes: 23 additions & 0 deletions hydroflow/examples/modules_outer_join/full_outer_join.hf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
lhs = mod[0] -> tee();
rhs = mod[1] -> tee();

lhs -> [0]joined;
rhs -> [1]joined;

joined = join() -> map(|(k, (lhs, rhs))| (k, (Some(lhs), Some(rhs)))) -> combined;

lhs -> [pos]missed_lhs;
rhs -> map(|(k, _v)| k) -> [neg]missed_lhs;

missed_lhs = anti_join()
-> map(|(k, v)| (k, (Some(v), None)))
-> combined;

rhs -> [pos]missed_rhs;
lhs -> map(|(k, _v)| k) -> [neg]missed_rhs;

missed_rhs = anti_join()
-> map(|(k, v)| (k, (None, Some(v))))
-> combined;

combined = union() -> mod;
16 changes: 16 additions & 0 deletions hydroflow/examples/modules_outer_join/left_outer_join.hf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
lhs = mod[0] -> tee();
rhs = mod[1] -> tee();

lhs -> [0]joined;
rhs -> [1]joined;

joined = join() -> map(|(k, (lhs, rhs))| (k, (lhs, Some(rhs)))) -> combined;

lhs -> [pos]missed;
rhs -> map(|(k, _v)| k) -> [neg]missed;

missed = anti_join()
-> map(|(k, v)| (k, (v, None)))
-> combined;

combined = union() -> mod;
30 changes: 30 additions & 0 deletions hydroflow/examples/modules_outer_join/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use hydroflow::hydroflow_syntax;

pub fn main() {
let mut df = hydroflow_syntax! {
lhs = source_iter([("a", 0), ("b", 1)]) -> tee();
rhs = source_iter([("a", 2), ("c", 3)]) -> tee();

lhs -> [0]inner_join;
rhs -> [1]inner_join;
inner_join = join() -> assert_eq([("a", (0, 2))]);

lhs -> [0]left_outer_join;
rhs -> [1]left_outer_join;
left_outer_join = import!("left_outer_join.hf") -> assert_eq([("a", (0, Some(2))), ("b", (1, None))]);

lhs -> [0]right_outer_join;
rhs -> [1]right_outer_join;
right_outer_join = import!("right_outer_join.hf") -> assert_eq([("a", (Some(0), 2)), ("c", (None, 3))]);

lhs -> [0]full_outer_join;
rhs -> [1]full_outer_join;
full_outer_join = import!("full_outer_join.hf") -> assert_eq([("a", (Some(0), Some(2))), ("b", (Some(1), None)), ("c", (None, Some(3)))]);
};
df.run_available();
}

#[test]
fn test() {
main();
}
6 changes: 6 additions & 0 deletions hydroflow/examples/modules_outer_join/right_outer_join.hf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// flip the lhs and rhs
mod[0] -> [1]left_outer_join;
mod[1] -> [0]left_outer_join;

// flip them back
left_outer_join = import!("left_outer_join.hf") -> map(|(k, (v1, v2))| (k, (v2, v1))) -> mod;
File renamed without changes.

0 comments on commit f327b02

Please sign in to comment.