Skip to content

Dash in database name is not supported by V2 client #2463

Closed

Description

@k-popov

It looks like parsing of JDBC URL does not support dash (hyphen) in database name. This results in Code: 81. DB::Exception: Database test does not exist. when trying to connect to database named test-dash.

Found in 0.8.4 but this part of code in master is the same.

RegEx at

private static final Pattern URL_REGEXP = Pattern.compile("(https?:)?\\/\\/([\\w\\.\\-]+|\\[[0-9a-fA-F:]+\\]):?([\\d]*)(?:\\/([\\w]+))?\\/?\\??(.*)$");
shows the following when testing:

>>> import re
>>> re.match('(https?:)?\\/\\/([\\w\\.\\-]+|\\[[0-9a-fA-F:]+\\]):?([\\d]*)(?:\\/([\\w]+))?\\/?\\??(.*)$', 'https://host-name:8123/test-dash?param=pampam').groups()
('https:', 'host-name', '8123', 'test', '-dash?param=pampam')

(Tested in python as it was a quick test but I assume \w is the same)
Note the 4th group only has test and -dash is already in 5th group where params should reside.

Adding - to characters set seems to fix parsing:

> re.match('(https?:)?\\/\\/([\\w\\.\\-]+|\\[[0-9a-fA-F:]+\\]):?([\\d]*)(?:\\/([\\w-]+))?\\/?\\??(.*)$', 'https://host-name:8123/test-dash?param=pampam').groups()
('https:', 'host-name', '8123', 'test-dash', 'param=pampam')

Here the 4th group contains full DB name test-dash

There was already a similar issue long ago: #251 but that was for client V1.

Activity

  1. rileythomp commented on Jun 19, 2025

    @rileythomp

    Repro with 0.9.0:

    $ clj -Sdeps '{:deps {com.clickhouse/clickhouse-jdbc {:mvn/version "0.9.0"}}}'
    user=> (let [conn (java.sql.DriverManager/getConnection "jdbc:clickhouse://localhost:8123/my-db" "default" "")
                 stmt (.prepareStatement conn "SELECT * FROM `my-table`;")]
             (let [rs (.executeQuery stmt)]
               (while (.next rs)
                 (println (.getString rs 1)))))
    Execution error (ServerException) at com.clickhouse.client.api.internal.HttpAPIClientHelper/readError (HttpAPIClientHelper.java:371).
    Code: 81. DB::Exception: Database my does not exist. (UNKNOWN_DATABASE) (version 25.2.2.39 (official build)) 
    
  2. enqueue commented on Jul 2, 2025

    @enqueue
    Contributor

    Relying on own regular expressions is not so nice. I would vote for using Java API for parsing URIs or URLs.

  3. added this to the 0.9.1 milestone on Jul 2, 2025
  4. enqueue commented on Jul 7, 2025

    @enqueue
    Contributor

    @chernser Wow, that was fast 🚀 Please run integration tests. I am still seeing some errors locally.

  5. chernser commented on Jul 7, 2025

    @chernser
    Contributor

    Will do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions