Clickhouse: Support for `<`, `<=`, `>`, `>=` operator with ASOF join.

Created on 5 Aug 2019  路  3Comments  路  Source: ClickHouse/ClickHouse

It would be useful, for example, if we want to join previous entity state to current state.

CREATE TABLE states (
    entity_id UUID
    state INT8
    timestamp DateTime
)
SELECT state AS cur_state, prev_state FROM states ASOF JOIN states AS prev_states ON states.entity_id = prev_states.entity_id AND states.timestamp > prev_states.timestamp ORDER BY timestamp DESC LIMIT 10;
comp-joins feature

Most helpful comment

7282

All 3 comments

+1. Need this functionality.

How to implement:

  1. Add less and greater logic here https://github.com/yandex/ClickHouse/blob/master/dbms/src/Interpreters/CollectJoinOnKeysVisitor.cpp#L72
  2. Save kind of comparison here https://github.com/yandex/ClickHouse/blob/master/dbms/src/Interpreters/CollectJoinOnKeysVisitor.cpp#L81
  3. Passthrough the kind of comparison into AnalyzedJoin (it would be avaliable in Join class as field)
  4. Change hardcoded >= logic depending on saved comparison type here https://github.com/yandex/ClickHouse/blob/master/dbms/src/Interpreters/RowRefs.cpp#L75
  5. Make tests for corner cases.

At the point 4 upper_bound is >=, lower_bound would be equal to <=. For strict comparison we need "upper_bound/lower_bound but not equal" logic.

7282

Was this page helpful?
0 / 5 - 0 ratings