xtern commented on code in PR #6274:
URL: https://github.com/apache/ignite-3/pull/6274#discussion_r2239182369


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/exp/IgniteSqlFunctions.java:
##########
@@ -362,8 +363,33 @@ public static BigDecimal toBigDecimal(Number value, int 
precision, int scale) {
         }
     }
 
+    /** Adjusts precision of {@link SqlTypeName#TIME} value. */
+    public static @Nullable Integer toTimeExact(@Nullable Object object, int 
precision) {
+        if (object == null) {
+            return null;
+        }
+
+        assert object instanceof Integer : object.getClass();
+
+        return toTimeExact((int) object, precision);
+    }
+
+    /** Adjusts precision of {@link SqlTypeName#TIME} value. */
+    public static int toTimeExact(int val, int precision) {
+        assert precision >= 0 : "Invalid precision: " + precision;
+
+        return IgniteSqlDateTimeUtils.adjustTimeMillis(val, precision);
+    }
+
+    /** Adjusts precision of {@link SqlTypeName#TIME} value. */
+    public static int toTimeExact(long val, int precision) {

Review Comment:
   I was thinking about another method `toTimeExact(int, int)`, sorry for the 
misunderstanding.
   This method (long, int) is called during interval arithmetic.
   ```sql
   SELECT ? + INTERVAL 1 DAY
   ```
   We generate something like this
   ```java
   outBuilder.addField(value_dynamic_param == null ? 0 : 
IgniteSqlFunctions.toTimeExact(Math.floorMod(IgniteMath.addExact(value_dynamic_param.intValue(),
 (int) Math.floorMod(IgniteMath.multiplyExact(1, 86400000L), 86400000L)), 
86400000L), 6));
   ```
   The minor issue here - Math.floorMod(long, long) is called instead of 
floorMod(int, int).
   This happens because RexImpTable#normalize calls method 
`FLOOR_MOD(Math.class, "floorMod", long.class, long.class)` . And return value 
is long.
   
   I couldn't reproduce the case where `toTimeExact(long, int)` needed to 
adjust fractions of a second, but for consistency I kept that adjustment.
   
   Another way - I can introduce our own Ignite method `floorMod(int, int)` and 
use it in `normalize` :thinking: 
   



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