peter-toth commented on code in PR #11197:
URL: https://github.com/apache/datafusion/pull/11197#discussion_r1663008804


##########
datafusion/optimizer/src/common_subexpr_eliminate.rs:
##########
@@ -1799,4 +1803,34 @@ mod test {
         assert!(result.len() == 1);
         Ok(())
     }
+
+    #[test]
+    fn test_short_circuits() -> Result<()> {
+        let table_scan = test_table_scan()?;
+
+        let extracted_short_circuit = 
col("a").eq(lit(0)).or(col("b").eq(lit(0)));
+        let not_extracted_short_circuit_leg = (col("a") + col("b")).eq(lit(0));
+        let plan = LogicalPlanBuilder::from(table_scan.clone())
+            .project(vec![
+                extracted_short_circuit.clone().alias("c1"),
+                extracted_short_circuit.alias("c2"),
+                col("c")
+                    .gt(lit(0))
+                    .or(not_extracted_short_circuit_leg.clone())
+                    .alias("c3"),
+                col("c")
+                    .gt(lit(1))
+                    .or(not_extracted_short_circuit_leg)
+                    .alias("c4"),
+            ])?
+            .build()?;
+
+        let expected = "Projection: __common_expr_1 AS c1, __common_expr_1 AS 
c2, test.c > Int32(0) OR test.a + test.b = Int32(0) AS c3, test.c > Int32(1) OR 
test.a + test.b = Int32(0) AS c4\
+        \n  Projection: test.a = Int32(0) OR test.b = Int32(0) AS 
__common_expr_1, test.a, test.b, test.c\
+        \n    TableScan: test";
+
+        assert_optimized_plan_eq(expected, plan, None);
+
+        Ok(())
+    }

Review Comment:
   I've adjusted the test case to test both legs of an OR expression: 
https://github.com/apache/datafusion/pull/11197/commits/8b75d82fbd837be723a43cb4edd6cf88369e4d18.
 In this PR none of them are extraceted, but the after that follow-up PR the 
srurely evaluated first leg (called `not_extracted_short_circuit_leg_1` now) 
will be extracted.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to