karlovnv opened a new issue, #12065:
URL: https://github.com/apache/datafusion/issues/12065

   ### Describe the bug
   
   Queries with FILTER WHERE don't work when parameters are provided.
   
   For instance, `SELECT SUM (amount) FILTER (WHERE year = $1) FROM payments` 
will fail on physical planning.
   
   Query like `COUNT (CASE WHEN year = $1 then amount ELSE NULL END)` fails as 
well.
   
   ### To Reproduce
   
   
   ```rust
   async fn main() -> Result<()> {
       //  generate test memtable with 30 u64 columns and some data
       let table1 = generate_memtable(30)?;
   
       let cfg = SessionConfig::new()
           .set("datafusion.sql_parser.dialect", "PostgreSQL".into());
   
       let ctx = SessionContext::new_with_config(cfg);
   
       ctx.register_table("table1", Arc::new(table1))?;
   
       let dataframe = ctx.sql(
           "select count (f_0) filter (where f_1 > $1) from table1"
           ).await?
           
.with_param_values(ParamValues::List(vec![ScalarValue::from(10u64)]));
   
       // fails here on physical planning:
       let result = dataframe?.collect().await.unwrap();
   
       let record_batch = result.first().unwrap();
   
       dbg!(record_batch.columns());
   
       Ok(())
   }
   ```
   
   This fails with error:
   
   ```
   thread 'main' panicked at filter-where-repro.rs:46:45:
   called `Result::unwrap()` on an `Err` value: 
   Context("type_coercion", SchemaError(FieldNotFound { field: Column { 
relation: None, name: "count(table1.f_0) FILTER (WHERE table1.f_1 > $1)" }, 
valid_fields: [Column { relation: None, name: "count(table1.f_0) FILTER (WHERE 
table1.f_1 > UInt64(10))" }] }, Some("")))
   ```
   
   ### Expected behavior
   
   _No response_
   
   ### Additional context
   
   _No response_


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

Reply via email to