Skip to content

Clickhouse support#8491

Closed
tsl-karlp wants to merge 15 commits intometabase:masterfrom
twosixlabs:enhancement/clickhouse_driver
Closed

Clickhouse support#8491
tsl-karlp wants to merge 15 commits intometabase:masterfrom
twosixlabs:enhancement/clickhouse_driver

Conversation

@tsl-karlp
Copy link
Copy Markdown

Beginnings of ClickHouse driver. Thanks to @b.mukvich for the initial work!

I had trouble running the tests. Not sure how to run just these new tests.

@tsl-karlp tsl-karlp changed the title Enhancement/clickhouse driver Clickhouse support Sep 10, 2018
@tsl-karlp tsl-karlp mentioned this pull request Sep 10, 2018
@camsaul
Copy link
Copy Markdown
Member

camsaul commented Sep 10, 2018

@tsl-karlp WRT to this error

# env ENGINES=h2,clickhouse lein test
... snip....
INSERT FAILED:
["INSERT INTO venues (name, latitude, longitude, price, category_id) VALUES (?, 10.0646, -165.374, 3, 4)" "Red Medicine"]

ClickHouseException:
 Message: ClickHouse exception, code: 27, host: localhost, port: 8123; Code: 27, e.displayText() = DB::Exception: Cannot parse input: expected \t before: \n: (at row 1)

Row 1:
Column 0,   name: name,        type: String,  parsed text: "Red Medicine"
ERROR: Line feed found where tab is expected. It's like your file has less columns than expected.
And if your file have right number of columns, maybe it have unescaped backslash in value before tab, which cause tab has escaped.

, e.what() = DB::Exception

 SQLState: null
 Error Code: 27

I Googled that error really quick and found this: ClickHouse/ClickHouse#2652. So my guess is it seems like it's trying to insert your rows in CSV format. So perhaps start by looking for the reason it's trying to insert them that way instead of the normal SQL syntax

; :subname (str "//" host ":" port "/" db)}
:subname (str "//" host ":" port)}
(dissoc opts :host :port :db)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the message at the end of this file 😉

@tsl-karlp
Copy link
Copy Markdown
Author

Thanks, @camsaul !

I don't think Clickhouse itself supports the normal SQL syntax for insertion. The clickhouse-jdbc wrapper, when using PreparedStatements, will POST something like:

INSERT INTO test FORMAT CSVWithNames
column1, column2, column3
1, 1, 1
2, 2, 2

Can the tests be modified to use PreaparedStatements, or should the Clickhouse tests have their own way of inserting the data?

@camsaul
Copy link
Copy Markdown
Member

camsaul commented Sep 10, 2018

Yeah it seems you might need to write a custom implementation of load-data! for Clickhouse so you can insert data in a way it likes

@tsl-karlp
Copy link
Copy Markdown
Author

@camsaul :

Yeah it seems you might need to write a custom implementation of load-data! for Clickhouse so you can insert data in a way it likes

Is there a good example of doing this in the code?

@camsaul
Copy link
Copy Markdown
Member

camsaul commented Sep 10, 2018

Not really, all of the other SQL drivers support normal SQL INSERT syntax in some form or another. But It shouldn't be too hard.

@Slach
Copy link
Copy Markdown

Slach commented Sep 11, 2018

guys, thanks for your great work

@tsl-karlp
Copy link
Copy Markdown
Author

Unfortunately, we lack the bandwidth and Clojure experience to finish this feature. We'll gladly hand it off to more capable hands now.

@ei-grad
Copy link
Copy Markdown
Contributor

ei-grad commented Oct 17, 2018

I have got my hands on this, and found that the latest code in twosixlabs/metabase@acbb5ab doesn't compile because db.spec/clickhouse was used in metabase.driver.clickhouse/connection-details->spec. Fixed, squashed/rebased on current master, added some (mostly cosmetic) stuff. Tests still need the custom load-data!, and it still throws the NullPointerException with unreadable stacktrace when trying to execute a query via metabase web UI (but the good news are - the appropriate query in the ClickHouse is actually executed). Working on it. Clojure is fun, got into it last night.

My 50 cents about docs/developers-guide.md - it is a bit unclear in sense it is missing a straight and sufficient sequence of commands to get the working build from the ground. There is a ./bin/build, but it failed. The main problem was I had a JDK version 10, but I had some other obstacles too, which could have been resolved easier if there was a sequence of commands.

Also, the clickhouse-jdbc URI parsing should be fixed, since (as of version 0.1.42) it doesn't allow the hypens in the database name, and (as it looks for me) has a broken the default database name selection logic if it is not specified in URI.

ei-grad pushed a commit to ei-grad/metabase that referenced this pull request Oct 17, 2018
[Andrew Grigorev: squashed commits from twosixlabs:enhancement/clickhouse_driver]
Signed-off-by: Andrew Grigorev <[email protected]>
@Slach
Copy link
Copy Markdown

Slach commented Oct 18, 2018

@ei-grad thank you for your work!

@ei-grad ei-grad mentioned this pull request Oct 18, 2018
ei-grad pushed a commit to ei-grad/metabase that referenced this pull request Nov 26, 2018
[Andrew Grigorev: squashed commits from twosixlabs:enhancement/clickhouse_driver]
Signed-off-by: Andrew Grigorev <[email protected]>
@tlrobinson
Copy link
Copy Markdown
Contributor

Hey all,

Thank you for this PR and apologies for the long delay responding. We've recently done some work to support drivers as plugins in Metabase and as of the next release (v0.32) we will be asking driver developers to first publish new drivers in their own repositories (typically named metabase-*-driver). If the driver fully passes the driver tests we will link to it from our documentation, and if a driver gains significant usage we will consider merging it into Metabase itself.

Here is some documentation about publishing a driver as a plugin in a separate repository: https://github.com/metabase/metabase/wiki/Writing-a-Driver:-Packaging-a-Driver-&-Metabase-Plugin-Basics#drivers-shipped-as-3rd-party-plugins

Here are two example drivers: https://github.com/metabase/sudoku-driver https://github.com/metabase/crate-driver

We still have some work to do on the documentation. You can follow progress and provide feedback on that here: #9348

Thank you.

@tlrobinson
Copy link
Copy Markdown
Contributor

By the way, I noticed there's another Clickhouse driver: #9469 You all may want to consider consolidating efforts.

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

Successfully merging this pull request may close these issues.

6 participants