ClickHouse / ClickHouse/clickhouse-java

JDBC Driver: PreparedStatement counts ? placeholders inside SQL comments (regression since 0.1.36)

オープン
#2,835 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Java
スター
1.6k
フォーク
636
平均マージ
2日 23時間
マージ済み PR(30日)
29

説明

## Problem

When a SQL query contains parameters inside comments (e.g. `-- filter by ${param}`
which gets replaced with `-- filter by ?` before reaching the driver), the driver
counts those `?` placeholders inside comments as actual parameters.

This causes:
- Old driver (ru.yandex, 0.1.x): `ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2`
- New driver (com.clickhouse, 0.3+): `Parameter index must between 1 and 2 but we got 3`

## Example SQL (after parameter substitution by the application)

```sql
-- filter by ? and ?
SELECT *
FROM my_table
WHERE severity = ?
AND status = ?
```

Driver sees 4 placeholders, application binds 2 values → exception.

## Expected behavior

`?` inside SQL comments (`--` and `/* */`) should be ignored when counting
PreparedStatement parameter placeholders.

## Versions tested

All versions below have this bug:
- 0.2.6
- 0.3.2
- 0.4.6
- 0.5.0
- 0.7.2 (with both `com.clickhouse.jdbc.ClickHouseDriver` and `ru.yandex.clickhouse.ClickHouseDriver`)
- 0.9.8 (with `ClickHouseDriver`, `DriverV1`, and `jdbc_sql_parser=JAVACC/ANTLR4/ANTLR4_PARAMS_PARSER`)

## Working version

`clickhouse-jdbc-0.1.36` (ru.yandex.clickhouse.ClickHouseDriver) correctly ignores
`?` inside comments.

## Environment

- ClickHouse server: 25.3 / 25.8
- Pentaho 9.4 (CDA/PRE data access)
- Java 11

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず、ClickHouseDriver と DriverV1 のパラメータカウントを追跡し、レポートで指定されている jdbc_sql_parser のモードを比較します。-- コメントと /* */ コメントの両方を含むクエリを再現し、その後、コメントの外側にあるプレースホルダーだけがバインド可能であることを示すカバレッジを追加し、報告されているパラメータインデックスエラーが解消されたことを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java, sql
領域
database
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
58/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。