alamb opened a new issue, #6790:
URL: https://github.com/apache/arrow-datafusion/issues/6790

   ### Describe the bug
   
   A query is failing that it can't find a column which exists
   
   This was reported by a customer of IOx
   
   ### To Reproduce
   
   DataFusion CLI v27.0.0
   
   ```sql
   ❯
   create table "MyTable" (
   "A"    VARCHAR,
   "B"    VARCHAR,
   "time" timestamp
   );
   0 rows in set. Query took 0.002 seconds.
   
   ❯ 
   SELECT "A", COUNT(DISTINCT("B"))
   FROM "MyTable"
   WHERE time >= now() - interval '1 month'
   GROUP BY "A"
   LIMIT 10;
   
   Optimizer rule 'simplify_expressions' failed
   caused by
   Schema error: No field named mytable."A". Valid fields are "MyTable.A", 
"COUNT(DISTINCT MyTable.B)".
   ```
   
   
   
   ### Expected behavior
   
   The query should plan successfully (but return no rows)
   ```sql
   +-----------+---------------------------+
   | MyTable.A | COUNT(DISTINCT MyTable.B) |
   +-----------+---------------------------+
   +-----------+---------------------------+
   ```
   
   ### Additional context
   
   The query works fine in version `26.0.0` 👍 
   
   ```sql
   DataFusion CLI v26.0.0
   ❯ create table "MyTable" (
   "A"    VARCHAR,
   "B"    VARCHAR,
   "time" timestamp
   );
   
   0 rows in set. Query took 0.003 seconds.
   ❯ SELECT "A", COUNT(DISTINCT("B"))
   FROM "MyTable"
   WHERE time >= now() - interval '1 month'
   GROUP BY "A"
   LIMIT 10;
   
   +-----------+---------------------------+
   | MyTable.A | COUNT(DISTINCT MyTable.B) |
   +-----------+---------------------------+
   +-----------+---------------------------+
   ```
   
   Also if we remove the distinct the query also works:
   
   ```sql
   ❯ SELECT "A", COUNT("B")
   FROM "MyTable"
   WHERE time >= now() - interval '1 month'
   GROUP BY "A"
   LIMIT 10;
   +---+------------------+
   | A | COUNT(MyTable.B) |
   +---+------------------+
   +---+------------------+
   ```


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

Reply via email to