Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clickhouse: JOIN with [ANY, ALL, ASOF, GLOBAL] fails. #1606

Closed
pkit opened this issue May 12, 2023 · 6 comments
Closed

clickhouse: JOIN with [ANY, ALL, ASOF, GLOBAL] fails. #1606

pkit opened this issue May 12, 2023 · 6 comments

Comments

@pkit
Copy link
Contributor

pkit commented May 12, 2023

ANY

SELECT
    number,
    joined
FROM system.numbers
ANY LEFT JOIN
(
    SELECT
        number * 2 AS number,
        (number * 10) + 1 AS joined
    FROM system.numbers
    LIMIT 10
) AS js2 USING (number)
LIMIT 10

Invalid expression / Unexpected token. Line 5, Col: 3.
  SELECT
    number,
    joined
FROM system.numbers
🔻ANY🔻 LEFT JOIN
(
    SELECT
        number * 2 AS number,
        (number * 10) + 1 AS joined
    FROM s

ASOF

SELECT count(*)
FROM
(
    SELECT
        1 AS id,
        [1, 2, 3] AS arr
) AS sessions
ASOF LEFT JOIN
(
    SELECT
        1 AS session_id,
        4 AS id
) AS visitors ON (visitors.session_id <= sessions.id) AND (arrayFirst(a -> a, arrayMap(a -> a, sessions.arr)) = visitors.id)

Invalid expression / Unexpected token. Line 8, Col: 4.
  SELECT count(*)
FROM
(
    SELECT
        1 AS id,
        [1, 2, 3] AS arr
) AS sessions
🔻ASOF🔻 LEFT JOIN
(
    SELECT
        1 AS session_id,
        4 AS id
) AS visitors ON (visitors.session_

GLOBAL

SELECT
    n,
    j1,
    j2
FROM
(
    SELECT toFloat64(dummy + 2) AS n
    FROM remote('127.0.0.{2,3}', system.one)
) AS jr1
GLOBAL ANY LEFT JOIN
(
    SELECT
        number / 3 AS n,
        number AS j1,
        'Hello' AS j2
    FROM system.numbers
    LIMIT 10
) AS jr2 USING (n)
LIMIT 10

Invalid expression / Unexpected token. Line 10, Col: 6.
  2
FROM
(
    SELECT toFloat64(dummy + 2) AS n
    FROM remote('127.0.0.{2,3}', system.one)
) AS jr1
🔻GLOBAL🔻 ANY LEFT JOIN
(
    SELECT
        number / 3 AS n,
        number AS j1,
        'Hello' AS j2
   

See docs on JOIN here https://clickhouse.com/docs/en/sql-reference/statements/select/join

@pkit pkit changed the title clickhouse: JOIN with [ANY, ASOF, GLOBAL] fails. clickhouse: JOIN with [ANY, ASOF, GLOBAL] fails. May 12, 2023
@pkit pkit changed the title clickhouse: JOIN with [ANY, ASOF, GLOBAL] fails. clickhouse: JOIN with [ANY, ALL, ASOF, GLOBAL] fails. May 12, 2023
@pkit
Copy link
Contributor Author

pkit commented May 12, 2023

ALL

SELECT *
FROM
(
    SELECT reinterpretAsString(number + reinterpretAsUInt8('A')) AS k
    FROM system.numbers
    LIMIT 10
) AS js1
ALL LEFT JOIN
(
    SELECT
        reinterpretAsString(intDiv(number, 2) + reinterpretAsUInt8('A')) AS k,
        number AS joined
    FROM system.numbers
    LIMIT 10
) AS js2 USING (k)
ORDER BY
    k ASC,
    joined ASC

Invalid expression / Unexpected token. Line 8, Col: 3.
  erpretAsString(number + reinterpretAsUInt8('A')) AS k
    FROM system.numbers
    LIMIT 10
) AS js1
🔻ALL🔻 LEFT JOIN
(
    SELECT
        reinterpretAsString(intDiv(number, 2) + reinterpretAsUInt8('A')) AS 

@tobymao
Copy link
Owner

tobymao commented May 12, 2023

left any and left asof join already supported, the documentation does not support any left

@pkit
Copy link
Contributor Author

pkit commented May 12, 2023

@pkit
Copy link
Contributor Author

pkit commented May 12, 2023

Just to add:

$ find ClickHouse/tests/ -name '*.sql' | xargs grep ' ANY LEFT ' | wc -l
139
$ find ClickHouse/tests/ -name '*.sql' | xargs grep ' LEFT ANY ' | wc -l
1

@tobymao
Copy link
Owner

tobymao commented May 12, 2023

out of scope for now. it's a bigger change and i don't feel like doing it. if you want to do a pr, i'll help you through it

@pkit
Copy link
Contributor Author

pkit commented May 12, 2023

Cool, will check out the code then. Thanks!

adrianisk pushed a commit to adrianisk/sqlglot that referenced this issue Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants