IMPALA-1559: FIRST_VALUE rewrite fn type might not match slot type

In some cases, the lookup for the first_value_rewrite function could
return a different fn with the wrong (yet technically compatible) type.

first_value_rewrite takes 2 parameters, the first is the parameter to
first_value, and the second is an integer explicitly added by the FE during
analysis. first_value_rewrite has signatures where the first parameter can
be of any type and the second is always a BIGINT. When the FE inserts the
second parameter, it may not actually be a BIGINT (e.g. it could be a
TINYINT, SMALLINT, etc.). In this case, the function arguments will not
match one of the registered signatures exactly and some compatable function
will be returned. For example, FIRST_VALUE(1.1) has a DECIMAL parameter
and if a TINYINT/SMALLINT/INT parameter is added for the rewrite, then
the first_value_rewrite fn lookup happened to match the fn taking a
FLOAT and BIGINT. (Ideally DECIMAL would not be implicitly castable to
a FLOAT/DOUBLE, but NumericLiterals do allow this casting.)

As a result, the agg fn actually returned a FLOAT while the AnalyticExpr
was of the type DECIMAL, and the analytic tuple contained a DECIMAL slot
which would throw a DCHECK in the BE (or perhaps crash in retail builds).

This fixes the issue by setting the NumericLiterals to be explicitlyCast,
i.e. the type will not change if re-analyzed. Then the correct fn signature
is found.

Change-Id: I1cefa3e29734ae647bd690263bb63f08f10ea8b9
Reviewed-on: http://gerrit.cloudera.org:8080/136
Reviewed-by: Alex Behm <alex.behm@cloudera.com>
Tested-by: Internal Jenkins
This commit is contained in:
Matthew Jacobs
2015-03-02 18:44:16 -08:00
committed by Internal Jenkins
parent d2988f8b11
commit 0c8022b9bc
4 changed files with 31 additions and 2 deletions

View File

@@ -1079,3 +1079,25 @@ select max(t3.c1) from
---- TYPES
STRING
====
---- QUERY
# IMPALA-1559: FIRST_VALUE rewrite function intermediate type not matching slot type
select
first_value(c3) over (order by c3 rows between 92 preceding and current row),
first_value(c2) over (order by c3 rows between 92 preceding and 1 preceding),
first_value(-32.9) over (order by c3 rows between 92 preceding and unbounded following),
first_value(1.1) over (order by c3 rows between 92 preceding and 1 preceding)
from decimal_tiny where c3 = 0.0
---- RESULTS
0.0,NULL,-32.9,NULL
0.0,100.00000,-32.9,1.1
0.0,100.00000,-32.9,1.1
0.0,100.00000,-32.9,1.1
0.0,100.00000,-32.9,1.1
0.0,100.00000,-32.9,1.1
0.0,100.00000,-32.9,1.1
0.0,100.00000,-32.9,1.1
0.0,100.00000,-32.9,1.1
0.0,100.00000,-32.9,1.1
---- TYPES
DECIMAL, DECIMAL, DECIMAL, DECIMAL
====