Skip to content

Unsupported JOIN ON conditions #43814

Closed
Closed

Description

@miroha

Hello.

Yesterday I wrote about unexpected behaviour: #43747

Some preview again:
I've some table. Each date contains data snapshots for 15 days ago and 50 days ahead. If I'll go to my table and run SELECT WHERE date = '2022-01-27' I will get rows with block_date from 2022-01-13 to 2022-03-18. I need to build reports per month, so at date = '2022-01-27' I need to see rows with block_date from 2022-01-01 to 2022-01-31. I can find this missing information if I go back a day. At date = '2022-01-26' I will find information for block_date = 2022-01-12 and so on.

For example I've these rows:

|date        | block_date   | total_plan_volume_grp20  |
| -----------| ------------ | -------------------------|
| 2022-01-27 | 2022-01-14   | 10                       |
| 2022-01-27 | 2022-01-13   | 20                       |
| 2022-01-26 | 2022-01-14   | 10                       | 
| 2022-01-26 | 2022-01-13   | 20                       | 
| 2022-01-26 | 2022-01-12   | 30                       | 
| 2022-01-25 | 2022-01-14   | 10                       | 
| 2022-01-25 | 2022-01-13   | 20                       |  
| 2022-01-25 | 2022-01-12   | 30                       | 
| 2022-01-25 | 2022-01-11   | 40                       |

I expect to get this:

|date        |block_date    |total_plan_volume_grp20    |
| --------   | ------------ | ------------------------- |
| 2022-01-27 | 2022-01-14   | 10                        |
| 2022-01-27 | 2022-01-13   | 20                        |
| 2022-01-27 | 2022-01-12   | 30                        |
| 2022-01-27 | 2022-01-11   | 40                        |
| 2022-01-26 | 2022-01-14   | 10                        |
| 2022-01-26 | 2022-01-13   | 20                        | 
| 2022-01-26 | 2022-01-12   | 30                        | 
| 2022-01-26 | 2022-01-11   | 40                        | 
| 2022-01-25 | 2022-01-14   | 10                        |
| 2022-01-25 | 2022-01-13   | 20                        | 
| 2022-01-25 | 2022-01-12   | 30                        | 
| 2022-01-25 | 2022-01-11   | 40                        | 

Early we used PostgreSQL and query below works fine with Postge. I tried to modify query a bit and run it in ClickHouse.
I decided to change my first query to replace WHERE EXISTS. Now I run with JOIN, but it still doesn't work and I'm stuck.

Query:

SELECT 
DISTINCT 
t1.date, t2.block_date, t2.total_plan_volume_grp20
  FROM connectors.historical_data_storage t1 
  JOIN connectors.historical_data_storage t2 ON t2.date BETWEEN t1.date-15 AND t1.date    

It throws an error:
Unsupported JOIN ON conditions. Unexpected 't2.date >= (date - 15)': While processing t2.date >= (date - 15). (INVALID_JOIN_ON_EXPRESSION) (version 22.10.2.11 (official build))

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions