korlov42 commented on code in PR #5682:
URL: https://github.com/apache/ignite-3/pull/5682#discussion_r2063383374


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/fun/IgniteSqlOperatorTable.java:
##########
@@ -60,16 +61,20 @@ public class IgniteSqlOperatorTable extends 
ReflectiveSqlOperatorTable {
     private static final SqlSingleOperandTypeChecker NOT_CUSTOM_TYPE =
             new NotCustomTypeOperandTypeChecker();
 
-    private static final SqlSingleOperandTypeChecker 
PLUS_OPERATOR_TYPES_CHECKER =
+    private static final SqlOperandTypeChecker DATETIME_MATCHING_INTERVAL = 
new SqlDateTimeIntervalTypeChecker(true);
+
+    private static final SqlOperandTypeChecker MATCHING_INTERVAL_DATETIME = 
new SqlDateTimeIntervalTypeChecker(false);
+
+    private static final SqlOperandTypeChecker PLUS_OPERATOR_TYPES_CHECKER =
             OperandTypes.NUMERIC_NUMERIC.and(SAME_SAME)
                     .or(OperandTypes.INTERVAL_SAME_SAME)
-                    .or(OperandTypes.DATETIME_INTERVAL.and(NOT_CUSTOM_TYPE))
-                    .or(OperandTypes.INTERVAL_DATETIME.and(NOT_CUSTOM_TYPE));
+                    
.or(OperandTypes.DATETIME_INTERVAL.and(DATETIME_MATCHING_INTERVAL).and(NOT_CUSTOM_TYPE))
+                    
.or(OperandTypes.INTERVAL_DATETIME.and(MATCHING_INTERVAL_DATETIME).and(NOT_CUSTOM_TYPE));

Review Comment:
   why do we still use default checkers like `OperandTypes.INTERVAL_DATETIME`?



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/fun/SqlDateTimeIntervalTypeChecker.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.ignite.internal.sql.engine.sql.fun;
+
+import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
+
+import java.util.Map;
+import java.util.Set;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlCallBinding;
+import org.apache.calcite.sql.SqlOperandCountRange;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.type.SqlOperandCountRanges;
+import org.apache.calcite.sql.type.SqlOperandTypeChecker;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.type.SqlTypeUtil;
+
+/**
+ * Type checking strategy for DATETIME + INTERVAL / INTERVAL + DATETIME / 
DATETIME - INTERVAL operations.
+ * This strategy only permits operands in which all fields of interval 
operand's type can be included in datetime operand's type. Examples:
+ * <ul>
+ *     <li>it permits {@code TIME op DAY TO SECOND INTERVALS} but does not 
allow {@code TIME op INTERVAL_MONTHS},
+ *     because the time type consists of hours, minutes, seconds. The day 
component is ignored.</li>
+ *     <li>it permits {@code DATE op INTERVAL (any interval type)}, because 
the date type includes both years, month, and days.
+ *     and that a sub-day interval is converted to day intervals e.g. {@code 
25 HOURS} is {@code 1 DAY},
+ *     {@code 5 SECONDS} = {@code 0 DAYS}, {@code 1440 MINUTES} is {@code 1 
DAY}.
+ *     </li>
+ *     <li>it permits {@code TIMESTAMP op INTERVAL (any interval type)}, 
because the timestamp type consists of fields from both the date
+ *     and the time types.</li>
+ * </ul>
+ */
+public class SqlDateTimeIntervalTypeChecker implements SqlOperandTypeChecker {
+
+    private static final Map<SqlTypeName, Set<SqlTypeName>> 
MATCHING_INTERVAL_TYPES = Map.of(
+            SqlTypeName.TIME, Set.of(
+                    SqlTypeName.INTERVAL_DAY,

Review Comment:
   Can we replace explicit enumeration with `SqlTypeName.DAY_INTERVAL_TYPES`?



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to