[
https://issues.apache.org/jira/browse/DRILL-2355?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14364639#comment-14364639
]
Mehant Baid commented on DRILL-2355:
------------------------------------
The results seem to be correct (numerically), the difference is that in Drill's
output we still have the decimal point in some cases (extra .0 in the result).
This is because we always bind trunc() functions with two input parameters to
the function holder with output type of float8. The main reason we do this is
because trunc's input is float8 even if we specified the rounding parameter to
be such that we don't need the fractional part the integer portion of float8
might still be too big to be stored in a bigint. Marking this as minor.
> TRUNC function returns incorrect result when second parameter is specified
> --------------------------------------------------------------------------
>
> Key: DRILL-2355
> URL: https://issues.apache.org/jira/browse/DRILL-2355
> Project: Apache Drill
> Issue Type: Bug
> Components: Functions - Drill
> Affects Versions: 0.8.0
> Reporter: Victoria Markman
> Assignee: Mehant Baid
> Fix For: 0.9.0
>
>
> I believe our TRUNC function is modeled on Postgres TRUNC function.
> Semandics of Postgres TRUNC function:
> {code}
> postgres=# select trunc(1234.1234);
> trunc
> -------
> 1234
> (1 row)
> postgres=# select trunc(1234.1234, 0);
> trunc
> -------
> 1234
> (1 row)
> postgres=# select trunc(1234.1234, 2);
> trunc
> ---------
> 1234.12
> (1 row)
> postgres=# select trunc(1234.1234, -1);
> trunc
> -------
> 1230
> (1 row)
> postgres=# select trunc(1234.1234, -3);
> trunc
> -------
> 1000
> (1 row)
> {code}
> This is incorrect, I can't truncate to zero decimal places:
> {code}
> 0: jdbc:drill:schema=dfs> select trunc(1234.1234) from sys.options limit 1;
> +------------+
> | EXPR$0 |
> +------------+
> | 1234.0 |
> +------------+
> 1 row selected (0.133 seconds)
> 0: jdbc:drill:schema=dfs> select trunc(1234.1234,0) from sys.options limit 1;
> +------------+
> | EXPR$0 |
> +------------+
> | 1234.0 |
> +------------+
> 1 row selected (0.065 seconds)
> {code}
> Second negative parameter, does not do what it is supposed to do as well:
> {code}
> 0: jdbc:drill:schema=dfs> select trunc(1234.1234, -1) from sys.options limit
> 1;
> +------------+
> | EXPR$0 |
> +------------+
> | 1230.0 |
> +------------+
> 1 row selected (0.068 seconds)
> 0: jdbc:drill:schema=dfs> select trunc(1234.1234, -3) from sys.options limit
> 1;
> +------------+
> | EXPR$0 |
> +------------+
> | 1000.0 |
> +------------+
> 1 row selected (0.072 seconds)
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)