pub(crate) fn create_from(mut mfp: MapFilterProject) -> Result<Self, String> {
            let mut lower_bounds = Vec::new();
            let mut upper_bounds = Vec::new();

            let mut temporal = Vec::new();

            // Optimize, to ensure that temporal predicates are move in to `mfp.predicates`.
            mfp.optimize();

            mfp.predicates.retain(|(_position, predicate)| {
                if predicate.contains_temporal() {
                    temporal.push(predicate.clone());
                    false
                } else {
                    true
                }
            });

            for predicate in temporal.into_iter() {
                // Supported temporal predicates are exclusively binary operators.
                if let MirScalarExpr::CallBinary {
                    mut func,
                    mut expr1,
                    mut expr2,
                } = predicate
                {
                    // Attempt to put `MzLogicalTimestamp` in the first argument position.
                    if !expr1.contains_temporal()
                        && *expr2 == MirScalarExpr::CallNullary(NullaryFunc::MzLogicalTimestamp)
                    {
                        std::mem::swap(&mut expr1, &mut expr2);
                        func = match func {
                            BinaryFunc::Eq => BinaryFunc::Eq,
                            BinaryFunc::Lt => BinaryFunc::Gt,
                            BinaryFunc::Lte => BinaryFunc::Gte,
                            BinaryFunc::Gt => BinaryFunc::Lt,
                            BinaryFunc::Gte => BinaryFunc::Lte,
                            x => {
                                return Err(format!(
                                    "Unsupported binary temporal operation: {:?}",
                                    x
                                ));
                            }
                        };
                    }

                    // Error if MLT is referenced in an unsuppported position.
                    if expr2.contains_temporal()
                        || *expr1 != MirScalarExpr::CallNullary(NullaryFunc::MzLogicalTimestamp)
                    {
                        return Err(format!(
                            "Unsupported temporal predicate. Note: `mz_logical_timestamp()` must be directly compared to a numeric non-temporal expression; if it is compared to a non-numeric type, consider casting that type to numeric. Expression found: {:?}",
                            MirScalarExpr::CallBinary { func, expr1, expr2 },
                            ));
                    }

                    // We'll need to use this a fair bit.
                    let decimal_one = MirScalarExpr::literal_ok(
                        Datum::from(Numeric::from(1)),
                        ScalarType::Numeric { scale: None },
                    );

                    // TODO(#7611): Truncate any significant fractional digits
                    // from positive values of `expr2`, while keeping the sign
                    // of negative values intact. (Negative values are never
                    // chosen as valid bounds, so their resultant values matter
                    // little, but we do want to know they were negative.)
                    let expr2_floor = expr2.call_unary(UnaryFunc::FloorNumeric(func::FloorNumeric));

                    // MzLogicalTimestamp <OP> <EXPR2> for several supported operators.
                    match func {
                        BinaryFunc::Eq => {
                            // Lower bound of expr, upper bound of expr+1
                            lower_bounds.push((expr2_floor).clone());
                            upper_bounds
                                .push(expr2_floor.call_binary(decimal_one, BinaryFunc::AddNumeric));
                        }
                        BinaryFunc::Lt => {
                            upper_bounds.push(expr2_floor);
                        }
                        BinaryFunc::Lte => {
                            upper_bounds
                                .push(expr2_floor.call_binary(decimal_one, BinaryFunc::AddNumeric));
                        }
                        BinaryFunc::Gt => {
                            lower_bounds
                                .push(expr2_floor.call_binary(decimal_one, BinaryFunc::AddNumeric));
                        }
                        BinaryFunc::Gte => {
                            lower_bounds.push(expr2_floor);
                        }
                        _ => {
                            return Err(format!(
                                "Unsupported binary temporal operation: {:?}",
                                func
                            ));
                        }
                    }
                } else {
                    return Err(format!(
                        "Unsupported temporal predicate. Note: `mz_logical_timestamp()` must be directly compared to a numeric non-temporal expression; if it is compared to a non-numeric type, consider casting that type to numeric. Expression found: {:?}",
                        predicate,
                        ));
                }
            }

            Ok(Self {
                mfp: SafeMfpPlan { mfp },
                lower_bounds,
                upper_bounds,
            })
        }
