You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "morrySnow (via GitHub)" <gi...@apache.org> on 2026/04/07 05:03:01 UTC
[PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
morrySnow opened a new pull request, #62154:
URL: https://github.com/apache/doris/pull/62154
### What problem does this PR solve?
**Problem Summary:**
`DateLiteral` in its `init()` method calls `DateUtils.getTimeZone()` to obtain the current timezone from the Nereids utility package. This couples the legacy `analysis` package to the newer `nereids` package unnecessarily.
### Changes
1. **Creates `DateLiteralUtils` helper class** with a static `createDateLiteral(String, Type)` factory method that replicates the exact parsing behavior of the removed constructor
2. **Removes the `DateLiteral(String, Type)` constructor** and its `init()` method from DateLiteral.java
3. **Moves timezone helpers** (`haveTimeZoneOffset`, `haveTimeZoneName`, `getTimeZoneSplitPos`, `HAS_OFFSET_PART`) to DateLiteralUtils
4. **Updates all production callers** (LiteralExpr, ExprToStringValueVisitor, PartitionExprUtil, ColumnDef, SchemaChangeProcDir, RollupProcDir, BuildIndexProcDir, PartitionsProcDir, PropertyAnalyzer, StatisticsUtil)
5. **Updates all test callers** to use the new factory method
6. **Removes the `DateUtils` import** from DateLiteral.java
The `DateUtils` dependency now lives only in `DateLiteralUtils`, not in `DateLiteral`.
### Design Notes
- `DateLiteralUtils` uses `DateLiteral.formatterList` (package-private) for compact format parsing
- `checkRange()`/`checkDate()` made package-private so DateLiteralUtils can perform the same validation as the original `init()`
- `DateLiteral(String)` single-arg constructor delegates to `DateLiteralUtils.createDateLiteral(s, null)`
- When auto-detecting type with microseconds and `enable_date_conversion=false`, DATETIME v1 is upgraded to DATETIMEV2 (matching the explicit-type path behavior)
### Release note
None
### Check List (For Author)
- Test: Unit Test (DateLiteralTest - 16 tests pass)
- Behavior changed: No
- Does this need documentation: No
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #62154:
URL: https://github.com/apache/doris/pull/62154#issuecomment-4203387596
I reviewed the refactor and did not find any correctness, compatibility, or concurrency issues in the changed FE paths. The parsing logic was extracted with equivalent behavior, the production call sites were updated consistently, and the new unit coverage exercises the key timezone and type-inference cases introduced by the refactor.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "morrySnow (via GitHub)" <gi...@apache.org>.
morrySnow commented on PR #62154:
URL: https://github.com/apache/doris/pull/62154#issuecomment-4203376993
run buildall
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #62154:
URL: https://github.com/apache/doris/pull/62154#issuecomment-4196669106
No issues found in the current patch.
Critical checkpoints:
- Goal and correctness: The change cleanly extracts string parsing/timezone handling out of `analysis.DateLiteral` into `DateLiteralUtils` and updates the in-tree callers in this path. The added/updated FE unit tests cover date, datetime, datetimev2, timestamptz, compact formats, timezone offsets, and invalid inputs.
- Scope/minimality: The refactor stays focused on decoupling `DateLiteral` from `nereids.util.DateUtils`; no unrelated logic, config, or persistence changes are mixed in.
- Concurrency: No concurrency-sensitive code is touched.
- Lifecycle/static init: Reusing `DateLiteral.formatterList` and package-private validators does not introduce a new lifecycle issue beyond the existing `DateLiteral` static initialization path.
- Configuration: No new config items or dynamic-config behavior are introduced.
- Compatibility: No storage, EditLog, or FE/BE protocol compatibility issue was observed in the modified paths. All in-tree call sites of the removed two-arg constructor were updated.
- Parallel code paths: The relevant production and test call sites using `DateLiteral(String, Type)` were updated consistently.
- Special conditional checks: No suspicious new conditional logic was added beyond the existing parsing rules.
- Test coverage: Coverage in the touched area is materially improved, including negative cases.
- Observability: Not applicable for this refactor.
- Transaction/persistence/data-write semantics: Not applicable.
- Performance: No meaningful regression was observed from the refactor.
- Other issues: None found.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "morrySnow (via GitHub)" <gi...@apache.org>.
morrySnow merged PR #62154:
URL: https://github.com/apache/doris/pull/62154
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #62154:
URL: https://github.com/apache/doris/pull/62154#issuecomment-4197239626
No issues found in the current head revision.
Review summary:
- Goal of the change: achieved. is decoupled from , and the extracted now matches the old behavior on the reviewed paths, including the null-type/thrift reconstruction path.
- Scope/minimality: acceptable. This stays a focused FE refactor plus caller/test updates.
- Concurrency/lifecycle/config/incompatible-change checkpoints: not applicable here; no locking, thread-safety, config, persistence, or storage-format changes were introduced.
- Parallel-path consistency: checked. The typed callers, thrift reconstruction path, string visitors, proc/property/statistics callers, and related tests were updated consistently.
- Special-condition checks: checked. Timezone parsing/type inference behavior appears preserved at the current head, including handling and auto-detection semantics.
- Test coverage: acceptable for this refactor. Unit coverage includes parsing parity, timezone conversion, invalid inputs, and behavior.
- Observability / transaction / data-write / FE-BE variable-passing checkpoints: not applicable for this change.
- Performance: no obvious regression beyond negligible refactor overhead.
Residual risk: limited to unit-tested FE literal parsing paths; no additional blocking issues identified.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "morrySnow (via GitHub)" <gi...@apache.org>.
morrySnow commented on PR #62154:
URL: https://github.com/apache/doris/pull/62154#issuecomment-4197210828
run buildall
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #62154:
URL: https://github.com/apache/doris/pull/62154#issuecomment-4203290621
PR approved by at least one committer and no changes requested.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "morrySnow (via GitHub)" <gi...@apache.org>.
morrySnow commented on PR #62154:
URL: https://github.com/apache/doris/pull/62154#issuecomment-4203377012
/review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "morrySnow (via GitHub)" <gi...@apache.org>.
morrySnow commented on PR #62154:
URL: https://github.com/apache/doris/pull/62154#issuecomment-4197086065
run buildall
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #62154:
URL: https://github.com/apache/doris/pull/62154#discussion_r3043353153
##########
fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteralUtils.java:
##########
@@ -0,0 +1,288 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.analysis;
+
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.catalog.Type;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.nereids.util.DateUtils;
+
+import com.google.common.base.Preconditions;
+
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
+import java.time.format.DateTimeParseException;
+import java.time.format.ResolverStyle;
+import java.time.temporal.ChronoField;
+import java.time.temporal.TemporalAccessor;
+import java.util.Collections;
+import java.util.regex.Pattern;
+import javax.annotation.Nullable;
+
+/**
+ * Utility class providing a static factory method for creating {@link DateLiteral} instances
+ * from string representations. This replicates the parsing logic of the
+ * {@code DateLiteral(String, Type)} constructor and its {@code init()} method.
+ */
+public class DateLiteralUtils {
+
+ private static final Pattern HAS_OFFSET_PART = Pattern.compile("[\\+\\-]\\d{2}:\\d{2}");
+
+ private DateLiteralUtils() {
+ }
+
+ /**
+ * Creates a {@link DateLiteral} by parsing the given string, replicating the exact behavior
+ * of the {@code DateLiteral(String, Type)} constructor and its internal {@code init()} method.
+ *
+ * @param s the date/datetime string to parse
+ * @param type the target date type, or {@code null} for auto-detection
+ * @return a new {@link DateLiteral} instance
+ * @throws AnalysisException if the string cannot be parsed or the resulting value is out of range
+ */
+ public static DateLiteral createDateLiteral(String s, @Nullable Type type) throws AnalysisException {
+ try {
+ if (type != null) {
+ Preconditions.checkArgument(type.isDateType());
+ }
+ TemporalAccessor dateTime = null;
+ boolean parsed = false;
+ int offset = 0;
+
+ // parse timezone
+ if (haveTimeZoneOffset(s) || haveTimeZoneName(s)) {
+ String tzString = new String();
+ if (haveTimeZoneName(s)) { // GMT, UTC+8, Z[, CN, Asia/Shanghai]
+ int split = getTimeZoneSplitPos(s);
+ Preconditions.checkArgument(split > 0);
+ tzString = s.substring(split);
+ s = s.substring(0, split);
+ } else { // +04:30
+ Preconditions.checkArgument(
+ s.charAt(s.length() - 6) == '-' || s.charAt(s.length() - 6) == '+');
+ tzString = s.substring(s.length() - 6);
+ s = s.substring(0, s.length() - 6);
+ }
+ ZoneId zone = ZoneId.of(tzString);
+ ZoneId dorisZone = DateUtils.getTimeZone();
+ if (type != null && type.isTimeStampTz()) {
+ dorisZone = ZoneId.of("UTC");
+ }
+ offset = dorisZone.getRules().getOffset(Instant.now()).getTotalSeconds()
+ - zone.getRules().getOffset(Instant.now()).getTotalSeconds();
+ }
+
+ if (!s.contains("-")) {
+ // handle format like 20210106, but should not handle 2021-1-6
+ for (DateTimeFormatter formatter : DateLiteral.formatterList) {
+ try {
+ dateTime = formatter.parse(s);
+ parsed = true;
+ break;
+ } catch (DateTimeParseException ex) {
+ // ignore
+ }
+ }
+ if (!parsed) {
+ throw new AnalysisException("Invalid date value: " + s);
+ }
+ } else {
+ String[] datePart = s.contains(" ") ? s.split(" ")[0].split("-") : s.split("-");
+ DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
+ if (datePart.length != 3) {
+ throw new AnalysisException("Invalid date value: " + s);
+ }
+ for (int i = 0; i < datePart.length; i++) {
+ switch (i) {
+ case 0:
+ if (datePart[i].length() == 2) {
+ // If year is represented by two digits, number bigger than 70 will be
+ // prefixed with 19 otherwise 20. e.g. 69 -> 2069, 70 -> 1970.
+ builder.appendValueReduced(ChronoField.YEAR, 2, 2, 1970);
+ } else {
+ builder.appendPattern(
+ String.join("", Collections.nCopies(datePart[i].length(), "u")));
+ }
+ break;
+ case 1:
+ builder.appendPattern(
+ String.join("", Collections.nCopies(datePart[i].length(), "M")));
+ break;
+ case 2:
+ builder.appendPattern(
+ String.join("", Collections.nCopies(datePart[i].length(), "d")));
+ break;
+ default:
+ throw new AnalysisException("Two many parts in date format " + s);
+ }
+ if (i < datePart.length - 1) {
+ builder.appendLiteral("-");
+ }
+ }
+ if (s.contains(" ")) {
+ builder.appendLiteral(" ");
+ }
+ String[] timePart = s.contains(" ") ? s.split(" ")[1].split(":") : new String[]{};
+ if (timePart.length > 0 && type != null
+ && (type.equals(Type.DATE) || type.equals(Type.DATEV2))) {
+ throw new AnalysisException("Invalid date value: " + s);
+ }
+ if (timePart.length == 0 && type != null
+ && (type.equals(Type.DATETIME) || type.equals(Type.DATETIMEV2))) {
+ throw new AnalysisException("Invalid datetime value: " + s);
+ }
+ for (int i = 0; i < timePart.length; i++) {
+ switch (i) {
+ case 0:
+ builder.appendPattern(
+ String.join("", Collections.nCopies(timePart[i].length(), "H")));
+ break;
+ case 1:
+ builder.appendPattern(
+ String.join("", Collections.nCopies(timePart[i].length(), "m")));
+ break;
+ case 2:
+ builder.appendPattern(String.join("", Collections.nCopies(
+ timePart[i].contains(".")
+ ? timePart[i].split("\\.")[0].length()
+ : timePart[i].length(), "s")));
+ if (timePart[i].contains(".")) {
+ builder.appendFraction(ChronoField.MICRO_OF_SECOND, 0, 6, true);
+ }
+ break;
+ default:
+ throw new AnalysisException("Two many parts in time format " + s);
+ }
+ if (i < timePart.length - 1) {
+ builder.appendLiteral(":");
+ }
+ }
+ // The default resolver style is 'SMART', which parses "2022-06-31" as "2022-06-30"
+ // and does not throw an exception. 'STRICT' is used here.
+ DateTimeFormatter formatter = builder.toFormatter().withResolverStyle(ResolverStyle.STRICT);
+ dateTime = formatter.parse(s);
+ parsed = true;
+ }
+
+ Preconditions.checkArgument(parsed);
+ long year = getOrDefault(dateTime, ChronoField.YEAR, 0);
+ long month = getOrDefault(dateTime, ChronoField.MONTH_OF_YEAR, 0);
+ long day = getOrDefault(dateTime, ChronoField.DAY_OF_MONTH, 0);
+ long hour = getOrDefault(dateTime, ChronoField.HOUR_OF_DAY, 0);
+ long minute = getOrDefault(dateTime, ChronoField.MINUTE_OF_HOUR, 0);
+ long second = getOrDefault(dateTime, ChronoField.SECOND_OF_MINUTE, 0);
+ long microsecond = getOrDefault(dateTime, ChronoField.MICRO_OF_SECOND, 0);
+
+ if (type != null) {
+ if (microsecond != 0 && type.isDatetime()) {
+ int dotIndex = s.lastIndexOf(".");
+ int scale = s.length() - dotIndex - 1;
+ type = ScalarType.createDatetimeV2Type(scale);
+ }
+ } else {
+ if (hour == 0 && minute == 0 && second == 0 && microsecond == 0) {
+ type = ScalarType.getDefaultDateType(Type.DATE);
+ } else {
+ type = ScalarType.getDefaultDateType(Type.DATETIME);
+ if (microsecond != 0 && type.isDatetime()) {
Review Comment:
This branch is not behavior-equivalent to the old `DateLiteral.init()` implementation. Before the refactor, the `type == null` path only inferred `DATETIMEV2` when `ScalarType.getDefaultDateType(Type.DATETIME)` already returned V2; if the default stayed as `DATETIME`, fractional seconds were not promoted here.
With this extra `type.isDatetime()` upgrade, type-less callers now see different results. The important one is `ExprToThriftVisitor`/`ConnectProcessor`: thrift only carries `TDateLiteral.value`, and `getLiteralExprFromThrift()` reconstructs with `type = null`, so under `enable_date_conversion=false` a payload like `2023-06-15 14:30:45.123456` now round-trips back as `DATETIMEV2` instead of the legacy `DATETIME` behavior. That is a semantic change outside the stated decoupling refactor and needs either to be reverted here or covered as an explicit compatibility change with tests for the thrift/null-type path.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "Thearas (via GitHub)" <gi...@apache.org>.
Thearas commented on PR #62154:
URL: https://github.com/apache/doris/pull/62154#issuecomment-4196627543
Thank you for your contribution to Apache Doris.
Don't know what should be done next? See [How to process your PR](https://cwiki.apache.org/confluence/display/DORIS/How+to+process+your+PR).
Please clearly describe your PR:
1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
3. What features were added. Why was this function added?
4. Which code was refactored and why was this part of the code refactored?
5. Which functions were optimized and what is the difference before and after the optimization?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #62154:
URL: https://github.com/apache/doris/pull/62154#issuecomment-4203290742
PR approved by anyone and no changes requested.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #62154:
URL: https://github.com/apache/doris/pull/62154#issuecomment-4204191070
PR approved by at least one committer and no changes requested.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "morrySnow (via GitHub)" <gi...@apache.org>.
morrySnow commented on PR #62154:
URL: https://github.com/apache/doris/pull/62154#issuecomment-4196628666
run buildall
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "morrySnow (via GitHub)" <gi...@apache.org>.
morrySnow commented on PR #62154:
URL: https://github.com/apache/doris/pull/62154#issuecomment-4196628716
/review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "morrySnow (via GitHub)" <gi...@apache.org>.
morrySnow commented on PR #62154:
URL: https://github.com/apache/doris/pull/62154#issuecomment-4197086101
/review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "morrySnow (via GitHub)" <gi...@apache.org>.
morrySnow commented on PR #62154:
URL: https://github.com/apache/doris/pull/62154#issuecomment-4197210809
/review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "morrySnow (via GitHub)" <gi...@apache.org>.
morrySnow commented on code in PR #62154:
URL: https://github.com/apache/doris/pull/62154#discussion_r3043432802
##########
fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteralUtils.java:
##########
@@ -0,0 +1,288 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.analysis;
+
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.catalog.Type;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.nereids.util.DateUtils;
+
+import com.google.common.base.Preconditions;
+
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
+import java.time.format.DateTimeParseException;
+import java.time.format.ResolverStyle;
+import java.time.temporal.ChronoField;
+import java.time.temporal.TemporalAccessor;
+import java.util.Collections;
+import java.util.regex.Pattern;
+import javax.annotation.Nullable;
+
+/**
+ * Utility class providing a static factory method for creating {@link DateLiteral} instances
+ * from string representations. This replicates the parsing logic of the
+ * {@code DateLiteral(String, Type)} constructor and its {@code init()} method.
+ */
+public class DateLiteralUtils {
+
+ private static final Pattern HAS_OFFSET_PART = Pattern.compile("[\\+\\-]\\d{2}:\\d{2}");
+
+ private DateLiteralUtils() {
+ }
+
+ /**
+ * Creates a {@link DateLiteral} by parsing the given string, replicating the exact behavior
+ * of the {@code DateLiteral(String, Type)} constructor and its internal {@code init()} method.
+ *
+ * @param s the date/datetime string to parse
+ * @param type the target date type, or {@code null} for auto-detection
+ * @return a new {@link DateLiteral} instance
+ * @throws AnalysisException if the string cannot be parsed or the resulting value is out of range
+ */
+ public static DateLiteral createDateLiteral(String s, @Nullable Type type) throws AnalysisException {
+ try {
+ if (type != null) {
+ Preconditions.checkArgument(type.isDateType());
+ }
+ TemporalAccessor dateTime = null;
+ boolean parsed = false;
+ int offset = 0;
+
+ // parse timezone
+ if (haveTimeZoneOffset(s) || haveTimeZoneName(s)) {
+ String tzString = new String();
+ if (haveTimeZoneName(s)) { // GMT, UTC+8, Z[, CN, Asia/Shanghai]
+ int split = getTimeZoneSplitPos(s);
+ Preconditions.checkArgument(split > 0);
+ tzString = s.substring(split);
+ s = s.substring(0, split);
+ } else { // +04:30
+ Preconditions.checkArgument(
+ s.charAt(s.length() - 6) == '-' || s.charAt(s.length() - 6) == '+');
+ tzString = s.substring(s.length() - 6);
+ s = s.substring(0, s.length() - 6);
+ }
+ ZoneId zone = ZoneId.of(tzString);
+ ZoneId dorisZone = DateUtils.getTimeZone();
+ if (type != null && type.isTimeStampTz()) {
+ dorisZone = ZoneId.of("UTC");
+ }
+ offset = dorisZone.getRules().getOffset(Instant.now()).getTotalSeconds()
+ - zone.getRules().getOffset(Instant.now()).getTotalSeconds();
+ }
+
+ if (!s.contains("-")) {
+ // handle format like 20210106, but should not handle 2021-1-6
+ for (DateTimeFormatter formatter : DateLiteral.formatterList) {
+ try {
+ dateTime = formatter.parse(s);
+ parsed = true;
+ break;
+ } catch (DateTimeParseException ex) {
+ // ignore
+ }
+ }
+ if (!parsed) {
+ throw new AnalysisException("Invalid date value: " + s);
+ }
+ } else {
+ String[] datePart = s.contains(" ") ? s.split(" ")[0].split("-") : s.split("-");
+ DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
+ if (datePart.length != 3) {
+ throw new AnalysisException("Invalid date value: " + s);
+ }
+ for (int i = 0; i < datePart.length; i++) {
+ switch (i) {
+ case 0:
+ if (datePart[i].length() == 2) {
+ // If year is represented by two digits, number bigger than 70 will be
+ // prefixed with 19 otherwise 20. e.g. 69 -> 2069, 70 -> 1970.
+ builder.appendValueReduced(ChronoField.YEAR, 2, 2, 1970);
+ } else {
+ builder.appendPattern(
+ String.join("", Collections.nCopies(datePart[i].length(), "u")));
+ }
+ break;
+ case 1:
+ builder.appendPattern(
+ String.join("", Collections.nCopies(datePart[i].length(), "M")));
+ break;
+ case 2:
+ builder.appendPattern(
+ String.join("", Collections.nCopies(datePart[i].length(), "d")));
+ break;
+ default:
+ throw new AnalysisException("Two many parts in date format " + s);
+ }
+ if (i < datePart.length - 1) {
+ builder.appendLiteral("-");
+ }
+ }
+ if (s.contains(" ")) {
+ builder.appendLiteral(" ");
+ }
+ String[] timePart = s.contains(" ") ? s.split(" ")[1].split(":") : new String[]{};
+ if (timePart.length > 0 && type != null
+ && (type.equals(Type.DATE) || type.equals(Type.DATEV2))) {
+ throw new AnalysisException("Invalid date value: " + s);
+ }
+ if (timePart.length == 0 && type != null
+ && (type.equals(Type.DATETIME) || type.equals(Type.DATETIMEV2))) {
+ throw new AnalysisException("Invalid datetime value: " + s);
+ }
+ for (int i = 0; i < timePart.length; i++) {
+ switch (i) {
+ case 0:
+ builder.appendPattern(
+ String.join("", Collections.nCopies(timePart[i].length(), "H")));
+ break;
+ case 1:
+ builder.appendPattern(
+ String.join("", Collections.nCopies(timePart[i].length(), "m")));
+ break;
+ case 2:
+ builder.appendPattern(String.join("", Collections.nCopies(
+ timePart[i].contains(".")
+ ? timePart[i].split("\\.")[0].length()
+ : timePart[i].length(), "s")));
+ if (timePart[i].contains(".")) {
+ builder.appendFraction(ChronoField.MICRO_OF_SECOND, 0, 6, true);
+ }
+ break;
+ default:
+ throw new AnalysisException("Two many parts in time format " + s);
+ }
+ if (i < timePart.length - 1) {
+ builder.appendLiteral(":");
+ }
+ }
+ // The default resolver style is 'SMART', which parses "2022-06-31" as "2022-06-30"
+ // and does not throw an exception. 'STRICT' is used here.
+ DateTimeFormatter formatter = builder.toFormatter().withResolverStyle(ResolverStyle.STRICT);
+ dateTime = formatter.parse(s);
+ parsed = true;
+ }
+
+ Preconditions.checkArgument(parsed);
+ long year = getOrDefault(dateTime, ChronoField.YEAR, 0);
+ long month = getOrDefault(dateTime, ChronoField.MONTH_OF_YEAR, 0);
+ long day = getOrDefault(dateTime, ChronoField.DAY_OF_MONTH, 0);
+ long hour = getOrDefault(dateTime, ChronoField.HOUR_OF_DAY, 0);
+ long minute = getOrDefault(dateTime, ChronoField.MINUTE_OF_HOUR, 0);
+ long second = getOrDefault(dateTime, ChronoField.SECOND_OF_MINUTE, 0);
+ long microsecond = getOrDefault(dateTime, ChronoField.MICRO_OF_SECOND, 0);
+
+ if (type != null) {
+ if (microsecond != 0 && type.isDatetime()) {
+ int dotIndex = s.lastIndexOf(".");
+ int scale = s.length() - dotIndex - 1;
+ type = ScalarType.createDatetimeV2Type(scale);
+ }
+ } else {
+ if (hour == 0 && minute == 0 && second == 0 && microsecond == 0) {
+ type = ScalarType.getDefaultDateType(Type.DATE);
+ } else {
+ type = ScalarType.getDefaultDateType(Type.DATETIME);
+ if (microsecond != 0 && type.isDatetime()) {
Review Comment:
Good catch. You're right — the `type.isDatetime()` upgrade in the `type == null` path was a semantic change beyond the refactor scope. Under `enable_date_conversion=false`, `getDefaultDateType(DATETIME)` returns legacy `DATETIME`, and the original code would silently drop microseconds rather than upgrade to `DATETIMEV2`.
Fixed by reverting the `type == null` branch to match the original `init()` exactly: only adjust scale when `getDefaultDateType` already returns `isDatetimeV2()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [refactor](fe) Decouple analysis.DateLiteral from nereids.util.DateUtils [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #62154:
URL: https://github.com/apache/doris/pull/62154#issuecomment-4197241040
No issues found in the current head revision.
Review summary:
- Goal of the change: achieved. `DateLiteral` is decoupled from `nereids.util.DateUtils`, and the extracted `DateLiteralUtils.createDateLiteral()` now matches the old `DateLiteral.init()` behavior on the reviewed paths, including the null-type/thrift reconstruction path.
- Scope/minimality: acceptable. This stays a focused FE refactor plus caller/test updates.
- Concurrency/lifecycle/config/incompatible-change checkpoints: not applicable here; no locking, thread-safety, config, persistence, or storage-format changes were introduced.
- Parallel-path consistency: checked. The typed callers, `ConnectProcessor` thrift reconstruction path, string visitors, proc/property/statistics callers, and related tests were updated consistently.
- Special-condition checks: checked. Timezone parsing/type inference behavior appears preserved at the current head, including `TIMESTAMPTZ` handling and auto-detection semantics.
- Test coverage: acceptable for this refactor. Unit coverage includes parsing parity, timezone conversion, invalid inputs, and `ExprToStringValueVisitor` behavior.
- Observability / transaction / data-write / FE-BE variable-passing checkpoints: not applicable for this change.
- Performance: no obvious regression beyond negligible refactor overhead.
Residual risk: limited to unit-tested FE literal parsing paths; no additional blocking issues identified.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org