ClickHouse: dateDiff counts unit boundaries but is parsed without date_part_boundary

オープン 初心者向け
#9,477 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
clickhouse, python
領域
databases

調査の方向性

ClickHouse パーサーでの dateDiff の処理を見つけ、date_part_boundary を設定する BigQuery、Snowflake、MySQL、DuckDB のパーサーと比較してください。まず、ClickHouse の日付関数に関するパーサーとそのテストを探します。解析された DateDiff の引数を True に更新し、issue の例を検証して、パーサーに絞ったテストを追加するか実行してください。

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

説明

ClickHouse's dateDiff counts unit boundaries crossed, but the ClickHouse dialect doesn't set date_part_boundary on the DateDiff it builds:

import sqlglot

node = sqlglot.parse_one("SELECT dateDiff('month', a, b)", read="clickhouse").expressions[0]
node.args.get("date_part_boundary")
# None

ClickHouse documents: "The difference is calculated using relative units. For example, the difference between 2021-12-29 and 2022-01-01 is 3 days for unit day, 1 month for unit month and 1 year for unit year."

Expected: date_part_boundary=True. That's how the BigQuery, Snowflake, MySQL and DuckDB parsers mark their boundary-counting date differences, and generators that honour it (for example Doris, which writes TIMESTAMPDIFF(MONTH, DATE_TRUNC(a, 'MONTH'), DATE_TRUNC(b, 'MONTH'))) would then keep ClickHouse's meaning.

Docs: https://clickhouse.com/docs/reference/functions/regular-functions/date-time-functions (dateDiff)

Checked on main (c321d9f). I used an LLM (Claude) to help narrow this down and write it up.

主要言語
Python
スター
9.8k
フォーク
1.5k
平均マージ
10時間 54分
マージ済み PR(30日)
310

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

tobymao/sqlglot のほかの issue

tobymao/sqlglot の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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