From c5a778934ee82d1c80db6eca7e432644ebd6362f Mon Sep 17 00:00:00 2001 From: BayoNet Date: Thu, 8 Aug 2019 11:37:08 +0300 Subject: [PATCH 1/5] DOCAPI-7984: ASOF JOIN ... ON syntax --- docs/en/query_language/select.md | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/docs/en/query_language/select.md b/docs/en/query_language/select.md index b75524274e1..048284faa6a 100644 --- a/docs/en/query_language/select.md +++ b/docs/en/query_language/select.md @@ -547,18 +547,29 @@ ClickHouse doesn't directly support syntax with commas, so we don't recommend us Tables for `ASOF JOIN` must have an ordered sequence column. This column cannot be alone in a table, and should be one of the data types: `UInt32`, `UInt64`, `Float32`, `Float64`, `Date`, and `DateTime`. -Use the following syntax for `ASOF JOIN`: +You can use the following types of syntax: -``` -SELECT expression_list FROM table_1 ASOF JOIN table_2 USING(equi_column1, ... equi_columnN, asof_column) -``` +- `ASOF JOIN ... ON` -`ASOF JOIN` uses `equi_columnX` for joining on equality (`user_id` in our example) and `asof_column` for joining on the closest match. + ```sql + SELECT expressions_list FROM table_1 ASOF LEFT JOIN table_2 ON equi_cond AND closest_match_cond + ``` + + You can use any number of equality conditions and exactly one closest match condition. For example, `SELECT count() FROM A ASOF LEFT JOIN B ON A.a == B.b AND B.t <= A.t`. There is just `table_2.some_col <= table_1.some_col` and `table_1.some_col >= table2.some_col` types of conditions are available. You cannot apply other conditions like `>`, `!=`. + +- `ASOF JOIN ... USING` + + ```sql + SELECT expressions_list FROM table_1 ASOF JOIN table_2 USING(equi_column1, ... equi_columnN, asof_column) + ``` + + `ASOF JOIN` uses `equi_columnX` for joining on equality and `asof_column` for joining on the closest match with the `table_1.asof_column >= table2.asof_column` condition. The `asof_column` column must be the last in the `USING` clause. For example, consider the following tables: ``` - table_1 table_2 + table_1 table_2 + event | ev_time | user_id event | ev_time | user_id ----------|---------|---------- ----------|---------|---------- ... ... @@ -568,12 +579,9 @@ event_1_2 | 13:00 | 42 event_2_3 | 13:00 | 42 ... ... ``` -`ASOF JOIN` takes the timestamp of a user event from `table_1` and finds an event in `table_2` where the timestamp is closest (equal or less) to the timestamp of the event from `table_1`. Herewith the `user_id` column is used for joining on equality and the `ev_time` column is used for joining on the closest match. - In our example, `event_1_1` can be joined with `event_2_1`, `event_1_2` can be joined with `event_2_3`, but `event_2_2` cannot be joined. +`ASOF JOIN` can take the timestamp of a user event from `table_1` and find an event in `table_2` where the timestamp is closest (equal or less) to the timestamp of the event from `table_1`. Herewith the `user_id` column can be used for joining on equality and the `ev_time` column can be used for joining on the closest match. In our example, `event_1_1` can be joined with `event_2_1`, `event_1_2` can be joined with `event_2_3`, but `event_2_2` cannot be joined. -Implementation details: -- `asof_column` should be last in the `USING` clause. - `ASOF` join is not supported in the [Join](../operations/table_engines/join.md) table engine. To set the default strictness value, use the session configuration parameter [join_default_strictness](../operations/settings/settings.md#settings-join_default_strictness). From 8c5833964d424a076a56ed88bc0527b29de8fda0 Mon Sep 17 00:00:00 2001 From: BayoNet Date: Wed, 21 Aug 2019 12:02:28 +0300 Subject: [PATCH 2/5] Update docs/en/query_language/select.md Co-Authored-By: Ivan Blinkov --- docs/en/query_language/select.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/query_language/select.md b/docs/en/query_language/select.md index 048284faa6a..8611cccb693 100644 --- a/docs/en/query_language/select.md +++ b/docs/en/query_language/select.md @@ -555,7 +555,7 @@ You can use the following types of syntax: SELECT expressions_list FROM table_1 ASOF LEFT JOIN table_2 ON equi_cond AND closest_match_cond ``` - You can use any number of equality conditions and exactly one closest match condition. For example, `SELECT count() FROM A ASOF LEFT JOIN B ON A.a == B.b AND B.t <= A.t`. There is just `table_2.some_col <= table_1.some_col` and `table_1.some_col >= table2.some_col` types of conditions are available. You cannot apply other conditions like `>`, `!=`. + You can use any number of equality conditions and exactly one closest match condition. For example, `SELECT count() FROM A ASOF LEFT JOIN B ON A.a == B.b AND B.t <= A.t`. There is just `table_2.some_col <= table_1.some_col` and `table_1.some_col >= table2.some_col` types of conditions are available. You cannot apply other conditions like `>` or `!=`. - `ASOF JOIN ... USING` From fde0a2f51efc0bb8b86d0cbe51bb798ff1e75c03 Mon Sep 17 00:00:00 2001 From: BayoNet Date: Wed, 21 Aug 2019 12:04:15 +0300 Subject: [PATCH 3/5] Update docs/en/query_language/select.md Co-Authored-By: Ivan Blinkov --- docs/en/query_language/select.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/en/query_language/select.md b/docs/en/query_language/select.md index 8611cccb693..9e6397720f8 100644 --- a/docs/en/query_language/select.md +++ b/docs/en/query_language/select.md @@ -552,7 +552,10 @@ You can use the following types of syntax: - `ASOF JOIN ... ON` ```sql - SELECT expressions_list FROM table_1 ASOF LEFT JOIN table_2 ON equi_cond AND closest_match_cond + SELECT expressions_list + FROM table_1 + ASOF LEFT JOIN table_2 + ON equi_cond AND closest_match_cond ``` You can use any number of equality conditions and exactly one closest match condition. For example, `SELECT count() FROM A ASOF LEFT JOIN B ON A.a == B.b AND B.t <= A.t`. There is just `table_2.some_col <= table_1.some_col` and `table_1.some_col >= table2.some_col` types of conditions are available. You cannot apply other conditions like `>` or `!=`. From 52728493d50c57546eaa311feda0f1b97f5fe9d0 Mon Sep 17 00:00:00 2001 From: BayoNet Date: Wed, 21 Aug 2019 12:04:33 +0300 Subject: [PATCH 4/5] Update docs/en/query_language/select.md Co-Authored-By: Ivan Blinkov --- docs/en/query_language/select.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/en/query_language/select.md b/docs/en/query_language/select.md index 9e6397720f8..fa024aa7cb3 100644 --- a/docs/en/query_language/select.md +++ b/docs/en/query_language/select.md @@ -563,7 +563,10 @@ You can use the following types of syntax: - `ASOF JOIN ... USING` ```sql - SELECT expressions_list FROM table_1 ASOF JOIN table_2 USING(equi_column1, ... equi_columnN, asof_column) + SELECT expressions_list + FROM table_1 + ASOF JOIN table_2 + USING (equi_column1, ... equi_columnN, asof_column) ``` `ASOF JOIN` uses `equi_columnX` for joining on equality and `asof_column` for joining on the closest match with the `table_1.asof_column >= table2.asof_column` condition. The `asof_column` column must be the last in the `USING` clause. From bfbed4100eeeabf735496733b7eaa70f6c62e003 Mon Sep 17 00:00:00 2001 From: BayoNet Date: Wed, 21 Aug 2019 12:05:23 +0300 Subject: [PATCH 5/5] Update docs/en/query_language/select.md Co-Authored-By: Ivan Blinkov --- docs/en/query_language/select.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/en/query_language/select.md b/docs/en/query_language/select.md index fa024aa7cb3..cb3f2bfa92b 100644 --- a/docs/en/query_language/select.md +++ b/docs/en/query_language/select.md @@ -588,7 +588,8 @@ event_1_2 | 13:00 | 42 event_2_3 | 13:00 | 42 `ASOF JOIN` can take the timestamp of a user event from `table_1` and find an event in `table_2` where the timestamp is closest (equal or less) to the timestamp of the event from `table_1`. Herewith the `user_id` column can be used for joining on equality and the `ev_time` column can be used for joining on the closest match. In our example, `event_1_1` can be joined with `event_2_1`, `event_1_2` can be joined with `event_2_3`, but `event_2_2` cannot be joined. -- `ASOF` join is not supported in the [Join](../operations/table_engines/join.md) table engine. +!!! note "Note" + `ASOF` join is **not** supported in the [Join](../operations/table_engines/join.md) table engine. To set the default strictness value, use the session configuration parameter [join_default_strictness](../operations/settings/settings.md#settings-join_default_strictness).