FANNG1 commented on code in PR #588: URL: https://github.com/apache/iceberg-rust/pull/588#discussion_r1738539115
########## crates/integrations/datafusion/src/physical_plan/scan.rs: ########## @@ -138,3 +150,231 @@ async fn get_batch_stream( Ok(Box::pin(stream)) } + +/// convert DataFusion filters ([`Expr`]) to an iceberg [`Predicate`] +/// if none of the filters could be converted, return `None` +/// if the conversion was successful, return the converted predicates combined with an AND operator +fn convert_filters_to_predicate(filters: &[Expr]) -> Option<Predicate> { + filters + .iter() + .filter_map(expr_to_predicate) + .reduce(Predicate::and) +} + +/// Recuresivly converting DataFusion filters ( in a [`Expr`]) to an Iceberg [`Predicate`]. +/// +/// This function currently handles the conversion of DataFusion expression of the following types: +/// +/// 1. Simple binary expressions (e.g., "column < value") +/// 2. Compound AND expressions (e.g., "x < 1 AND y > 10") +/// 3. Compound OR expressions (e.g., "x < 1 OR y > 10") +/// +/// For AND expressions, if one part of the expression can't be converted, +/// the function will still return a predicate for the part that can be converted. +/// For OR expressions, if any part can't be converted, the entire expression +/// will fail to convert. +/// +/// # Arguments +/// +/// * `expr` - A reference to a DataFusion [`Expr`] to be converted. +/// +/// # Returns +/// +/// * `Some(Predicate)` if the expression could be successfully converted. +/// * `None` if the expression couldn't be converted to an Iceberg predicate. +fn expr_to_predicate(expr: &Expr) -> Option<Predicate> { Review Comment: Maybe we could use `visitor pattern` to make code more cleaner to avoid code bomb if supporting more expressions. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org