Repository navigation
add date extract - #26248
add date extract#26248
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-reviewed exact head e8b7d62 against latest main 522a157. CI is green and the prospective merge is clean.
Requesting changes for two independent production issues.
[P1] Make the new VARCHAR temporal parser complete and range-safe instead of returning plausible values for malformed input.
The shared component parser currently drifts in both directions from the canonical datetime grammar:
- A normal ISO datetime such as
2024-01-01T12:34:56is rejected, so all five new VARCHAR overloads return NULL. MySQL 8.4.10 accepts it, and MatrixOne already accepts this form intypes.ParseDatetime. - Out-of-range time suffixes such as
2024-01-01 24:00:00and2024-01-01 23:60:00are accepted because the state machine counts time-field digits but never records or validates their values. All five functions then return normal results, whereas MySQL returns NULL. 4294967297-01-01is accumulated as int64 and narrowed to int32 before validation, wrapping to year 1. The probe on this head produced a valid0001-01-01, so DAYNAME/WEEKOFYEAR and the component extractors return plausible but false values; MySQL returns NULL.- The month state has no rejection branch for unexpected characters. For example,
2024-0x-01is accepted as an incomplete date and produces DAYOFMONTH=1 and QUARTER=0, while MySQL returns NULL for every extractor.
These are one parser-contract problem, not isolated literals: accept the supported complete datetime grammar, validate separators and time ranges, and bounds-check raw components before narrowing. Please add category tests for ISO separators, malformed separators, time boundaries, and oversized components.
[P2] Remove the measurable regression added to the existing ParseDateCast hot path.
ParseDateCast now trims and calls isZeroDatetimeString, then ParseDateCastComponents repeats both operations. isZeroDatetimeString includes a full IndexByte scan, so every existing date cast and external-ingestion caller pays duplicated preprocessing even though the PR only needs raw components for the new overloads.
A same-host, zero-allocation benchmark against latest main, 500 ms x 5, gave these median times:
- dashed date: 23.70 -> 29.06 ns/op (+22.6%)
- compact date: 14.79 -> 17.92 ns/op (+21.2%)
- datetime with fraction: 53.53 -> 62.29 ns/op (+16.4%)
Please structure the shared parser around an internal already-trimmed path or return enough metadata for ParseDateCast to avoid redoing the scan. Keep a regression benchmark or otherwise verify parity for existing ParseDateCast callers.
Other verification on this exact head passed: full pkg/container/types and pkg/sql/plan/function suites under race; the new focused tests for 100 repetitions under race; vet and diff checks. I also exhaustively compared Date.Week(3) with Go ISOWeek over every valid date from year 1 through 9999, and that WEEKOFYEAR replacement is correct.
验证已通过:git diff --check、相关 UT 的 race 重复执行,以及 pkg/container/types、pkg/sql/plan/function 的 race 测试。 |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-reviewed exact head 858ea17e1c12b780adc1677d952c0b31b2d5a24e. The previous parser-safety and ParseDateCast performance blockers are fixed: ISO-T, range checks, oversized years, and malformed separators now follow the intended paths, and same-host 0-allocation benchmarks show the common dashed/compact/datetime-with-fraction paths are about 46%/24%/55% faster than current main.
Two independent MySQL-compatibility issues remain:
-
[P1] Implement MySQL year-0 calendar semantics instead of treating every year-0 value as an incomplete date and validating it as year 2000. On MySQL 8.4.10,
0000-01-01is a valid date: DAYOFMONTH/DAYNAME/MONTHNAME/QUARTER/WEEKOFYEAR return1 / Sunday / January / 1 / 52. This head returns NULL for DAYNAME and WEEKOFYEAR becausetypes.ValidDaterejects year 0. Conversely, MySQL rejects0000-02-29for all five functions because year 0 is not a leap year, whilevalidationYear = 2000makes this head return29 / February / 1from the component extractors. MatrixOne already has the MySQL-specific year-0 rule incalcDaysInYear; please validate and calculate this category consistently and add both valid and invalid year-0 regressions. -
[P2] Accept the nonstandard date delimiters that MySQL still accepts. MySQL 8.4.10 returns
15 / Monday / January / 1 / 3for both2024/01/15and2024:01:15(with deprecation warnings). The shared state machine accepts only-, so all five new overloads return NULL. This is a real migration compatibility break for existing MySQL data even though those delimiters are deprecated. Please handle the delimiter grammar as a category rather than adding literal-specific exceptions, and cover date plus datetime forms.
Both categories were reproduced against MySQL 8.4.10 and with direct current-head parser probes. The PR-owned focused tests pass, confirming these are coverage gaps rather than environment failures.
|
XuPeng-SH
left a comment
There was a problem hiding this comment.
P1: relaxed temporal parsing is still only partially compatible and now codifies a valid MySQL date-context value as invalid. In parseDateCastComponents, the (s[i] != : || yearLen == 4) gate makes 10:11:12 fail, and the new unit test explicitly expects that error. MySQL date-context rules interpret it as 2010-11-12; delimited YY-MM-DD/YY:MM:DD values use the documented 00-69 => 2000-2069 and 70-99 => 1970-1999 conversion. The same root issue exists in the datetime suffix: 2024/01/15 12*34*56 is valid relaxed MySQL syntax, but this parser accepts only : between time fields. These inputs therefore return NULL from DAYNAME/WEEKOFYEAR/etc. even though MySQL returns a value. Please implement the delimiter category coherently rather than special-casing four-digit-year colon: normalize two-digit years at the shared parser boundary, accept punctuation delimiters between time fields while retaining range/full-consumption validation, and add boundary/oracle tests (for example 10:11:12, years 69/70, and a datetime with * time delimiters). The year-0 calendar fix and standard hot paths otherwise look sound; focused tests passed and ParseDateCast remains 0-allocation.
|
XuPeng-SH
left a comment
There was a problem hiding this comment.
The two-digit-year fix is still incomplete for compact MySQL date forms. parseDateCastComponents rejects every all-digit input shorter than 7 bytes before applying normalizeDateCastYear, so the new VARCHAR overloads return NULL for 101112, 691231, 700101, and incomplete 101100.
MySQL 8.4 interprets these as 2010-11-12, 2069-12-31, 1970-01-01, and 2010-11-00, respectively. The five functions added by this PR consequently return the corresponding day/month/quarter values (and NULL only for the calendar-dependent functions on the incomplete date). My focused test against this head confirmed ParseDateCastComponents returns invalid argument parsedate for all four inputs.
Please extend the two-digit-year normalization to compact YYMMDD forms as well, including the 69/70 boundary and incomplete-date cases, and add unit/BVT coverage. MySQL also accepts compact YYMMDDHHMMSS (for example 101112123456) as the same date, so that form should be covered if the intent is to preserve the accepted VARCHAR temporal grammar.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-reviewed the current head in the context of the full discussion and the author's latest response. The response implements the previously requested categories: two-digit delimited years (including the 69/70 window), relaxed punctuation in time fields, year-0 calendar handling, parser range/full-consumption checks, and focused UT/BVT coverage. Full pkg/container/types and pkg/sql/plan/function tests pass locally, as do the relevant focused tests under -race -count=10.
I am treating compact YYMMDD / YYMMDDHHMMSS parsing as a non-blocking follow-up rather than expanding this PR beyond issue #24504 after the author addressed the requested cases. MySQL accepts those forms, while the shared parser currently rejects them, so retaining that compatibility gap as a follow-up would still be useful.
Merge Queue Status
This pull request spent 51 minutes 55 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonPull request #26248 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
Failing checks:
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #24504
What this PR does / why we need it:
• 此分支主要完成: