alamb commented on code in PR #17521:
URL: https://github.com/apache/datafusion/pull/17521#discussion_r2343741787


##########
datafusion/sqllogictest/test_files/push_down_filter.slt:
##########
@@ -395,3 +395,28 @@ order by t1.k, t2.v;
 ----
 1 1 1
 10000000 10000000 10000000
+
+# Regression test for https://github.com/apache/datafusion/issues/17512
+
+query I
+COPY (
+    SELECT arrow_cast('2025-01-01T00:00:00Z'::timestamptz, 
'Timestamp(Microsecond, Some("UTC"))') AS start_timestamp
+)
+TO 'test_files/scratch/push_down_filter/17512.parquet'
+STORED AS PARQUET;
+----
+1
+
+statement ok
+CREATE EXTERNAL TABLE records STORED AS PARQUET LOCATION 
'test_files/scratch/push_down_filter/17512.parquet';
+
+query I
+SELECT 1
+FROM (
+    SELECT start_timestamp
+    FROM records
+    WHERE start_timestamp <= '2025-01-01T00:00:00Z'::timestamptz
+) AS t
+WHERE t.start_timestamp::time < '00:00:01'::time;

Review Comment:
   > They need to take the f into account. The optimizer that does that is 
called "unwrap cast in comparison" AFAICT. 
   
   Yes I agree (assuming `f` is a `cast` expression)
   
   > The find_most_restrictive_predicate should operate only on predicates 
comparing column c directly, ignoring those which compare f(c).
   
   That is my understanding of what this PR does. I am not sure if you are just 
confirming this change or if you are proposing / suggesting something more
   
   



##########
datafusion/optimizer/src/simplify_expressions/simplify_predicates.rs:
##########
@@ -239,8 +239,99 @@ fn find_most_restrictive_predicate(
 fn extract_column_from_expr(expr: &Expr) -> Option<Column> {
     match expr {
         Expr::Column(col) => Some(col.clone()),
-        // Handle cases where the column might be wrapped in a cast or other 
operation

Review Comment:
   👍 



-- 
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

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

Reply via email to