benj created DRILL-7519:
---------------------------

             Summary: Error on case when different branche are array of same 
type but build differenlty
                 Key: DRILL-7519
                 URL: https://issues.apache.org/jira/browse/DRILL-7519
             Project: Apache Drill
          Issue Type: Bug
    Affects Versions: 1.17.0
            Reporter: benj


With 3 array build like
{code:sql}
SELECT T.s, typeof(T.s), modeof(T.s)
      ,T.j, typeof(T.j), modeof(T.j)
      ,T.j2.a, typeof(T.j2.a), modeof(T.j2.a)
FROM (
 SELECT split('a,b',',') as s
 , convert_fromJSON('["c","d"]') AS j
 , convert_fromJSON('{"tag":["e","f"]}') AS j2
) AS T
+-----------+---------+--------+-----------+---------+--------+-----------+---------+--------+
|     s     | EXPR$1  | EXPR$2 |     j     | EXPR$4  | EXPR$5 |  EXPR$6   | 
EXPR$7  | EXPR$8 |
+-----------+---------+--------+-----------+---------+--------+-----------+---------+--------+
| ["a","b"] | VARCHAR | ARRAY  | ["c","d"] | VARCHAR | ARRAY  | ["e","f"] | 
VARCHAR | ARRAY  |
+-----------+---------+--------+-----------+---------+--------+-----------+---------+--------+
{code}
it's possible to use *s* and *j* in the branch of the same case, but it's not 
possible to use *s or j* in accordance with *j2.tag*
{code:sql}
SELECT CASE WHEN true THEN T.s ELSE T.j END
     , CASE WHEN false THEN T.s ELSE T.j END
FROM (
 SELECT split('a,b',',') AS s
      , convert_fromJSON('["c","d"]') AS j
      , convert_fromJSON('{"tag":["e","f"]}') AS j2
) AS T
+-----------+-----------+
|  EXPR$0   |  EXPR$1   |
+-----------+-----------+
| ["a","b"] | ["c","d"] |
+-----------+-----------+

SELECT CASE WHEN true THEN T.j2.tag ELSE T.s /*idem with T.j*/ END
     , CASE WHEN false THEN T.j2.tag ELSE T.s /*idem with T.j*/ END
 FROM (SELECT split('a,b',',') AS s, convert_fromJSON('["c","d"]') AS j, 
convert_fromJSON('{"tag":["e","f"]}') AS j2) AS T;
+-----------+-----------+
|  EXPR$0   |  EXPR$1   |
+-----------+-----------+
| ["e","f"] | ["a","b"] |
+-----------+-----------+

/* But surprisingly */
SELECT CASE WHEN false THEN T.j2.tag ELSE T.s /*idem with T.j*/ END
FROM (SELECT split('a,b',',') AS s, convert_fromJSON('["c","d"]') AS j, 
convert_fromJSON('{"tag":["e","f"]}') AS j2) AS T;
Error: SYSTEM ERROR: NullPointerException

/* and */
SELECT CASE WHEN true THEN T.j2.tag ELSE T.s /*idem with T.j*/ END
FROM (SELECT split('a,b',',') AS s, convert_fromJSON('["c","d"]') AS j, 
convert_fromJSON('{"tag":["e","f"]}') AS j2) AS T;
+-----------+
|  EXPR$0   |
+-----------+
| ["e","f"] |
+-----------+

{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to