Uploaded image for project: 'Apache Drill'
  1. Apache Drill
  2. DRILL-4944

incorrect results - case expression

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Won't Fix
    • 1.9.0
    • None
    • Execution - Flow
    • None

    Description

      Drill 1.9.0 (git commit id: 4edabe7a) returns null, which is wrong.

       0: jdbc:drill:schema=dfs.tmp> SELECT res2, case res2 WHEN 0.1 THEN 0.9999 ELSE null END
      . . . . . . . . . . . . . . > FROM
      . . . . . . . . . . . . . . > (
      . . . . . . . . . . . . . . >     SELECT
      . . . . . . . . . . . . . . >     (CASE WHEN (false) THEN null ELSE CAST(0.1 as float) end) res2
      . . . . . . . . . . . . . . >     FROM (values(1)) foo
      . . . . . . . . . . . . . . > ) foobar ;
      +-------+---------+
      | res2  | EXPR$1  |
      +-------+---------+
      | 0.1   | null    |
      +-------+---------+
      1 row selected (0.106 seconds)
       

      Postgres returns correct results

       postgres=# SELECT res2, case res2 WHEN 0.1 THEN 0.9999 ELSE null END
      postgres-# FROM
      postgres-# (
      postgres(#     SELECT
      postgres(#     (CASE WHEN (false) THEN null ELSE CAST(0.1 as float) end) res2
      postgres(#     FROM (values(1)) foo
      postgres(# ) foobar ;
       res2 |  case
      ------+--------
        0.1 | 0.9999
      (1 row)
       

      Calcite also returns correct results

       0: jdbc:calcite:model=target/test-classes/mod> SELECT res2, case res2 WHEN 0.1 THEN 0.9999 ELSE null END
      . . . . . . . . . . . . . . . . . . . . . . .> FROM
      . . . . . . . . . . . . . . . . . . . . . . .> (
      . . . . . . . . . . . . . . . . . . . . . . .>       SELECT
      . . . . . . . . . . . . . . . . . . . . . . .>          (CASE WHEN (false) THEN null ELSE CAST(0.1 as float) end) res2
      . . . . . . . . . . . . . . . . . . . . . . .>      FROM (values(1)) foo
      . . . . . . . . . . . . . . . . . . . . . . .> ) foobar ;
      +-----------------+--------+
      |      RES2       | EXPR$1 |
      +-----------------+--------+
      | 0.1             | 0.9999 |
      +-----------------+--------+
      1 row selected (1.277 seconds)
       

      Details of explain plan from Drill 1.9.0

       0: jdbc:drill:schema=dfs.tmp> explain plan for SELECT res2, case res2 WHEN 0.1 THEN 0.9999 ELSE null END
      . . . . . . . . . . . . . . > FROM
      . . . . . . . . . . . . . . > (
      . . . . . . . . . . . . . . >       SELECT
      . . . . . . . . . . . . . . >          (CASE WHEN (false) THEN null ELSE CAST(0.1 as float) end) res2
      . . . . . . . . . . . . . . >      FROM (values(1)) foo
      . . . . . . . . . . . . . . > ) foobar ;
      +------+------+
      | text | json |
      +------+------+
      | 00-00    Screen
      00-01      Project(res2=[$0], EXPR$1=[$1])
      00-02        Project(res2=[CASE(false, null, 0.1)], EXPR$1=[CASE(=(CASE(false, null, 0.1), 0.1), 0.9999, null)])
      00-03          Values
       | {
        "head" : {
          "version" : 1,
          "generator" : {
            "type" : "ExplainHandler",
            "info" : ""
          },
          "type" : "APACHE_DRILL_PHYSICAL",
          "options" : [ ],
          "queue" : 0,
          "resultMode" : "EXEC"
        },
        "graph" : [ {
          "pop" : "Values",
          "@id" : 3,
          "content" : [ {
            "EXPR$0" : {
              "$numberLong" : 1
            }
          } ],
          "initialAllocation" : 1000000,
          "maxAllocation" : 10000000000,
          "cost" : 1.0
        }, {
          "pop" : "project",
          "@id" : 2,
          "exprs" : [ {
            "ref" : "`res2`",
            "expr" : " ( if (false ) then (NULL )  else (0.1 )  end  ) "
          }, {
            "ref" : "`EXPR$1`",
            "expr" : " ( if (equal( ( if (false ) then (NULL )  else (0.1 )  end  ) , 0.1)  ) then (0.9999 )  else (NULL )  end  ) "
          } ],
          "child" : 3,
          "initialAllocation" : 1000000,
          "maxAllocation" : 10000000000,
          "cost" : 1.0
        }, {
          "pop" : "project",
          "@id" : 1,
          "exprs" : [ {
            "ref" : "`res2`",
            "expr" : "`res2`"
          }, {
            "ref" : "`EXPR$1`",
            "expr" : "`EXPR$1`"
          } ],
          "child" : 2,
          "initialAllocation" : 1000000,
          "maxAllocation" : 10000000000,
          "cost" : 1.0
        }, {
          "pop" : "screen",
          "@id" : 0,
          "child" : 1,
          "initialAllocation" : 1000000,
          "maxAllocation" : 10000000000,
          "cost" : 1.0
        } ]
      } |
       

      Attachments

        Activity

          People

            sharnyk Serhii Harnyk
            khfaraaz Khurram Faraaz
            Khurram Faraaz Khurram Faraaz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: