Bug: ISO timestamps are normalized in chart WHERE filters but not WITH FILL bounds

未关闭
#661 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
clickhouse, typescript

调研方向

Read packages/core/src/modules/report/src/chart-dates.ts and packages/core/src/modules/chart/src/sql.ts, focusing on normalizeBoundary(), dateRangeWhere(), and intervalBucket(). Trace how custom date boundaries reach the WHERE filters and WITH FILL bounds, then inspect nearby tests for coverage. Done when supported inputs produce consistently normalized bounds and regression coverage checks the generated fill parameters.

由索引模型根据 Issue 内容生成。

描述

Summary

Time-series chart queries handle the same custom date range differently in two parts of the generated SQL. The WHERE filters normalize ISO timestamps to ClickHouse date strings, while WITH FILL passes the original ISO strings to toDateTime().

For an input such as 2025-01-15T00:00:00.000Z, this leaves a fractional ISO timestamp in a toDateTime(String) expression and can cause ClickHouse to reject the chart query with Code 6 (CANNOT_PARSE_TEXT).

All dates and identifiers below are synthetic. No application data is required for the SQL example.

Version checked

  • Repository: Openpanel-dev/openpanel
  • Branch: main
  • Commit: a5a6eb7d62c9579620ec5e3fbfd4ce760f3d8073
  • Verification: source inspection and execution of the current date-normalization and SQL-fragment helpers in memory. A full application/database test was not run for this commit.

Steps to reproduce

  1. Use a valid chart request for a project in a local development environment.
  2. Set these custom range fields, keeping the remaining request fields valid:
{
  "range": "custom",
  "interval": "minute",
  "startDate": "2025-01-15T00:00:00.000Z",
  "endDate": "2025-01-15T01:00:00.000Z"
}
  1. Inspect the generated SQL and bound parameters, then execute the query against ClickHouse.

The relevant generated expressions are equivalent to:

-- WHERE: normalized
created_at >= toDateTime('2025-01-15 00:00:00')

-- WITH FILL: original ISO strings
WITH FILL
FROM toStartOfMinute(toDateTime('2025-01-15T00:00:00.000Z'))
TO toStartOfMinute(toDateTime('2025-01-15T01:00:00.000Z'))
STEP toIntervalMinute(1)

In the current implementation these values are bound as String parameters; parameter binding does not normalize their date format.

Minimal SQL example

This isolates the generated fill expression without accessing application tables:

SELECT
  toStartOfMinute(toDateTime('2025-01-15 00:00:00')) AS date,
  count() AS count
FROM numbers(1)
GROUP BY date
ORDER BY date WITH FILL
  FROM toStartOfMinute(toDateTime('2025-01-15T00:00:00.000Z'))
  TO toStartOfMinute(toDateTime('2025-01-15T01:00:00.000Z'))
  STEP toIntervalMinute(1);

Replacing only the fill bounds with 2025-01-15 00:00:00 and 2025-01-15 01:00:00 provides a comparison with consistent formatting. The example is provided for database reproduction; the verification performed on the commit above was limited to helper execution and generated parameters.

Expected behavior

A supported custom date range should be normalized consistently for filtering and gap filling, and the chart query should succeed. Unsupported date formats should be rejected before issuing a database query.

Actual behavior

The generated WHERE parameter is 2025-01-15 00:00:00, but the generated fill parameter remains 2025-01-15T00:00:00.000Z. The latter can produce a ClickHouse date-parsing error instead of a chart result.

Local helper execution confirmed the same unnormalized String bounds for minute, hour, day, week, and month. This confirms SQL generation across those intervals, not five end-to-end database tests.

Relevant source

  • Custom date normalization: normalizeBoundary() expands date-only inputs but returns full timestamp strings unchanged.
  • WHERE date normalization: dateRangeWhere() applies formatClickhouseDate().
  • Fill bounds: intervalBucket() passes the original bounds through sql.string() into toDateTime().
  • Fill construction: chartSeriesQuery() forwards startDate and endDate to the bucket's fill function.

Suggested fix and regression coverage

Normalize custom date boundaries consistently before building both WHERE and WITH FILL, preserving the intended timezone and range semantics. Alternatively, use a consistent typed date-binding/parsing approach for both clauses.

Add regression coverage for ISO timestamps with milliseconds and Z, explicit timezone offsets, date-only inputs, and existing ClickHouse-style date strings. Include a database-backed test for the generated WITH FILL query, in addition to SQL-parameter assertions.

主要语言
TypeScript
星标
7.3k
派生
539
平均合并
1 天 20 小时
30 天内合并 PR
80

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Openpanel-dev/openpanel 的其他 Issue

查看 Openpanel-dev/openpanel 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。