[ 
https://issues.apache.org/jira/browse/DRILL-799?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14010655#comment-14010655
 ] 

Mehant Baid commented on DRILL-799:
-----------------------------------

The problem is we are using Math.pow() to adjust the scale of the input. 
Math.pow() returns double which is imprecise and hence while multiplying it 
with a large number (16 digit number in this case) it adds some noise to the 
actual input. Instead of using Math.pow() we should move to a static list of 
table containing powers of 10 we are interested in. 

> cast bigint to decimal adds values after decimal points
> -------------------------------------------------------
>
>                 Key: DRILL-799
>                 URL: https://issues.apache.org/jira/browse/DRILL-799
>             Project: Apache Drill
>          Issue Type: Bug
>          Components: Functions - Drill
>            Reporter: Chun Chang
>            Assignee: Mehant Baid
>
> tested use git.commit.id.abbrev=5d7e3d3
> when casting bigint, we add values after decimal points:
> 0: jdbc:drill:schema=dfs> select c_bigint, cast(c_bigint as decimal(18,2)) 
> from data where c_row = 9;
> +------------+------------+
> |  c_bigint  |   EXPR$1   |
> +------------+------------+
> | -4567890123456789 | -4567890123456789.12 |
> +------------+------------+
> 0: jdbc:drill:schema=dfs> explain plan for select c_bigint, cast(c_bigint as 
> decimal(18,2)) from data where c_row = 9;
> +------------+------------+
> |    text    |    json    |
> +------------+------------+
> | ScreenPrel
>   ProjectPrel(c_bigint=[$2], EXPR$1=[CAST($2):DECIMAL(18, 2)])
>     FilterPrel(condition=[=(CAST($1):INTEGER, 9)])
>       ScanPrel(groupscan=[ParquetGroupScan [entries=[ReadEntryWithPath 
> [path=maprfs:/user/root/mondrian/data]], 
> selectionRoot=/user/root/mondrian/data, columns=[SchemaPath [`c_row`], 
> SchemaPath [`c_bigint`]]]])
>  | {
>   "head" : {
>     "version" : 1,
>     "generator" : {
>       "type" : "ExplainHandler",
>       "info" : ""
>     },
>     "type" : "APACHE_DRILL_PHYSICAL",
>     "options" : [ ],
>     "resultMode" : "EXEC"
>   },
>   "graph" : [ {
>     "pop" : "parquet-scan",
>     "@id" : 1,
>     "entries" : [ {
>       "path" : "maprfs:/user/root/mondrian/data"
>     } ],
>     "storage" : {
>       "type" : "file",
>       "connection" : "maprfs:///",
>       "workspaces" : {
>         "default" : {
>           "location" : "/user/root/mondrian/",
>           "writable" : false,
>           "storageformat" : null
>         },
>         "home" : {
>           "location" : "/",
>           "writable" : false,
>           "storageformat" : null
>         },
>         "root" : {
>           "location" : "/",
>           "writable" : false,
>           "storageformat" : null
>         },
>         "tmp" : {
>           "location" : "/tmp",
>           "writable" : true,
>           "storageformat" : "csv"
>         }
>       },
>       "formats" : {
>         "psv" : {
>           "type" : "text",
>           "extensions" : [ "tbl" ],
>           "delimiter" : "|"
>         },
>         "csv" : {
>           "type" : "text",
>           "extensions" : [ "csv" ],
>           "delimiter" : ","
>         },
>         "tsv" : {
>           "type" : "text",
>           "extensions" : [ "tsv" ],
>           "delimiter" : "\t"
>         },
>         "parquet" : {
>           "type" : "parquet"
>         },
>         "json" : {
>           "type" : "json"
>         }
>       }
>     },
>     "format" : {
>       "type" : "parquet"
>     },
>     "columns" : [ "`c_row`", "`c_bigint`" ],
>     "selectionRoot" : "/user/root/mondrian/data"
>   }, {
>     "pop" : "filter",
>     "@id" : 2,
>     "child" : 1,
>     "expr" : "equal(cast( (`c_row` ) as INT ), 9) ",
>     "initialAllocation" : 1000000,
>     "maxAllocation" : 10000000000
>   }, {
>     "pop" : "project",
>     "@id" : 3,
>     "exprs" : [ {
>       "ref" : "`c_bigint`",
>       "expr" : "`c_bigint`"
>     }, {
>       "ref" : "`EXPR$1`",
>       "expr" : "cast( (`c_bigint` ) as DECIMAL18(18, 2) )"
>     } ],
>     "child" : 2,
>     "initialAllocation" : 1000000,
>     "maxAllocation" : 10000000000
>   }, {
>     "pop" : "screen",
>     "@id" : 4,
>     "child" : 3,
>     "initialAllocation" : 1000000,
>     "maxAllocation" : 10000000000
>   } ]
> } |



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to