1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
use quote::quote_spanned;
use syn::parse_quote;
use super::{OperatorCategory, OperatorConstraints, WriteContextArgs, RANGE_1};
/// > 2 input streams of type S and T, 1 output stream of type (S, T)
///
/// Forms the multiset cross-join (Cartesian product) of the (possibly duplicated) items in the input streams, returning all
/// tupled pairs regardless of duplicates.
///
/// ```dfir
/// source_iter(vec!["happy", "happy", "sad"]) -> [0]my_join;
/// source_iter(vec!["dog", "cat", "cat"]) -> [1]my_join;
/// my_join = cross_join_multiset() -> sort() -> assert_eq([
/// ("happy", "cat"),
/// ("happy", "cat"),
/// ("happy", "cat"),
/// ("happy", "cat"),
/// ("happy", "dog"),
/// ("happy", "dog"),
/// ("sad", "cat"),
/// ("sad", "cat"),
/// ("sad", "dog"), ]);
/// ```
pub const CROSS_JOIN_MULTISET: OperatorConstraints = OperatorConstraints {
name: "cross_join_multiset",
categories: &[OperatorCategory::MultiIn],
hard_range_inn: &(2..=2),
soft_range_inn: &(2..=2),
hard_range_out: RANGE_1,
soft_range_out: RANGE_1,
num_args: 0,
persistence_args: &(0..=2),
type_args: &(0..=1),
is_external_input: false,
has_singleton_output: false,
flo_type: None,
ports_inn: Some(|| super::PortListSpec::Fixed(parse_quote! { 0, 1 })),
ports_out: None,
input_delaytype_fn: |_| None,
write_fn: |wc @ &WriteContextArgs {
op_span,
ident,
inputs,
..
},
diagnostics| {
let mut output = (super::join_multiset::JOIN_MULTISET.write_fn)(wc, diagnostics)?;
let lhs = &inputs[0];
let rhs = &inputs[1];
let write_iterator = output.write_iterator;
output.write_iterator = quote_spanned!(op_span=>
let #lhs = #lhs.map(|a| ((), a));
let #rhs = #rhs.map(|b| ((), b));
#write_iterator
let #ident = #ident.map(|((), (a, b))| (a, b));
);
Ok(output)
},
};