Add PostgreSQL-compatible EXTRACT units#100274
Conversation
…YEAR, WEEK, CENTURY, DECADE, MILLENNIUM Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Workflow [PR], commit [6661f10] Summary: ✅ AI ReviewSummaryThis PR adds PostgreSQL-style Findings❌ Blockers
ClickHouse Rules
Performance & Safety
Final Verdict
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| -- Test PostgreSQL-compatible EXTRACT units | ||
|
|
||
| -- EPOCH: seconds since 1970-01-01 | ||
| SELECT EXTRACT(EPOCH FROM toDateTime('2024-01-15 12:30:45', 'UTC')); |
There was a problem hiding this comment.
Please add a coverage case for EXTRACT(EPOCH FROM toDateTime64(...)).
Right now the new test checks only Date/DateTime, so it does not lock the intended behavior for fractional seconds. This is especially important because the implementation currently routes through toUnixTimestamp.
Add `DateTime64` test case for `EXTRACT(EPOCH FROM ...)` to document that subsecond precision is truncated (returns integer seconds via `toUnixTimestamp`). Add case-insensitive keyword tests and `DateTime64` tests for DOW, DOY, ISOYEAR units. Document the truncation behavior in the EPOCH docs entry. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Update docs to mention `Date32` and `DateTime64` as supported types. Add tests for all new PostgreSQL-compatible EXTRACT units (EPOCH, DOW, DOY, ISODOW, ISOYEAR, WEEK, CENTURY, DECADE, MILLENNIUM) with `Date32` and `DateTime64` arguments. https://github.com/ClickHouse/ClickHouse/pull/100274/changes#diff-3b481535bcd78eeebb8fb9282ee4ca40a5e1a69f499146820b39fe5389e903ac Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
alexey-milovidov
left a comment
There was a problem hiding this comment.
The code is good.
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 97.54% (119/122, 1 noise lines excluded) |
Add PostgreSQL-compatible units to the
EXTRACToperator:EPOCH,DOW,DOY,ISODOW,ISOYEAR,WEEK,CENTURY,DECADE,MILLENNIUM.These are parsed as extract-only units (not interval kinds) and mapped to existing ClickHouse functions:
EPOCH→toUnixTimestampDOW→toDayOfWeek(expr, 2)(0 = Sunday, 6 = Saturday)DOY→toDayOfYearISODOW→toDayOfWeek(expr)(1 = Monday, 7 = Sunday)ISOYEAR→toISOYearWEEK→toISOWeek(previously threw an error)CENTURY→intDiv(toYear(expr) - 1, 100) + 1DECADE→intDiv(toYear(expr), 10)MILLENNIUM→intDiv(toYear(expr) - 1, 1000) + 1Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add PostgreSQL-compatible units to the
EXTRACToperator:EPOCH,DOW,DOY,ISODOW,ISOYEAR,WEEK,CENTURY,DECADE,MILLENNIUM. Also fixEXTRACT(WEEK FROM date)which previously threw an error.Documentation entry for user-facing changes
The
EXTRACToperator now supports additional PostgreSQL-compatible units:EXTRACT(EPOCH FROM expr)— seconds since 1970-01-01 00:00:00 UTCEXTRACT(DOW FROM expr)— day of week (0 = Sunday, 6 = Saturday)EXTRACT(DOY FROM expr)— day of year (1–366)EXTRACT(ISODOW FROM expr)— ISO day of week (1 = Monday, 7 = Sunday)EXTRACT(ISOYEAR FROM expr)— ISO 8601 week-numbering yearEXTRACT(WEEK FROM expr)— ISO 8601 week number (1–53)EXTRACT(CENTURY FROM expr)— centuryEXTRACT(DECADE FROM expr)— decade (year / 10)EXTRACT(MILLENNIUM FROM expr)— millenniumExample: