924060929 commented on code in PR #67238:
URL: https://github.com/apache/doris/pull/67238#discussion_r4439814178


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/SearchSignatureForDateDiff.java:
##########
@@ -0,0 +1,79 @@
+// 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.functions;
+
+import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.util.ExpressionUtils;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * Signature search for the {@code *_diff} functions, which list {@code 
(TIMESTAMPTZ, TIMESTAMPTZ)} first.
+ *
+ * <p>{@link SearchSignature} scores a string literal against the TIMESTAMPTZ 
overload by whether it
+ * carries a time zone, and breaks a remaining tie between the temporal 
overloads by list order. A
+ * string-typed argument that is not a literal, such as a VARCHAR column or a 
subquery or UNION
+ * output slot, gives it nothing to score, so the call bound TIMESTAMPTZ by 
list order and the value
+ * was cast through the session time zone (apache/doris#66120).
+ *
+ * <p>For that case only, when the call has a string-typed argument and no 
string literal to inspect,
+ * the TIMESTAMPTZ overload is tried after the others, so the call binds 
DATETIMEV2 as it does for
+ * zone-less literals. A call with an inspectable string literal is searched 
in list order with the
+ * usual score, so results for zoned, zone-less and mixed literals do not 
change.
+ */
+public interface SearchSignatureForDateDiff extends 
ExplicitlyCastableSignature {
+
+    @Override
+    default FunctionSignature searchSignature(List<FunctionSignature> 
signatures) {
+        List<Expression> arguments = getArguments();
+        if (hasStringArgument(arguments) && 
!hasInspectableStringLiteral(arguments)) {
+            return 
ExplicitlyCastableSignature.super.searchSignature(withTimeStampTzLast(signatures));

Review Comment:
   [P2] Preserve accepted zoned VARCHAR inputs when changing the overload
   
   For VARCHAR columns containing `1800-01-01 01:00:00-14:21` and `1800-01-01 
00:00:00-14:21`, the base binds `hours_diff(a,b)` to TIMESTAMPTZ and computes 
1. This branch instead inserts DATETIMEV2 casts. Both DATETIMEV2 parser paths 
in `cast_to_datetimev2_impl.hpp` reject offset minutes other than 0/30/45, so 
this previously supported input becomes NULL in non-strict mode or fails in 
strict mode. The TIMESTAMPTZ parser accepts it, and the base's 
`test_cast_timestamptz.groovy` explicitly covers `-14:21`. Preserve the 
accepted offset formats at the diff argument-conversion boundary while 
retaining wall-clock handling for zone-less strings, and add a VARCHAR-column 
regression. Confirmed by static tracing; no SQL was executed.



-- 
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