askalt opened a new issue, #14326: URL: https://github.com/apache/datafusion/issues/14326
Consider the following case: We have an exec with schema = [a,b,c] and an equivalent class: a == b. Then we project [a+c,b+c] from it. As a==b we can conclude that a+c==b+c, but that case does not work for now, i.e. the next test fails: ```rust #[tokio::test] async fn test_stat_projection_equivalent_classes() -> Result<()> { // - columns: [a, b, c]. // - "a" and "b" in the same equivalence class. // - then after a+c, b+c projection col(0) and col(1) must be // in the same class too. let schema = Arc::new(Schema::new(vec![ Field::new("a", DataType::Int32, false), Field::new("b", DataType::Int32, false), Field::new("c", DataType::Int32, false), ])); let mut eq_properties = EquivalenceProperties::new(Arc::clone(&schema)); eq_properties.add_equal_conditions(&col("a", &schema)?, &col("b", &schema)?)?; let properties = PlanProperties::new( eq_properties, Partitioning::UnknownPartitioning(1), EmissionType::Both, Boundedness::Bounded, ); let projection = ProjectionExec::try_new( vec![ ( binary( col("a", &schema)?, Operator::Plus, col("c", &schema)?, &schema, )?, "a+c".to_owned(), ), ( binary( col("b", &schema)?, Operator::Plus, col("c", &schema)?, &schema, )?, "b+c".to_owned(), ), ], Arc::new(PropertiesExec { properties, schema: Arc::clone(&schema), }), )?; let actual_properties = projection.properties(); let eq_group = actual_properties.eq_properties.eq_group(); assert!(!eq_group.is_empty()); Ok(()) } ``` It is because current code that builds new classes just compares source expressions: https://github.com/apache/datafusion/blob/09a0844b562df808784d7a23de0b794f13246a93/datafusion/physical-expr/src/equivalence/class.rs#L588-L595 Instead, I propose to build normalized mapping (where each source expression is normalized against existing equivalence classes) and then and then make a comparison. -- 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: github-unsubscr...@datafusion.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org