IMSMWU/RClickhouse

Join on the same key is not possible

Closed this issue · 2 comments

vrkrv commented

Hi!

I use pkg v0.5.2. When I join tables on the same key it results in error:

db1 %>%
  select(a1, a2) %>%
  left_join(db2 %>% select(a1, b1, by = c("a1"))
# Error in select(conn@ptr, statement) : 
#  DB::Exception: Column 'a1' is ambiguous

If I run the same statement with explain:

db1 %>%
  select(a1, a2) %>%
  left_join(db2 %>% select(a1, b1, by = c("a1")) %>%
  explain
# <SQL>
# SELECT `a1`, `a2`, `b1`
# FROM db1 
#   ALL LEFT JOIN (SELECT `a1`, `b1`
# FROM `tmp_newgroup`) 
#   ON (`a1` = `a1`)
# <PLAN>

I can join two DBs if I rename key in one of them and provide explicit by statement.
The cause of the problem is clear -- sql translator do not name left/right tables.
In sql correct statment shall look like this:

SELECT A.`a1`, A.`a2`, B.`b1`
FROM db1 A
  ALL LEFT JOIN (SELECT `a1`, `b1`
FROM `tmp_newgroup`) B 
  ON (A.`a1` = B.`a1`)

Thank you very much for creating the issue. We will try to fix it as quickly as possible.

Hello :)
it looks like a prior modification that was added to address Issue #44 was responsible. Since then multiple updates have been made to Clickhouse and apparently made some of the code obsolete. For now, I removed parts of 52ba27e that caused the problem. I will continue to test and investigate if this resolved the issue entirely and also doesn't break anything from #44