Repository navigation
Name HAVING when an aggregate is rejected in WHERE, and stop calling every unparseable date too short - #116817
Conversation
…every unparseable date too short
Two findings from a second pass over the error-message survey. The first
pass damaged benchmark queries at random, which is good at finding
messages that point at the wrong place but says nothing about the
mistakes people make on purpose, so this pass ran a hand-written corpus
of those instead: syntax borrowed from other dialects and the classic
semantic errors.
`SELECT count() AS c FROM t WHERE c > 1` is the textbook mistake, and the
message was actively confusing, because the alias is expanded before the
check runs:
Aggregate function count() AS c is found in WHERE in query
The user never wrote an aggregate in WHERE, and nothing said where it
would be allowed. Name that:
Aggregate function count() AS c is found in WHERE in query.
Aggregate functions are not allowed in WHERE and PREWHERE, because
they are computed after filtering; use HAVING to filter by the result
of an aggregation
The hint is attached to the WHERE and PREWHERE checks only. The other
callers of `assertNoAggregateFunctionNodes` - JOIN TREE, GROUP BY, another
aggregate function, a column DEFAULT expression - have no such
alternative to suggest and keep the message they had.
`toDate('yesterday')` reported
Cannot parse date: value is too short
which is false: the value is nine characters and the parse failed on the
first character not being a digit. `readDateTextFallback` uses one `error`
lambda for every way the parse can fail - a non-digit where a digit
belongs, a delimiter that is not in the allowed set, or the value ending
early - so the message must not claim a particular one:
Cannot parse date: expected a date in the YYYY-MM-DD or YYYYMMDD format
Values of ten characters or more take the fast path, which already shows
the offending text (`Cannot parse date here: abcd-01-02`) and is left
alone. No test asserts either of the two old strings; the tests that
assert the error codes `ILLEGAL_AGGREGATION` and `CANNOT_PARSE_DATE` were
run and pass.
|
Workflow [PR], commit [eed6f5d] Summary: ✅
AI ReviewSummaryThis PR improves two SQL diagnostics: it adds a Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit eed6f5d.
Changed lines: Changed C/C++ lines covered: 46/47 (97.87%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units22 translation units recompiled, 139 s compile time in total, 22 of them have a recent master baseline. |
The messages it asserts are produced by the analyzer; with `enable_analyzer = 0` the same errors come from a different code path and are worded differently, so the test failed in the `old analyzer` CI configuration.
Review pointed out that the hint only covered the query-tree analyzer, while `enable_analyzer = 0` keeps its own copy of the check in `GetAggregatesVisitor` and so kept the old message. Share the text between the two and pass it from `TreeRewriter` as well, so the advice does not depend on which analyzer runs. The test covers that path explicitly with `SETTINGS enable_analyzer = 0`. The test also drops the table it creates, as `_cleanup_database` in `clickhouse-test` asks new tests to do.
The test showed the `Date` path as a contrast to the integer one, and did it by pinning the whole message - which couples it to #116817, where the reason part of `Cannot parse date` changes. Normalise the reason away: what this test is about is that the `Date` path has a message of its own, not what that message says.
…nd-date-error-messages
Master added `05049_totime_legacy_create_as_nested`, so the test moves to 05053.
Related: #116806
Related: #116809
Related: #116812
Related: #116815
Two findings from a second pass over the survey of the error messages ClickHouse produces for mistakes in SQL queries. The first pass damaged benchmark queries at random, which is good at finding messages that point at the wrong place but says nothing about the mistakes people make on purpose. This pass ran a hand-written corpus of those instead — syntax borrowed from T-SQL, Oracle, MySQL and Postgres, plus the classic semantic errors. Most of it is answered well already (
NVL,TOP,ROWNUM,MERGE,FOR UPDATE,NUMBER, positional-argument bounds,arrayJoinon a non-array, comparing a string to a number). Two answers were not.An aggregate rejected in WHERE did not mention HAVING.
SELECT count() AS c FROM t WHERE c > 1is the textbook SQL mistake, and the message was actively confusing, because the alias is expanded before the check runs:The user never wrote an aggregate in WHERE — they wrote
c— and nothing in the message says where an aggregate is allowed. Now:The hint goes to the WHERE and PREWHERE checks only. The other callers of
assertNoAggregateFunctionNodes— JOIN TREE, GROUP BY, inside another aggregate function, a columnDEFAULTexpression — have no such alternative to suggest and keep the message they had.Every unparseable date was called too short.
toDate('yesterday')reported:The value is nine characters; the parse failed because the first character is not a digit.
readDateTextFallbackuses a singleerrorlambda for every way the parse can fail — a non-digit where a digit belongs, a delimiter outside the allowed set, or the value genuinely ending early — so the message cannot claim a particular one:Values of ten characters or more take the fast path in
readDateTextImpl, which already shows the offending text (Cannot parse date here: abcd-01-02) and is left alone. The new wording names the canonical formats rather than a required delimiter, because delimiters other than-are accepted (toDate('2020!01!02')works) — the test covers that.No test asserts either of the two old strings. The 48 stateless tests that mention
ILLEGAL_AGGREGATION,CANNOT_PARSE_DATEorCannot parse datewere run; the 7 failures are unrelated environment ones (no ZooKeeper, no second loopback listener forremote('127.0.0.2', …), no writeable access storage), and every test that covers the change passes, including02916_date_text_parsing,01933_invalid_date,01424_parse_date_time_bad_dateand04203_analyzer_having_non_aggregate_compat.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
An aggregate function used in
WHEREorPREWHERE— most often through an alias, as inSELECT count() AS c FROM t WHERE c > 1— is now told to useHAVINGinstead. A value that cannot be parsed as aDateis no longer reported as being too short when that is not the reason; the message now names the expected format.Workflow [PR]
Sync PR [sync-upstream/pr/116817]