fn lower_quantifier(
        &mut self,
        quantifier_id: QuantifierId,
        get_outer: expr::MirRelationExpr,
        outer_column_map: &ColumnMap,
        id_gen: &mut IdGen,
    ) -> expr::MirRelationExpr {
        let quantifier = self.model.get_quantifier(quantifier_id);
        let input_box = quantifier.input_box;
        let mut input = self.apply(input_box, get_outer.clone(), outer_column_map, id_gen);

        match &quantifier.quantifier_type {
            QuantifierType::Foreach => {
                // No special handling required
            }
            QuantifierType::Scalar => {
                // Add the machinery to ensure the lowered plan always produce one row,
                // but one row at most, per outer key.
                let col_type = input.typ().column_types.into_last();

                let outer_arity = get_outer.arity();
                // We must determine a count for each `get_outer` prefix,
                // and report an error if that count exceeds one.
                let guarded = input.let_in(id_gen, |_id_gen, get_select| {
                    // Count for each `get_outer` prefix.
                    let counts = get_select.clone().reduce(
                        (0..outer_arity).collect::<Vec<_>>(),
                        vec![expr::AggregateExpr {
                            func: expr::AggregateFunc::Count,
                            expr: expr::MirScalarExpr::literal_ok(Datum::True, ScalarType::Bool),
                            distinct: false,
                        }],
                        None,
                    );
                    // Errors should result from counts > 1.
                    let errors = counts
                        .filter(vec![expr::MirScalarExpr::Column(outer_arity).call_binary(
                            expr::MirScalarExpr::literal_ok(Datum::Int64(1), ScalarType::Int64),
                            expr::BinaryFunc::Gt,
                        )])
                        .project((0..outer_arity).collect::<Vec<_>>())
                        .map(vec![expr::MirScalarExpr::literal(
                            Err(expr::EvalError::MultipleRowsFromSubquery),
                            col_type.clone().scalar_type,
                        )]);
                    // Return `get_select` and any errors added in.
                    get_select.union(errors)
                });
                // append Null to anything that didn't return any rows
                let default = vec![(Datum::Null, col_type.nullable(true))];
                input = get_outer.lookup(id_gen, guarded, default);
            }
            _ => panic!("Unsupported quantifier type"),
        }

        input
    }
/// Lowers the given quantifier by applying it to the outer relation.
Lowers the given quantifier by applying it to the outer relation.
Lowers the given quantifier by applying it to the outer relation .
fn lower_quantifier(
        &mut self,
        quantifier_id: QuantifierId,
        get_outer: expr::MirRelationExpr,
        outer_column_map: &ColumnMap,
        id_gen: &mut IdGen,
    ) -> expr::MirRelationExpr {
        let quantifier = self.model.get_quantifier(quantifier_id);
        let input_box = quantifier.input_box;
        let mut input = self.apply(input_box, get_outer.clone(), outer_column_map, id_gen);
        match &quantifier.quantifier_type {
            QuantifierType::Foreach => {
                // No special handling required
            }
            QuantifierType::Scalar => {
                // Add the machinery to ensure the lowered plan always produce one row,
                // but one row at most, per outer key.
                let col_type = input.typ().column_types.into_last();
                let outer_arity = get_outer.arity();
                // We must determine a count for each `get_outer` prefix,
                // and report an error if that count exceeds one.
                let guarded = input.let_in(id_gen, |_id_gen, get_select| {
                    // Count for each `get_outer` prefix.
                    let counts = get_select.clone().reduce(
                        (0..outer_arity).collect::<Vec<_>>(),
                        vec![expr::AggregateExpr {
                            func: expr::AggregateFunc::Count,
                            expr: expr::MirScalarExpr::literal_ok(Datum::True, ScalarType::Bool),
                            distinct: false,
                        }],
                        None,
                    );
                    // Errors should result from counts > 1.
                    let errors = counts
                        .filter(vec![expr::MirScalarExpr::Column(outer_arity).call_binary(
                            expr::MirScalarExpr::literal_ok(Datum::Int64(1), ScalarType::Int64),
                            expr::BinaryFunc::Gt,
                        )])
                        .project((0..outer_arity).collect::<Vec<_>>())
                        .map(vec![expr::MirScalarExpr::literal(
                            Err(expr::EvalError::MultipleRowsFromSubquery),
                            col_type.clone().scalar_type,
                        )]);
                    // Return `get_select` and any errors added in.
                    get_select.union(errors)
                });
                // append Null to anything that didn't return any rows
                let default = vec![(Datum::Null, col_type.nullable(true))];
                input = get_outer.lookup(id_gen, guarded, default);
            }
            _ => panic!("Unsupported quantifier type"),
        }
        input
    }
fn lower_quantifier ( & mut self , quantifier_id : QuantifierId , get_outer : expr :: MirRelationExpr , outer_column_map : & ColumnMap , id_gen : & mut IdGen , ) -> expr :: MirRelationExpr { let quantifier = self . model . get_quantifier ( quantifier_id ) ; let input_box = quantifier . input_box ; let mut input = self . apply ( input_box , get_outer . clone ( ) , outer_column_map , id_gen ) ; match & quantifier . quantifier_type { QuantifierType :: Foreach => { // No special handling required } QuantifierType :: Scalar => { // Add the machinery to ensure the lowered plan always produce one row, // but one row at most, per outer key. let col_type = input . typ ( ) . column_types . into_last ( ) ; let outer_arity = get_outer . arity ( ) ; // We must determine a count for each `get_outer` prefix, // and report an error if that count exceeds one. let guarded = input . let_in ( id_gen , | _id_gen , get_select | { // Count for each `get_outer` prefix. let counts = get_select . clone ( ) . reduce ( ( 0 .. outer_arity ) . collect :: < Vec < _ > > ( ) , vec ! [ expr AggregateExpr { func expr AggregateFunc Count expr expr MirScalarExpr literal_ok ( Datum True ScalarType Bool ) distinct false } ] , None , ) ; // Errors should result from counts > 1. let errors = counts . filter ( vec ! [ expr MirScalarExpr Column ( outer_arity ) call_binary ( expr MirScalarExpr literal_ok ( Datum Int64 ( 1 ) ScalarType Int64 ) expr BinaryFunc Gt ) ] ) . project ( ( 0 .. outer_arity ) . collect :: < Vec < _ > > ( ) ) . map ( vec ! [ expr MirScalarExpr literal ( Err ( expr EvalError MultipleRowsFromSubquery ) col_type clone ( ) scalar_type ) ] ) ; // Return `get_select` and any errors added in. get_select . union ( errors ) } ) ; // append Null to anything that didn't return any rows let default = vec ! [ ( Datum Null col_type nullable ( true ) ) ] ; input = get_outer . lookup ( id_gen , guarded , default ) ; } _ => panic ! ( " " ) , } input }
Lowers the given quantifier by applying it to the outer relation.
Lowers the given quantifier by applying it to the outer relation .
&mut self
quantifier_id
QuantifierId
get_outer
expr::MirRelationExpr
outer_column_map
&ColumnMap
id_gen
&mut IdGen
&mut self
quantifier_id
QuantifierId
get_outer
expr::MirRelationExpr
outer_column_map
&ColumnMap
id_gen
&mut IdGen