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

Uploads not working for versions using the new JDBC2 clickhouse-java driver. #284

Open
wotbrew opened this issue Jan 30, 2025 · 1 comment · May be fixed by #286
Open

Uploads not working for versions using the new JDBC2 clickhouse-java driver. #284

wotbrew opened this issue Jan 30, 2025 · 1 comment · May be fixed by #286
Labels
bug Something isn't working

Comments

@wotbrew
Copy link

wotbrew commented Jan 30, 2025

Describe the bug

Uploading a .csv crashes with recent versions of the driver.

Steps to reproduce

  1. download the EE metabase.jar

    • I used 0.52.8
  2. download latest clickhouse driver

    • I used 1.52.0
  3. setup metabase EE, add a clickhouse cloud database.

    • I used a free trial cloud instance
  4. Goto admin settings -> uploads, enable uploads for the clickhouse database (schema probably doesnt matter, any will do)

  5. Exit admin, in your personal collection upload a .csv. I used a simple foo\n42 .csv with one column and row.

Image

Expected behaviour

The .csv is uploaded

Error log

Upload error details
There were some errors while uploading csv3.csv:

An SQLException was provoked by the following failure: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0

and in the logs:

{:message
 "An SQLException was provoked by the following failure: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0"}

Configuration

Environment

  • metabase-clickhouse-driver version: 1.52.0
  • metabase-clickhouse-driver configuration: clickhouse cloud
  • Metabase version: 0.52.8
  • OS: MacOS 15.2

ClickHouse server

  • ClickHouse Server version: Cloud Version 24.10
@wotbrew wotbrew added the bug Something isn't working label Jan 30, 2025
@wotbrew
Copy link
Author

wotbrew commented Jan 30, 2025

My understanding is this is due to a difference in parameter styles between clickhouse-java JDBC1 and JDBC2. e.g There are no parameter placeholders in the drivers/insert-into! sql on L237. Somehow this worked with the previous JDBC driver.

This causes the above crash as the allocated object array is of size zero.

It can be fixed by giving the sql statement a number of parameters like so:

Index: src/metabase/driver/clickhouse.clj
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/metabase/driver/clickhouse.clj b/src/metabase/driver/clickhouse.clj
--- a/src/metabase/driver/clickhouse.clj	(revision 7f6f95a4f0e95d54f0331e62c9251478f32b070a)
+++ b/src/metabase/driver/clickhouse.clj	(date 1738246351954)
@@ -234,7 +234,9 @@
      db-id
      {:write? true}
      (fn [^java.sql.Connection conn]
-       (let [sql (format "INSERT INTO %s (%s)" (quote-name table-name) (str/join ", " (map quote-name column-names)))]
+       (let [sql (format "INSERT INTO %s (%s) VALUES (%s)" (quote-name table-name)
+                         (str/join ", " (map quote-name column-names))
+                         (str/join ", " (repeat (count column-names) "?")))]
          (with-open [ps (.prepareStatement conn sql)]
            (doseq [row values]
              (when (seq row)

wotbrew added a commit to wotbrew/metabase-clickhouse-driver that referenced this issue Feb 4, 2025
clickhouse-java no longer accepts implied parameters on insert.
We now generate JDBC parameter placeholders.

Fixes ClickHouse#284
@wotbrew wotbrew linked a pull request Feb 4, 2025 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant