apache / apache/shardingsphere

When connecting to ClickHouse Server or Doris FE using MySQL JDBC Driver, SQL is always parsed using the MySQL dialect

Open
#36,081 5 comments 0 reactions 1 assignee Claimed by @linghengqian View on GitHub
db: ClickHouse db: Doris in: infra status: blocked type: bug
Dominant language
Java
Stars
20.8k
Forks
6.9k
Avg merge
11h 35m
Merged PRs (30d)
326

Description

## Bug Report

**For English only**, other languages will not accept.

Before report a bug, make sure you have:

- Searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues).
- Read documentation: [ShardingSphere Doc](https://shardingsphere.apache.org/document/current/en/overview).

Please pay attention on issues you submitted, because we maybe need more details.
If no response anymore and we cannot reproduce it on current information, we will **close it**.

Please answer these questions before submitting your issue. Thanks!

### Which version of ShardingSphere did you use?

- https://github.com/apache/shardingsphere/commit/ee301e61ca29f5bfd92976bdabafbcb137dd8593

### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

- `ShardingSphere-JDBC`

### Expected behavior

- When connecting to Doris FE using MySQL JDBC Driver, SQL is parsed using the Doris dialect. This involves the module `org.apache.shardingsphere:shardingsphere-parser-sql-doris`.
- When connecting to ClickHouse Server using MySQL JDBC Driver, SQL is parsed using the ClickHouse dialect. This involves the module `org.apache.shardingsphere:shardingsphere-parser-sql-clickhouse`.

### Actual behavior

- When connecting to ClickHouse Server or Doris FE using MySQL JDBC Driver, SQL is always parsed using the MySQL dialect. This involves the module `org.apache.shardingsphere:shardingsphere-parser-sql-mysql`.

### Reason analyze (If you can)

- For example, when using MySQL JDBC Driver's `jdbc:mysql://localhost:9030/demo_ds_0` to connect to Doris FE in the shardingsphere jdbc configuration file, `org.apache.shardingsphere.infra.database.core.type.DatabaseTypeFactory#get()` will find two `org.apache.shardingsphere.infra.database.core.type.DatabaseType`, which are,

- `org.apache.shardingsphere.infra.database.mysql.type.MySQLDatabaseType`
- `org.apache.shardingsphere.infra.database.doris.DorisDatabaseType`

- Since both `org.apache.shardingsphere:shardingsphere-parser-sql-doris` and `org.apache.shardingsphere:shardingsphere-parser-sql-mysql` are on the classpath, shardingsphere will almost always use the class corresponding to the MySQL dialect, namely `org.apache.shardingsphere.sql.parser.mysql.parser.MySQLParserFacade`.

- `org.apache.shardingsphere.sql.parser.doris.parser.DorisParserFacade` is completely ignored.
- The metadata obtained by the MySQL JDBC Driver should be appropriately judged in `org.apache.shardingsphere.infra.database.DatabaseTypeEngine#getStorageType(javax.sql.DataSource)`. I'm referring to exactly https://doris.apache.org/docs/3.0/db-connect/database-connect and https://clickhouse.com/docs/interfaces/mysql .

```shell
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 236
Server version: 5.7.99 Doris version doris-2.0.3-rc06-37d31a5
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
```

```shell
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 20.2.1.1-ClickHouse

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
```

- `org.apache.shardingsphere.infra.database.clickhouse.type.ClickHouseDatabaseType` happens to lack support for MySQL Interface.

### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

```shell
vfox add java
vfox install java@24.0.2-graalce
vfox use --global java@24.0.2-graalce

git clone git@github.com:apache/shardingsphere.git
cd ./shardingsphere/
./mvnw -PgenerateMetadata -e -T 1C clean verify
```

### Example codes for reproduce this issue (such as a github link).

- This is actually an undocumented bug in `org.apache.shardingsphere.test.natived.jdbc.databases.DorisFETest` from the master branch. An early investigation came from https://github.com/apache/shardingsphere/issues/29052 .
- By the way, I don't know if MariaDB has this bug. It seems that the unit tests for MariaDB integration intentionally use the MySQL dialect.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.