You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@inikolaev Hey Igor! That's great! Please let me know how it goes and if you have any questions regarding implementation. Please don't hesitate to contact me directly in our Slack. Thanks!
@inikolaev That's a great start, some things to consider :
Is a pool needed ? Since the protocol is http based isn't it sufficient to share the same ClickHouse instance ?
For query cancelling:
the clickhouse http api allows you to specify a query_id query string parameter which can then be killed via `KILL QUERY WHERE query_id = ${query_id}`
you can pass this via the clickhouse api as a second argument to the querying function, for example { queryOptions : { query_id: getNextQueryId() } . and could implement getNextQueryId within the driver to return a GUID prefixed with cubejs for example
@paveltiunov are there any existing tests to test driver implementations, or query implementations ? I did a quick scan of the codebase but couldn't find anything.
I've just submitted a PR to @inikolaev which includes a fix to the query to return array of object, as well as a docker-compose based setup of clickhouse and a test file to verify the driver implementation
@inikolaev That's a great start, some things to consider :
Is a pool needed ? Since the protocol is http based isn't it sufficient to share the same ClickHouse instance ?
I wasn't sure whether Node`s http/https modules do any connection pooling on their own.
For query cancelling:
the clickhouse http api allows you to specify a query_id query string parameter which can then be killed via `KILL QUERY WHERE query_id = ${query_id}`
you can pass this via the clickhouse api as a second argument to the querying function, for example { queryOptions : { query_id: getNextQueryId() } . and could implement getNextQueryId within the driver to return a GUID prefixed with cubejs for example
Good idea! I was following the MySQL driver which seems to simply cancel all queries running for too long. @paveltiunov what is the intended behaviour? The implementation for Postgres seems to be cancelling the currently running query.
@inikolaev It looks like the clickhouse driver only supports raw sql strings, so parameter substitution is going to have to be done to support parameterised query calls like driver.query("select ?", [1])
@inikolaev I have pushed a change to my branch which starts on the implementation of a ClickHouseQuery class see packages/cubejs-schema-compiler/adapter/ClickHouseQuery.js
to test, run docker-compose up in the packages/cubejs-schema-compiler folder (will convert to test containers at some point) then run
yarn test --grep DataSchemaCompiler which works apart from the 'export import test' which I skipped
yarn test --grep "simple join" which doesn't work due to ClickHouse not supporting OR in join expressions - this is an interesting challenge.
error is :
Error: Invalid expression for JOIN ON. Expected equals expression, got (`visitors.created_at_date` = q_1.`visitors.created_at_date`) OR (isNull(`visitors.created_at_date`) AND isNull(q_1.`visitors.created_at_date`)).
Supported syntax: JOIN ON Expr([table.]column, ...) = Expr([table.]column, ...) [AND Expr([table.]column, ...) = Expr([table.]column, ...) ...] (version 19.5.2.6 (official build))
I edited packages/cubejs-schema-compiler/test/DataSchemaCompilerTest.js and packages/cubejs-schema-compiler/test/GraphBuilderTest.js to use a new ClickHouseDbRunner instead of the DbRunner which is based on postgresql. Ideally the test suite will run both versions, but this is more a quick way of testing which parts of ClickHouse work and which don't
Hey guys! Great team play here! Well done! 👍 @cameronbraid There's no universal test suite for drivers but the idea is great! I think worth adding an issue where we can discuss it. @inikolaev Yeah. MySQL cancel implementation is a little bit awkward. Should use CONNECTION_ID() instead of killing all the problematic processes. If you can obtain some query/process id on or before query execution and then kill it by id that's ideal implementation.
Ok, seems like it only sets nulls for non-primitive types - at lease when I added string column I started to get null as a value for it. Also it worked without session_id - I guess it failed for you because you try to set it with SET join_use_nulls = 1 which tries to set this setting on session level and fails if there's no session_id.
I could set session_id as well if it's really necessary, it's not a big deal. The only question is whether we win anything from it.
There looks to be a bug in the ClickHouse join when you join on the first column in the table. It should use a Nullable type in the results, but is using Int8 instead of Nullable(Int8)
set join_use_nulls = 1;
drop database temp_1556476999691;
CREATE database temp_1556476999691;
CREATE TABLE temp_1556476999691.a (a Int32, x Nullable(Int32)) ENGINE Memory;
CREATE TABLE temp_1556476999691.b (b Int32, x Nullable(Int32)) ENGINE Memory;
INSERT INTO temp_1556476999691.a VALUES (1, 1), (2, 2), (3, 3);
INSERT INTO temp_1556476999691.b VALUES (2, 2), (3, 3), (4, 4);
SELECT a.a as a, b.b as b FROM temp_1556476999691.a LEFT OUTER JOIN temp_1556476999691.b ON a.a = b.b FORMAT JSON;
SELECT a.x as ax, b.x as bx FROM temp_1556476999691.a LEFT OUTER JOIN temp_1556476999691.b ON a.x = b.x FORMAT JSON;
It looks like the session error I was having was not due to my change to using join_use_nulls in the query, but rather that I was using temporary tables which require a session. So there is no need to use sessions with the driver generally, however we may wish to add an option to use them if people want to use temporary tables, which are great for testing since they dropped automatically when the session ends
set join_use_nulls = 1;
drop database temp_1556476999691;
CREATE database temp_1556476999691;
CREATE TABLE temp_1556476999691.a (a Int32, x Nullable(Int32), value Int32) ENGINE Memory;
CREATE TABLE temp_1556476999691.b (b Int32, x Nullable(Int32), value Int32) ENGINE Memory;
INSERT INTO temp_1556476999691.a VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3);
INSERT INTO temp_1556476999691.b VALUES (2, 2, 2), (3, 3, 3), (4, 4, 4);
SELECT a.a as a, b.b as b, a.value as aValue, b.value as bValue FROM temp_1556476999691.a LEFT OUTER JOIN temp_1556476999691.b ON a.a = b.b;
SELECT a.x as ax, b.x as bx, a.value as aValue, b.value as bValue FROM temp_1556476999691.a LEFT OUTER JOIN temp_1556476999691.b ON a.x = b.x;
It looks like the session error I was having was not due to my change to using join_use_nulls in the query, but rather that I was using temporary tables which require a session. So there is no need to use sessions with the driver generally, however we may wish to add an option to use them if people want to use temporary tables, which are great for testing since they dropped automatically when the session ends
It might actually make sense to enable session so that it would be consistent with other databases. It's a quick fix, I will just do it now :)
On Mon, 29 Apr 2019 at 17:14, Igor Nikolaev ***@***.***> wrote:
It looks like the session error I was having was not due to my change to
using join_use_nulls in the query, but rather that I was using temporary
tables which require a session. So there is no need to use sessions with
the driver generally, however we may wish to add an option to use them if
people want to use temporary tables, which are great for testing since they
dropped automatically when the session ends
It might actually make sense to enable session so that it would be
consistent with other databases. It's a quick fix, I will just do it now :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#93 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAFEFFMH32OV2BDBDNKIWPTPS2N6RANCNFSM4HIGALXQ>
.
What is the scope of a session for a driver in cube.js though ? …
On Mon, 29 Apr 2019 at 17:14, Igor Nikolaev @.***> wrote: It looks like the session error I was having was not due to my change to using join_use_nulls in the query, but rather that I was using temporary tables which require a session. So there is no need to use sessions with the driver generally, however we may wish to add an option to use them if people want to use temporary tables, which are great for testing since they dropped automatically when the session ends It might actually make sense to enable session so that it would be consistent with other databases. It's a quick fix, I will just do it now :) — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#93 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFEFFMH32OV2BDBDNKIWPTPS2N6RANCNFSM4HIGALXQ .
I don't know if there is one, but I think usually there's a session per connection in other databases.
Activity
paveltiunov commentedon Apr 24, 2019
@cameronbraid Hey Cameron! Thanks for posting this!
Do you have production Clickhouse instance? Do you think you can spearhead Clickhouse driver development if we can help you?
Thanks!
cameronbraid commentedon Apr 25, 2019
I am evaluating both clickhouse and cube.js
So I may not be in the best position to do that.
Though, if I find both of these technologies address our needs I am sure willing to help.
paveltiunov commentedon Apr 25, 2019
@cameronbraid Hey Cameron! Sounds great! In case you can find some time for that here's driver implementation guide: https://github.com/statsbotco/cube.js/blob/master/CONTRIBUTING.md#implementing-driver
inikolaev commentedon Apr 26, 2019
@paveltiunov I'm also looking at ClickHouse + Cube.js and could take a look into implementing a driver.
inikolaev commentedon Apr 26, 2019
I've started some initial work on the driver here: https://github.com/inikolaev/cube.js/tree/clickhouse-driver
I'm using https://github.com/apla/node-clickhouse library to make calls to ClickHouse which uses HTTP interface. I haven't yet tested it though.
paveltiunov commentedon Apr 26, 2019
@inikolaev Hey Igor! That's great! Please let me know how it goes and if you have any questions regarding implementation. Please don't hesitate to contact me directly in our Slack. Thanks!
cameronbraid commentedon Apr 27, 2019
@inikolaev That's a great start, some things to consider :
Is a pool needed ? Since the protocol is http based isn't it sufficient to share the same ClickHouse instance ?
For query cancelling:
`KILL QUERY WHERE query_id = ${query_id}`{ queryOptions : { query_id: getNextQueryId() }. and could implementgetNextQueryIdwithin the driver to return a GUID prefixed with cubejs for examplecameronbraid commentedon Apr 27, 2019
@paveltiunov are there any existing tests to test driver implementations, or query implementations ? I did a quick scan of the codebase but couldn't find anything.
cameronbraid commentedon Apr 27, 2019
I've just submitted a PR to @inikolaev which includes a fix to the query to return array of object, as well as a docker-compose based setup of clickhouse and a test file to verify the driver implementation
inikolaev#1
I'm taking a look at doing a ClickHouseQuery class next
inikolaev commentedon Apr 27, 2019
I wasn't sure whether Node`s http/https modules do any connection pooling on their own.
Good idea! I was following the MySQL driver which seems to simply cancel all queries running for too long. @paveltiunov what is the intended behaviour? The implementation for Postgres seems to be cancelling the currently running query.
cameronbraid commentedon Apr 27, 2019
@inikolaev It looks like the clickhouse driver only supports raw sql strings, so parameter substitution is going to have to be done to support parameterised query calls like driver.query("select ?", [1])
cameronbraid commentedon Apr 27, 2019
@inikolaev I have pushed a change to my branch which starts on the implementation of a
ClickHouseQueryclass seepackages/cubejs-schema-compiler/adapter/ClickHouseQuery.jsto test, run
docker-compose upin thepackages/cubejs-schema-compilerfolder (will convert to test containers at some point) then runyarn test --grep DataSchemaCompilerwhich works apart from the 'export import test' which I skippedyarn test --grep "simple join"which doesn't work due to ClickHouse not supportingORin join expressions - this is an interesting challenge.error is :
I edited
packages/cubejs-schema-compiler/test/DataSchemaCompilerTest.jsandpackages/cubejs-schema-compiler/test/GraphBuilderTest.jsto use a newClickHouseDbRunnerinstead of theDbRunnerwhich is based on postgresql. Ideally the test suite will run both versions, but this is more a quick way of testing which parts of ClickHouse work and which don'tpaveltiunov commentedon Apr 27, 2019
Hey guys! Great team play here! Well done! 👍
@cameronbraid There's no universal test suite for drivers but the idea is great! I think worth adding an issue where we can discuss it.
@inikolaev Yeah. MySQL cancel implementation is a little bit awkward. Should use
CONNECTION_ID()instead of killing all the problematic processes. If you can obtain some query/process id on or before query execution and then kill it by id that's ideal implementation.12 remaining items
inikolaev commentedon Apr 28, 2019
Ok, seems like it only sets nulls for non-primitive types - at lease when I added string column I started to get
nullas a value for it. Also it worked withoutsession_id- I guess it failed for you because you try to set it withSET join_use_nulls = 1which tries to set this setting on session level and fails if there's nosession_id.I could set
session_idas well if it's really necessary, it's not a big deal. The only question is whether we win anything from it.inikolaev commentedon Apr 28, 2019
I pushed changes which enable
join_use_nulls- give it a trycameronbraid commentedon Apr 29, 2019
There looks to be a bug in the ClickHouse join when you join on the first column in the table. It should use a Nullable type in the results, but is using Int8 instead of Nullable(Int8)
first one (same as your example) is broken
Second one, joining on a second column (with the same values) correctly returns ax as Nullable
cameronbraid commentedon Apr 29, 2019
Actually, I think I got that wrong.. it depends on the nullability of the column being joined on. Very strange.
cameronbraid commentedon Apr 29, 2019
It looks like the session error I was having was not due to my change to using join_use_nulls in the query, but rather that I was using temporary tables which require a session. So there is no need to use sessions with the driver generally, however we may wish to add an option to use them if people want to use temporary tables, which are great for testing since they dropped automatically when the session ends
cameronbraid commentedon Apr 29, 2019
Its only an issue with the join column
cameronbraid commentedon Apr 29, 2019
Someone else found the same issue ClickHouse/ClickHouse#3145 (comment)
cameronbraid commentedon Apr 29, 2019
https://den-crane.github.io/CHvsPG.html
inikolaev commentedon Apr 29, 2019
It might actually make sense to enable session so that it would be consistent with other databases. It's a quick fix, I will just do it now :)
cameronbraid commentedon Apr 29, 2019
inikolaev commentedon Apr 29, 2019
I don't know if there is one, but I think usually there's a session per connection in other databases.
feat: clickhouse dialect implementation (#98)
feat: clickhouse dialect implementation (cube-js#98)