/// Partitions `predicates` into non-temporal, and lower and upper temporal bounds.
///
/// The first returned list is of predicates that do not contain `mz_logical_timestamp`.
/// The second and third returned lists contain expressions that, once evaluated, lower
/// and upper bound the validity interval of a record, respectively. These second two
/// lists are populared only by binary expressions of the form
/// ```ignore
/// mz_logical_timestamp cmp_op expr
/// ```
/// where `cmp_op` is a comparison operator and `expr` does not contain `mz_logical_timestamp`.
///
/// If any unsupported expression is found, for example one that uses `mz_logical_timestamp`
/// in an unsupported position, an error is returned.
Partitions `predicates` into non-temporal, and lower and upper temporal bounds.
The first returned list is of predicates that do not contain `mz_logical_timestamp`.
The second and third returned lists contain expressions that, once evaluated, lower
and upper bound the validity interval of a record, respectively.

If any unsupported expression is found, for example one that uses `mz_logical_timestamp`
in an unsupported position, an error is returned.
Partitions ` predicates ` into non - temporal and lower and upper temporal bounds . The first returned list is of predicates that do not contain ` mz_logical_timestamp ` . The second and third returned lists contain expressions that once evaluated lower and upper bound the validity interval of a record respectively . If any unsupported expression is found for example one that uses ` mz_logical_timestamp ` in an unsupported position an error is returned .
pub(crate) fn create_from(mut mfp: MapFilterProject) -> Result<Self, String> {
            let mut lower_bounds = Vec::new();
            let mut upper_bounds = Vec::new();
            let mut temporal = Vec::new();
            // Optimize, to ensure that temporal predicates are move in to `mfp.predicates`.
            mfp.optimize();
            mfp.predicates.retain(|(_position, predicate)| {
                if predicate.contains_temporal() {
                    temporal.push(predicate.clone());
                    false
                } else {
                    true
                }
            });
            for predicate in temporal.into_iter() {
                // Supported temporal predicates are exclusively binary operators.
                if let MirScalarExpr::CallBinary {
                    mut func,
                    mut expr1,
                    mut expr2,
                } = predicate
                {
                    // Attempt to put `MzLogicalTimestamp` in the first argument position.
                    if !expr1.contains_temporal()
                        && *expr2 == MirScalarExpr::CallNullary(NullaryFunc::MzLogicalTimestamp)
                    {
                        std::mem::swap(&mut expr1, &mut expr2);
                        func = match func {
                            BinaryFunc::Eq => BinaryFunc::Eq,
                            BinaryFunc::Lt => BinaryFunc::Gt,
                            BinaryFunc::Lte => BinaryFunc::Gte,
                            BinaryFunc::Gt => BinaryFunc::Lt,
                            BinaryFunc::Gte => BinaryFunc::Lte,
                            x => {
                                return Err(format!(
                                    "Unsupported binary temporal operation: {:?}",
                                    x
                                ));
                            }
                        };
                    }
                    // Error if MLT is referenced in an unsuppported position.
                    if expr2.contains_temporal()
                        || *expr1 != MirScalarExpr::CallNullary(NullaryFunc::MzLogicalTimestamp)
                    {
                        return Err(format!(
                            "Unsupported temporal predicate. Note: `mz_logical_timestamp()` must be directly compared to a numeric non-temporal expression; if it is compared to a non-numeric type, consider casting that type to numeric. Expression found: {:?}",
                            MirScalarExpr::CallBinary { func, expr1, expr2 },
                            ));
                    }
                    // We'll need to use this a fair bit.
                    let decimal_one = MirScalarExpr::literal_ok(
                        Datum::from(Numeric::from(1)),
                        ScalarType::Numeric { scale: None },
                    );
                    // TODO(#7611): Truncate any significant fractional digits
                    // from positive values of `expr2`, while keeping the sign
                    // of negative values intact. (Negative values are never
                    // chosen as valid bounds, so their resultant values matter
                    // little, but we do want to know they were negative.)
                    let expr2_floor = expr2.call_unary(UnaryFunc::FloorNumeric(func::FloorNumeric));
                    // MzLogicalTimestamp <OP> <EXPR2> for several supported operators.
                    match func {
                        BinaryFunc::Eq => {
                            // Lower bound of expr, upper bound of expr+1
                            lower_bounds.push((expr2_floor).clone());
                            upper_bounds
                                .push(expr2_floor.call_binary(decimal_one, BinaryFunc::AddNumeric));
                        }
                        BinaryFunc::Lt => {
                            upper_bounds.push(expr2_floor);
                        }
                        BinaryFunc::Lte => {
                            upper_bounds
                                .push(expr2_floor.call_binary(decimal_one, BinaryFunc::AddNumeric));
                        }
                        BinaryFunc::Gt => {
                            lower_bounds
                                .push(expr2_floor.call_binary(decimal_one, BinaryFunc::AddNumeric));
                        }
                        BinaryFunc::Gte => {
                            lower_bounds.push(expr2_floor);
                        }
                        _ => {
                            return Err(format!(
                                "Unsupported binary temporal operation: {:?}",
                                func
                            ));
                        }
                    }
                } else {
                    return Err(format!(
                        "Unsupported temporal predicate. Note: `mz_logical_timestamp()` must be directly compared to a numeric non-temporal expression; if it is compared to a non-numeric type, consider casting that type to numeric. Expression found: {:?}",
                        predicate,
                        ));
                }
            }
            Ok(Self {
                mfp: SafeMfpPlan { mfp },
                lower_bounds,
                upper_bounds,
            })
        }
