Repository navigation
fix(common-utils): return timestamps for min/max on date and time columns - #3722
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 3c45a2b The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🔵 Tier 2 — Low RiskSmall, isolated change with no API route or data model modifications. Why this tier:
Additional context: touches the query rendering engine lightly (70 lines, under the 150-line bar for Tier 4) Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns. Stats
|
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
PR Review
2 finding(s): 🔴 0 P0/P1 · 🟡 2 P2 · 🔵 0 P3 2 posted as inline comment(s) on the changed lines. Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides. |
Deep ReviewThe change is small and well-scoped: a new ✅ No critical issues found. 🟡 P2 — recommended
🔵 P3 nitpicks (2)
Reviewers (3): correctness/orchestrator analysis, maintainability, performance. Testing gaps:
Note: synthesized from the reviewers that had reported when output was required; the correctness, testing, api-contract, adversarial, security, TypeScript, previous-comments, agent-native, and learnings reviewers were dispatched but had not yet returned, so their findings are not reflected above. No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
E2E Test Results✅ All tests passed • 479 passed • 1 skipped • 1079s
Tests ran across 4 shards in parallel. |
…series number tiles (review P2)
|
Related to #3543? |
pulpdrew
left a comment
There was a problem hiding this comment.
LGTM. Nice tests! IMO they'd be even nicer if they were .int integration tests that hit clickhouse for real, instead
|
@pulpdrew updated to link to issue, and added an integration test |
| const unsafeExpr = { | ||
| UNSAFE_RAW_SQL: | ||
| isAny || isNone ? `${expr}` : `toFloat64OrDefault(toString(${expr}))`, | ||
| isAny || isNone || keepValueType |
There was a problem hiding this comment.
🟡 P2 — Uncast min/max over zero matching rows returns 1970-01-01 epoch instead of an empty value
When keepValueType is set, render the -OrNull form (minOrNull/maxOrNull, minIfOrNull/maxIfOrNull) so no matching rows gives NULL. This applies to the plain, -If and sample-weighted min/max branches. Also add an integration case for a group with no rows matching the aggCondition. Right now minIf(Timestamp, cond)/max(Timestamp) over no rows returns the type default, 1970-01-01 00:00:00. That is easy to read as a real timestamp, where the old 0 was clearly empty. It is common in MCP: mergeWhereIntoSelectItems (packages/api/src/mcp/tools/query/table.ts:327) puts the top-level where into every select's aggCondition. So clickstack_table with groupBy ServiceName, where StatusCode:Error and max(Timestamp) reports "last error 1970-01-01T00:00:00Z" for services that have no errors. A number tile over an empty range shows the epoch too.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
| ); | ||
| } catch (e) { | ||
| console.warn( | ||
| `Column ${valueExpression} lookup failed while choosing min/max cast`, |
There was a problem hiding this comment.
🟡 P2 — MV-optimized query with a SimpleAggregateFunction(min|max, DateTime) column still casts to 0
Unwrap SimpleAggregateFunction(<fn>, T) before calling classifyTimestampType, or have the MV rewrite carry the source column's type. Otherwise the same tile gives a timestamp on the base table and 0 when MV optimization applies. For SimpleAggregateFunction columns, getAggregateMergeFunction (packages/common-utils/src/core/materializedViews.ts:266-269) keeps aggFn as min/max and swaps valueExpression to the MV column. The column type is then SimpleAggregateFunction(max, DateTime64(9)), which stripTypeWrappers doesn't unwrap and classifyTimestampType rejects, so the cast comes back.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
Summary
minandmaxon a Date, DateTime, or DateTime64 column (e.g.Timestamp) returned0typedFloat64. The renderer casts every aggregate's value withtoFloat64OrDefault(toString(expr)), and a DateTime's string form doesn't parse as a float. MCP agents hit this withclickstack_tableand worked around it by putting raw SQL inaggFn: "none", one of the paths that pushes them towardclickstack_sql.min/max now skip the cast when the value is a bare column whose type, from the cached column metadata, is Date/DateTime/DateTime64. The result keeps the column type, and MCP serializes it as an ISO string like
"2026-11-18T10:00:02.123456789Z".The cast is kept everywhere else:
SpanAttributes['x'], expressions, unknown columnsavg,sum,quantile, …) on a date columnCharts keep the cast because they need a numeric value: pie/bar drop non-numeric columns and would throw "No value columns found", and a time-bucketed result's chart formatter treats the first date column as the time bucket. They still show
0for min/max of a timestamp, as onmain. Ratios and formulas do arithmetic on the value, which ClickHouse rejects for dates, and a multi-series number tile shows the first numeric column, so a date series would be silently skipped.Screenshots or video
How to reproduce
Starting point:
yarn app:dev:localconnected to the demo server, oryarn dev.On
main:/chart), pick a Traces source, display type Table.Timestamp. Add series 2: Maximum ofTimestamp. Group byServiceName.0.On this branch:
Timestampshows the latest timestamp.main(no error).Link for ease
How to test on Vercel preview
Preview routes: /chart
Steps:
Timestamp, add a second series with Maximum ofTimestamp, and run the query.0.Tests
New
min/max on date and time columnsblock inrenderChartConfig.test.ts: DateTime64, DateTime,Nullable(Date), backtick-quoted names,-Ifwith an aggCondition, and sample-weighted rendering return the uncast column (these fail onmain); numeric, map-attribute, unknown-column,avg, pie, bar, and time-bucketed cases keep the cast. Existing numeric min/max tests and snapshots are unchanged.References
min/maxof a DateTime is 0, and unknown options such ashavingare silently ignored #3543 (min/maxof a DateTime returns 0). Part 2, silently dropped unknown MCP tool options, is not addressed here.