[ https://issues.apache.org/jira/browse/CALCITE-5146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17534207#comment-17534207 ]
itxiangkui edited comment on CALCITE-5146 at 5/10/22 7:52 AM: -------------------------------------------------------------- A bug that would trigger a floating-point overflow? was (Author: JIRAUSER286541): A bug that would trigger a floating-point overflow > Udf-Timestamp Function Rel get a weird value > -------------------------------------------- > > Key: CALCITE-5146 > URL: https://issues.apache.org/jira/browse/CALCITE-5146 > Project: Calcite > Issue Type: Bug > Affects Versions: 1.30.0 > Reporter: itxiangkui > Priority: Major > > I have defined several UDFs: > {code:java} > public static String from_unixtime(long unixTimestamp, String format) { > try { > if (String.valueOf(unixTimestamp).length() == 10) { > unixTimestamp = 1000 * > Long.parseLong(String.valueOf(unixTimestamp)); > } > return DateFormatUtils.format(unixTimestamp, format); > } catch (Exception e) { > return null; > } > } {code} > > {code:java} > private static final TimeZone DEFAULT_BEIJING_TIME_ZONE = > TimeZone.getTimeZone(ZoneId.of("Asia/Shanghai")); > public static long unix_timestamp(String dateStr) { > long ts = parseToTimeMillis(dateStr, DEFAULT_BEIJING_TIME_ZONE); > return ts / 1000; > }{code} > > > *{color:#ff8b00}But from_unixtime got a wrong parameter when you subtract 25 > days{color}* > > {code:java} > 0: jdbc:avatica:remote:url=http://localhost:6> select > from_unixtime(unix_timestamp(timestamp'2022-05-01')*1000-24*86400000,'yyyy-MM-dd'); > +------------+ > | EXPR$0 | > +------------+ > | 2022-04-07 | > +------------+ > 1 row selected (0.049 seconds) > 0: jdbc:avatica:remote:url=http://localhost:6> select > from_unixtime(unix_timestamp(timestamp'2022-05-01')*1000-25*86400000,'yyyy-MM-dd'); > +------------+ > | EXPR$0 | > +------------+ > | 2022-05-25 | > +------------+ > {code} > > > > > -- This message was sent by Atlassian Jira (v8.20.7#820007)