pub ( crate ) fn create_from ( mut mfp : MapFilterProject ) -> Result < Self , String > { let mut lower_bounds = Vec :: new ( ) ; let mut upper_bounds = Vec :: new ( ) ; let mut temporal = Vec :: new ( ) ; // Optimize, to ensure that temporal predicates are move in to `mfp.predicates`. mfp . optimize ( ) ; mfp . predicates . retain ( | ( _position , predicate ) | { if predicate . contains_temporal ( ) { temporal . push ( predicate . clone ( ) ) ; false } else { true } } ) ; for predicate in temporal . into_iter ( ) { // Supported temporal predicates are exclusively binary operators. if let MirScalarExpr :: CallBinary { mut func , mut expr1 , mut expr2 , } = predicate { // Attempt to put `MzLogicalTimestamp` in the first argument position. if ! expr1 . contains_temporal ( ) && * expr2 == MirScalarExpr :: CallNullary ( NullaryFunc :: MzLogicalTimestamp ) { std :: mem :: swap ( & mut expr1 , & mut expr2 ) ; func = match func { BinaryFunc :: Eq => BinaryFunc :: Eq , BinaryFunc :: Lt => BinaryFunc :: Gt , BinaryFunc :: Lte => BinaryFunc :: Gte , BinaryFunc :: Gt => BinaryFunc :: Lt , BinaryFunc :: Gte => BinaryFunc :: Lte , x => { return Err ( format ! ( " " x ) ) ; } } ; } // Error if MLT is referenced in an unsuppported position. if expr2 . contains_temporal ( ) || * expr1 != MirScalarExpr :: CallNullary ( NullaryFunc :: MzLogicalTimestamp ) { return Err ( format ! ( " " MirScalarExpr CallBinary { func expr1 expr2 } ) ) ; } // We'll need to use this a fair bit. let decimal_one = MirScalarExpr :: literal_ok ( Datum :: from ( Numeric :: from ( 1 ) ) , ScalarType :: Numeric { scale : None } , ) ; // TODO(#7611): Truncate any significant fractional digits // from positive values of `expr2`, while keeping the sign // of negative values intact. (Negative values are never // chosen as valid bounds, so their resultant values matter // little, but we do want to know they were negative.) let expr2_floor = expr2 . call_unary ( UnaryFunc :: FloorNumeric ( func :: FloorNumeric ) ) ; // MzLogicalTimestamp <OP> <EXPR2> for several supported operators. match func { BinaryFunc :: Eq => { // Lower bound of expr, upper bound of expr+1 lower_bounds . push ( ( expr2_floor ) . clone ( ) ) ; upper_bounds . push ( expr2_floor . call_binary ( decimal_one , BinaryFunc :: AddNumeric ) ) ; } BinaryFunc :: Lt => { upper_bounds . push ( expr2_floor ) ; } BinaryFunc :: Lte => { upper_bounds . push ( expr2_floor . call_binary ( decimal_one , BinaryFunc :: AddNumeric ) ) ; } BinaryFunc :: Gt => { lower_bounds . push ( expr2_floor . call_binary ( decimal_one , BinaryFunc :: AddNumeric ) ) ; } BinaryFunc :: Gte => { lower_bounds . push ( expr2_floor ) ; } _ => { return Err ( format ! ( " " func ) ) ; } } } else { return Err ( format ! ( " " predicate ) ) ; } } Ok ( Self { mfp : SafeMfpPlan { mfp } , lower_bounds , upper_bounds , } ) }
Partitions `predicates` into non-temporal, and lower and upper temporal bounds.
Partitions ` predicates ` into non - temporal and lower and upper temporal bounds .
mfp
MapFilterProject
mfp
MapFilterProject