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

Chun Chang commented on DRILL-861:
----------------------------------

here is the plan:

0: jdbc:drill:schema=dfs> explain plan for select sum(cast(c_decimal38 as 
decimal(38,14))) from data where c_row <= 14;
+------------+------------+
|    text    |    json    |
+------------+------------+
| 00-00    Screen
00-01      StreamAgg(group=[{}], EXPR$0=[SUM($0)])
00-02        UnionExchange
01-01          StreamAgg(group=[{}], EXPR$0=[SUM($0)])
01-02            Project($f0=[CAST($2):DECIMAL(38, 14)])
01-03              SelectionVectorRemover
01-04                Filter(condition=[<=($1, 14)])
01-05                  Scan(groupscan=[ParquetGroupScan 
[entries=[ReadEntryWithPath [path=maprfs:/user/root/mondrian/data]], 
selectionRoot=/user/root/mondrian/data, columns=[SchemaPath [`c_row`], 
SchemaPath [`c_decimal38`]]]])
 | {
  "head" : {
    "version" : 1,
    "generator" : {
      "type" : "ExplainHandler",
      "info" : ""
    },
    "type" : "APACHE_DRILL_PHYSICAL",
    "options" : [ ],
    "resultMode" : "EXEC"
  },
  "graph" : [ {
    "pop" : "parquet-scan",
    "@id" : 65541,
    "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_decimal38`" ],
    "selectionRoot" : "/user/root/mondrian/data"
  }, {
    "pop" : "filter",
    "@id" : 65540,
    "child" : 65541,
    "expr" : "less_than_or_equal_to(`c_row`, 14) ",
    "initialAllocation" : 1000000,
    "maxAllocation" : 10000000000
  }, {
    "pop" : "selection-vector-remover",
    "@id" : 65539,
    "child" : 65540,
    "initialAllocation" : 1000000,
    "maxAllocation" : 10000000000
  }, {
    "pop" : "project",
    "@id" : 65538,
    "exprs" : [ {
      "ref" : "`$f0`",
      "expr" : "cast( (`c_decimal38` ) as DECIMAL38SPARSE(38, 14) )"
    } ],
    "child" : 65539,
    "initialAllocation" : 1000000,
    "maxAllocation" : 10000000000
  }, {
    "pop" : "streaming-aggregate",
    "@id" : 65537,
    "child" : 65538,
    "keys" : [ ],
    "exprs" : [ {
      "ref" : "`EXPR$0`",
      "expr" : "sum(`$f0`) "
    } ],
    "initialAllocation" : 1000000,
    "maxAllocation" : 10000000000
  }, {
    "pop" : "union-exchange",
    "@id" : 2,
    "child" : 65537,
    "initialAllocation" : 1000000,
    "maxAllocation" : 10000000000
  }, {
    "pop" : "streaming-aggregate",
    "@id" : 1,
    "child" : 2,
    "keys" : [ ],
    "exprs" : [ {
      "ref" : "`EXPR$0`",
      "expr" : "sum(`EXPR$0`) "
    } ],
    "initialAllocation" : 1000000,
    "maxAllocation" : 10000000000
  }, {
    "pop" : "screen",
    "@id" : 0,
    "child" : 1,
    "initialAllocation" : 1000000,
    "maxAllocation" : 10000000000
  } ]
} |
+------------+------------+
1 row selected (0.228 seconds)

> sum(decimal38) gives wrong result, even without overflowing
> -----------------------------------------------------------
>
>                 Key: DRILL-861
>                 URL: https://issues.apache.org/jira/browse/DRILL-861
>             Project: Apache Drill
>          Issue Type: Bug
>          Components: Functions - Drill
>            Reporter: Chun Chang
>            Assignee: Mehant Baid
>
> #Wed May 28 17:19:59 PDT 2014
> git.commit.id.abbrev=c8a08c3
> sum over decimal38 type of data gives wrong result. this is without encounter 
> overflowing.
> I have the following data in a decimal38 column:
> 0: jdbc:drill:schema=dfs> select cast(c_decimal38 as decimal(38,14)) from 
> data where c_row <= 14;
> +------------+
> |   EXPR$0   |
> +------------+
> | 0E-14      |
> | 1.00000000000000 |
> | 123456789.00000000000000 |
> | 999999999.00000000000000 |
> | -999999999.00000000000000 |
> | 1.000000E-8 |
> | -1.000000E-8 |
> | 12345.67890000000000 |
> | 123456789.12345678900000 |
> | 999999999999999999.00000000000000 |
> | -999999999999999999.00000000000000 |
> | 0E-14      |
> | 0E-14      |
> | 12345678901234.12345678901234 |
> +------------+
> 14 rows selected (0.288 seconds)
> The sum of the columns gives the following wrong number:
> 0: jdbc:drill:schema=dfs> select sum(cast(c_decimal38 as decimal(38,14))) 
> from data where c_row <= 14;
> +------------+
> |   EXPR$0   |
> +------------+
> | 1.2345925827186123E13 |
> The correct number should be (from postgres, I also hand calculated):
> foodmart=# select sum(cast(c_decimal38 as decimal(38,14))) from data where 
> c_row <= 14;
>               sum
> -------------------------------
>  12345925827158.92581357801234



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

Reply via email to