AMashenkov commented on code in PR #3558:
URL: https://github.com/apache/ignite-3/pull/3558#discussion_r1554070793


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/exp/IgniteSqlFunctions.java:
##########
@@ -574,6 +575,75 @@ public static Long subtractTimeZoneOffset(long timestamp, 
TimeZone timeZone) {
         return timestamp - offset;
     }
 
+    /**
+     * Helper for CAST({timestamp} AS VARCHAR(n)).
+     *
+     * <p>Note: this method is a copy of the avatica {@link 
DateTimeUtils#unixTimestampToString(long, int)} method,
+     *          with the only difference being that it does not add trailing 
zeros.
+     */
+    public static String unixTimestampToString(long timestamp, int precision) {
+        IgniteStringBuilder buf = new IgniteStringBuilder(17);
+        int date = (int) (timestamp / DateTimeUtils.MILLIS_PER_DAY);
+        int time = (int) (timestamp % DateTimeUtils.MILLIS_PER_DAY);
+
+        if (time < 0) {
+            --date;
+
+            time += (int) DateTimeUtils.MILLIS_PER_DAY;
+        }
+
+        buf.app(DateTimeUtils.unixDateToString(date)).app(' ');
+
+        unixTimeToString(buf, time, precision);
+
+        return buf.toString();
+    }
+
+    /**
+     * Helper for CAST({time} AS VARCHAR(n)).
+     *
+     * <p>Note: this method is a copy of the avatica {@link 
DateTimeUtils#unixTimestampToString(long, int)} method,
+     *          with the only difference being that it does not add trailing 
zeros.
+     */
+    public static String unixTimeToString(int time, int precision) {
+        IgniteStringBuilder buf = new IgniteStringBuilder(8);

Review Comment:
   I guess default buffer size is '8'  for precision '0'.
   Should it be `8+ (precision>0) ? 1 + precision: 0 `?



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

Reply via email to