fix(insights): stop toDateTime re-parsing an already-parsed datetime#58684
Draft
sampennington wants to merge 1 commit into
Draft
fix(insights): stop toDateTime re-parsing an already-parsed datetime#58684sampennington wants to merge 1 commit into
sampennington wants to merge 1 commit into
Conversation
A DateTime-typed property is wrapped in toDateTime() by the property-type swapper. When an enclosing toDateTime() also wrapped it, the printer could not see through the (stale-typed) alias to tell the inner value was already a datetime, so it emitted parseDateTime64BestEffortOrNull on a DateTime — ClickHouse rejects this with an illegal-type error and the insight fails. - Property-type swapper now sets the return type on the toDateTime() call it synthesizes for DateTime properties. - The ClickHouse printer looks through Alias nodes when resolving a function's overload, so a stale alias type no longer hides the real type. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
🎭 Playwright didn't run on this PR — your changes touch code that could affect E2E behavior, but Playwright is opt-in via label now to keep CI cost down. Add the Most PRs don't need this. Real regressions still get caught on master and fix-forward. |
Contributor
Author
Automated code reviewReviewed the diff against Correctness
Points worth confirming
Tests
Style / maintainability
Verdict: Ship it — minor test-strengthening suggestions are non-blocking. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Insight queries (Trends, Funnels, etc.) using a DateTime-typed property crashed the whole query with ClickHouse
A value of illegal type ... to function 'parseDateTime64BestEffortOrNull'. Expected: String, got: DateTime64. This was one of the largest deterministic query-builder failures in the Product analytics — insight query failures triage — part of the ongoing effort to reduce deterministic query-builder bugs.The property-type swapper wraps a DateTime property in
toDateTime()to coerce the stored string. When an enclosingtoDateTime()also wrapped that value, the printer couldn't tell the inner result was already a datetime — it resolved the wrapped value's type through anAliaswhose declared type was stale (stillString, from before the swapper rewrote the alias's inner expression). So it emittedparseDateTime64BestEffortOrNullon a value that was already aDateTime64, which ClickHouse rejects.Changes
CallType(returningDateTimeType) on thetoDateTime()call it synthesizes for DateTime properties — previously the call was untyped.Aliasnodes when resolving a function's overload, so a stale alias type no longer hides the real expression type. This makestoDateTime()'sDateTime → toDateTimeoverload fire instead of falling back to the string-parse default.How did you test this code?
I'm an agent. Automated tests run locally:
test_to_datetime_does_not_double_parse_datetime_propertyinposthog/hogql/printer/test/test_printer.py, reproducing the double-parse and asserting it no longer happens.test_printer.py+test_property_types.pysuites — 649 passed, 184 snapshots unchanged.Publish to changelog?
no
🤖 Agent context
Authored by Claude Code (Opus 4.7). Found via
system.query_loganalysis of failing product-analytics insight queries (exception_code = 43, illegal-type onparseDateTime64BestEffortOrNull).Decisions:
toDateTime()call, and even with a type the printer read it through a staleAliastype. Fixing only one leaves the bug.toDateTime) — an alias's declared type being stale after a transform rewrites its inner expression is a general hazard, and resolving against the real expression is strictly more correct.parseDateTime64BestEffortOrNullon a DateTime column reached through a subquery, seen in HogQLQuery rather than insight queries) is not addressed here and may need follow-up.Agent-authored; requires human review.