Skip to content

Please support Clickhouse #93

Closed
Closed

Activity

  1. paveltiunov commented on Apr 24, 2019

    @paveltiunov
    Member

    @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!

  2. added
    help wanted
    on Apr 24, 2019
  3. cameronbraid commented on Apr 25, 2019

    @cameronbraid
    ContributorAuthor

    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.

  4. paveltiunov commented on Apr 25, 2019

    @paveltiunov
    Member
  5. inikolaev commented on Apr 26, 2019

    @inikolaev
    Contributor

    @paveltiunov I'm also looking at ClickHouse + Cube.js and could take a look into implementing a driver.

  6. inikolaev commented on Apr 26, 2019

    @inikolaev
    Contributor

    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.

  7. paveltiunov commented on Apr 26, 2019

    @paveltiunov
    Member

    @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!

  8. cameronbraid commented on Apr 27, 2019

    @cameronbraid
    ContributorAuthor

    @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
  9. cameronbraid commented on Apr 27, 2019

    @cameronbraid
    ContributorAuthor

    @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.

  10. cameronbraid commented on Apr 27, 2019

    @cameronbraid
    ContributorAuthor

    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

  11. inikolaev commented on Apr 27, 2019

    @inikolaev
    Contributor

    @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.

  12. cameronbraid commented on Apr 27, 2019

    @cameronbraid
    ContributorAuthor

    @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])

  13. cameronbraid commented on Apr 27, 2019

    @cameronbraid
    ContributorAuthor

    @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

  14. paveltiunov commented on Apr 27, 2019

    @paveltiunov
    Member

    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.

  15. 12 remaining items

  16. inikolaev commented on Apr 28, 2019

    @inikolaev
    Contributor

    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.

  17. inikolaev commented on Apr 28, 2019

    @inikolaev
    Contributor

    I pushed changes which enable join_use_nulls - give it a try

  18. cameronbraid commented on Apr 29, 2019

    @cameronbraid
    ContributorAuthor

    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;
    

    first one (same as your example) is broken

    
    {
    	"meta":
    	[
    		{
    			"name": "a",
    			"type": "Int32"
    		},
    		{
    			"name": "b",
    			"type": "Nullable(Int32)"
    		}
    	],
    
    	"data":
    	[
    		{
    			"a": 1,
    			"b": 0
    		},
    		{
    			"a": 2,
    			"b": 2
    		},
    		{
    			"a": 3,
    			"b": 3
    		}
    	],
    
    	"rows": 3,
    
    	"statistics":
    	{
    		"elapsed": 0.0017359,
    		"rows_read": 6,
    		"bytes_read": 39
    	}
    }
    

    Second one, joining on a second column (with the same values) correctly returns ax as Nullable

    {
    	"meta":
    	[
    		{
    			"name": "ax",
    			"type": "Nullable(Int32)"
    		},
    		{
    			"name": "bx",
    			"type": "Nullable(Int32)"
    		}
    	],
    
    	"data":
    	[
    		{
    			"ax": 1,
    			"bx": null
    		},
    		{
    			"ax": 2,
    			"bx": 2
    		},
    		{
    			"ax": 3,
    			"bx": 3
    		}
    	],
    
    	"rows": 3,
    
    	"statistics":
    	{
    		"elapsed": 0.0013721,
    		"rows_read": 6,
    		"bytes_read": 42
    	}
    }
    
  19. cameronbraid commented on Apr 29, 2019

    @cameronbraid
    ContributorAuthor

    Actually, I think I got that wrong.. it depends on the nullability of the column being joined on. Very strange.

  20. cameronbraid commented on Apr 29, 2019

    @cameronbraid
    ContributorAuthor

    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

  21. cameronbraid commented on Apr 29, 2019

    @cameronbraid
    ContributorAuthor

    Its only an issue with the join column

    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;
    
    ┌─a─┬─b─┬─aValue─┬─bValue─┐
    │ 1 │ 0 │      1 │   ᴺᵁᴸᴸ │
    │ 2 │ 2 │      2 │      2 │
    │ 3 │ 3 │      3 │      3 │
    └───┴───┴────────┴────────┘
    
    ┌─ax─┬───bx─┬─aValue─┬─bValue─┐
    │  1 │ ᴺᵁᴸᴸ │      1 │   ᴺᵁᴸᴸ │
    │  2 │    2 │      2 │      2 │
    │  3 │    3 │      3 │      3 │
    └────┴──────┴────────┴────────┘
    
    
  22. cameronbraid commented on Apr 29, 2019

    @cameronbraid
    ContributorAuthor

    Someone else found the same issue ClickHouse/ClickHouse#3145 (comment)

  23. inikolaev commented on Apr 29, 2019

    @inikolaev
    Contributor

    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 :)

  24. cameronbraid commented on Apr 29, 2019

    @cameronbraid
    ContributorAuthor
  25. inikolaev commented on Apr 29, 2019

    @inikolaev
    Contributor

    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.

  26. added this to the v0.8.3 milestone on May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wanted

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions