Repository navigation
Conversation
jsqlparser wraps a parenthesized condition in a Parenthesis node, which the converter rejected as unsupported, so a filter such as a < 1 OR (a = 1 AND b < 2) failed. Unwrap it.
Let the filter use CURRENT_DATE, CURRENT_TIME and CURRENT_TIMESTAMP with INTERVAL arithmetic, so the optimizing scope can leave out recently written data without updating the property by a periodic job, for example 'self-optimizing.filter' = 'event_time < CURRENT_TIMESTAMP - INTERVAL ''3'' HOUR'. - DateTimeExpressionEvaluator evaluates the value expression of the filter: CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP (with or without parentheses) and INTERVAL in the forms INTERVAL '3' HOUR, INTERVAL 3 HOUR and INTERVAL '3 HOUR' with the units YEAR, MONTH, WEEK, DAY, HOUR, MINUTE and SECOND, combined with + and -. Any other value expression is rejected; the caller still gets an IllegalArgumentException, now naming the unsupported node. - ExpressionUtil converts the result for DATE, TIME and TIMESTAMP columns; a CURRENT_TIMESTAMP-based value can also be compared with a DATE or TIME column. The value can be on either side of a comparison or a bound of BETWEEN. A timestamp without zone is compared with CURRENT_TIMESTAMP in UTC, the convention data expiration uses for timestamp fields; CURRENT_DATE and CURRENT_TIME use the JVM zone. - The filter is converted whenever the table is evaluated or planned, that is when a new snapshot is found, so CURRENT_* moves with the writes. The whole filter is converted with one current time taken from a Clock (the JVM clock in production), so several occurrences see the same instant and tests can fix the time and the zone. - Tests for the evaluator and for the end-to-end conversion per column type. configurations.md documents the functions and that the filter selects whole partitions, so the condition belongs on a partition column that leaves out the partitions still being written.
Tables partitioned by string columns such as dt='20260930' could not use the time functions. - DATE_FORMAT(expression, pattern) formats a CURRENT_DATE / CURRENT_TIME / CURRENT_TIMESTAMP based value with a Java DateTimeFormatter pattern for a string column; a pattern with % (MySQL or Trino style) is rejected. A string column accepts a literal or DATE_FORMAT; other functions are rejected. - CURRENT_TIMESTAMP AT TIME ZONE '<zone>' gives the wall-clock time of that zone and keeps the zone rules, so INTERVAL arithmetic follows daylight saving time. A timestamp column without zone compares it as stored (as if UTC), a DATE or TIME column takes its date or time, DATE_FORMAT formats it, and a column with zone rejects it since AT TIME ZONE gives a wall-clock time here. DATE_FORMAT and the comparison with DATE, TIME and timestamp-without-zone columns therefore do not depend on the JVM zone, for example dt < DATE_FORMAT(CURRENT_TIMESTAMP AT TIME ZONE 'Asia/Seoul' - INTERVAL '1' DAY, 'yyyyMMdd'). - Tests for both, including daylight saving time; configurations.md updated.
This branch has not been deployed
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.
Why are the changes needed?
Close #4559.
Based on #4558. Its commit is the first one here until #4558 is merged.
Brief change log
DateTimeExpressionEvaluator(new): evaluates the value side of the filter. It supportsCURRENT_DATE,CURRENT_TIME,CURRENT_TIMESTAMP(with or without()),INTERVAL '3' HOUR,INTERVAL 3 HOURandINTERVAL '3 HOUR'(YEARtoSECOND, andWEEK) with+and-,AT TIME ZONE '<zone>', andDATE_FORMAT(expression, pattern). Any other node is rejected with anUnsupportedOperationExceptionnaming it. The current time is read once per conversion from aClock.ExpressionUtil: converts the evaluated value for the column type, also when the value is on the left of a comparison or aBETWEENbound.docs/user-guides/configurations.md: the functions, and a note that the filter selects whole partitions.Time zones:
CURRENT_DATE,CURRENT_TIME, and a date or time taken fromCURRENT_TIMESTAMPuse the AMS JVM zone.CURRENT_TIMESTAMPis compared with timestamp columns as an instant. Values of a timestamp column without zone are read as UTC, as data expiration does.CURRENT_TIMESTAMP AT TIME ZONE 'z'is the wall clock in z. A timestamp column without zone compares it with the stored value as is, a timestamp column with zone rejects it, andINTERVALarithmetic after it follows z's daylight saving rules.A STRING column accepts a literal or
DATE_FORMAT. A pattern containing%is rejected.How was this patch tested?
Add some test cases that check the changes thoroughly including negative and positive cases if possible
TestDateTimeExpressionEvaluatorandTestExpressionUtil. The clock is fixed inAmerica/Los_Angeles, so the zone choices and daylight saving transitions are asserted regardless of the build machine's zone.Add screenshots for manual tests if appropriate
Run test locally before making a pull request
Also verified on an AMS built from these changes on 0.8.0. With the filter below on a table partitioned by string
dtandhr, only partitions that ended more than two hours earlier were optimized. An hour later, after the next write, the partition that had crossed the boundary was optimized as well.Documentation