github-actions[bot] commented on code in PR #66761:
URL: https://github.com/apache/doris/pull/66761#discussion_r3836582411


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java:
##########
@@ -1410,15 +1520,8 @@ public static Expression processInPredicate(InPredicate 
inPredicate) {
         final InPredicate fmtInPredicate =
                 hitString ? new InPredicate(inPredicate.getCompareExpr(), 
newOptions) : inPredicate;
 
-        List<DataType> waitForCoercion = fmtInPredicate.children()
-                .stream()
-                .map(Expression::getDataType).collect(Collectors.toList());
-        Optional<DataType> optionalCommonType;
-        if (GlobalVariable.enableNewTypeCoercionBehavior) {
-            optionalCommonType = 
TypeCoercionUtils.findWiderCommonType(waitForCoercion, false, false);
-        } else {
-            optionalCommonType = 
TypeCoercionUtils.findWiderCommonTypeForComparison(waitForCoercion, true);
-        }
+        Optional<DataType> optionalCommonType = 
findWiderCommonTypeForExpressionsByVariable(

Review Comment:
   [P2] Do not let one impossible option invalidate the whole IN list
   
   This all-or-nothing common-type search rejects a useful predicate such as 
`ts IN (CAST('2024-01-02 03:04:05.123456' AS DATETIMEV2(6)), CAST('2262-04-11 
23:47:16.854776' AS DATETIMEV2(6)))`: the first option is exactly representable 
and can match, while the second is above the TIMESTAMP_NS maximum and can never 
match. Each equivalent mixed equality is supported by the exact comparison 
path, yet the non-representable option makes the entire `IN` fail analysis. 
Please eliminate or lower options individually while preserving NULL/NOT IN 
three-valued semantics, and change the current expected-error coverage into a 
result test.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/TimeStampNsLiteral.java:
##########
@@ -0,0 +1,347 @@
+// 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.nereids.trees.expressions.literal;
+
+import org.apache.doris.analysis.LiteralExpr;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.DateTimeType;
+import org.apache.doris.nereids.types.DateTimeV2Type;
+import org.apache.doris.nereids.types.TimeStampNsType;
+import org.apache.doris.nereids.types.TimeStampTzType;
+import org.apache.doris.nereids.types.TimeV2Type;
+import org.apache.doris.nereids.util.DateUtils;
+
+import java.math.BigInteger;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
+import java.time.temporal.ChronoField;
+import java.time.temporal.TemporalAccessor;
+import java.time.temporal.TemporalQueries;
+import java.util.Objects;
+
+/** Literal for the fixed nanosecond-precision TIMESTAMP_NS type. */
+public final class TimeStampNsLiteral extends DateLiteral {
+    private static final long NANOS_PER_SECOND = 1_000_000_000L;
+    private static final long MAX_NANOSECOND = NANOS_PER_SECOND - 1;
+    private static final LocalDateTime MIN_VALUE
+            = LocalDateTime.of(1677, 9, 21, 0, 12, 43, 145224192);
+    private static final LocalDateTime MAX_VALUE
+            = LocalDateTime.of(2262, 4, 11, 23, 47, 16, 854775807);
+
+    private final long hour;
+    private final long minute;
+    private final long second;
+    private final long nanosecond;
+
+    public TimeStampNsLiteral(String value) {
+        this(parse(value));
+    }
+
+    /** Construct a TIMESTAMP_NS literal from civil datetime fields. */
+    public TimeStampNsLiteral(long year, long month, long day, long hour, long 
minute, long second,
+            long nanosecond) {
+        super(TimeStampNsType.INSTANCE, year, month, day);
+        this.hour = hour;
+        this.minute = minute;
+        this.second = second;
+        this.nanosecond = nanosecond;
+        if (checkRange()) {
+            throw new AnalysisException("timestamp_ns literal [" + toString()
+                    + "] is outside Int64 epoch nanosecond range");
+        }
+    }
+
+    private TimeStampNsLiteral(LocalDateTime value) {
+        this(value.getYear(), value.getMonthValue(), value.getDayOfMonth(),
+                value.getHour(), value.getMinute(), value.getSecond(), 
value.getNano());
+    }
+
+    private static LocalDateTime parse(String value) {
+        TemporalAccessor temporal = parseDateTime(value, 
DateUtils.NANOSECOND_SCALE + 1).get();
+        long year = DateUtils.getOrDefault(temporal, ChronoField.YEAR);
+        long month = DateUtils.getOrDefault(temporal, 
ChronoField.MONTH_OF_YEAR);
+        long day = DateUtils.getOrDefault(temporal, ChronoField.DAY_OF_MONTH);
+        long hour = DateUtils.getOrDefault(temporal, ChronoField.HOUR_OF_DAY);
+        long minute = DateUtils.getOrDefault(temporal, 
ChronoField.MINUTE_OF_HOUR);
+        long second = DateUtils.getOrDefault(temporal, 
ChronoField.SECOND_OF_MINUTE);
+
+        LocalDateTime result = LocalDateTime.of((int) year, (int) month, (int) 
day,
+                (int) hour, (int) minute, (int) second,
+                DateUtils.getOrDefault(temporal, ChronoField.NANO_OF_SECOND));
+        if (DateUtils.getNanosecondGuardDigit(value) >= 5) {
+            result = result.plusNanos(1);
+        }
+
+        ZoneId zoneId = temporal.query(TemporalQueries.zone());
+        if (zoneId != null) {
+            Instant instant = DateUtils.convertLocalToInstant(result, zoneId);

Review Comment:
   [P2] Preserve nanoseconds when a named-zone local time is in a DST gap
   
   For a UTC session, folding `CAST('2024-03-10 
02:30:00.123456789America/New_York' AS TIMESTAMP_NS)` reaches this call with 
`.123456789`, but `DateUtils.convertLocalToInstant` returns the transition's 
integral instant for the skipped local time and drops that fraction. FE 
therefore folds the value to `2024-03-10 07:00:00.000000000`, while the BE 
parser resolves the civil second and then restores the parsed nanoseconds, 
producing `2024-03-10 07:00:00.123456789` when folding is disabled. Please use 
the fraction-preserving conversion policy here and add a paired folded/runtime 
named-zone gap case.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to