[
https://issues.apache.org/jira/browse/CALCITE-5146?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
itxiangkui updated CALCITE-5146:
--------------------------------
Description:
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}
was:
I have defined several UDFs:
{code:java}
// code placeholder
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}
//unix_timestamp
public long unix_timestamp(String dateStr) {
long ts = parseToTimeMillis(dateStr, DEFAULT_BEIJING_TIME_ZONE);
return ts / 1000;
}{code}
> 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)