mirror of
https://github.com/apache/impala.git
synced 2026-01-05 21:00:54 -05:00
This patch changes the resolution of overloaded functions so that we prefer functions where there is no loss of precision in argument types. Previously, the logic would happily convert DECIMAL to FLOAT even if there was a more suitable overload available. E.g. greatest(TINYINT, DECIMAL) was resolved to greatest(FLOAT...) instead of greatest(DECIMAL). This only changes behaviour when no overload exactly matches the argument types, but the arguments can be converted with no loss of precision, e.g. TINYINT to DECIMAL. This patch introduces a conceptual distinction between strict and non-strict compatibility. All contexts aside from function matching use non-strict to support the current behavior of implicitly casting decimals to floats/doubles. This patch also makes resolution of overloaded functions consistent regardless of what order functions were added to the Db - overloads are checked in a canonical order. Switching to this canonical order revealed further problems with overload resolution where the correct overload was selected only because of the order in which it was added to the database. For example, the logic equally preferred resolving fn(STRING, TINYINT) to fn(TIMESTAMP, INT) or fn(STRING, INT). This required changes to the compatibility matrix. Various cleanup and simplification of the type compatibility logic is also included. Change-Id: I50e657c78cdcb925b616b5b088b801510020e255 Reviewed-on: http://gerrit.cloudera.org:8080/845 Reviewed-by: Tim Armstrong <tarmstrong@cloudera.com> Tested-by: Internal Jenkins
155 lines
3.3 KiB
Plaintext
155 lines
3.3 KiB
Plaintext
====
|
|
---- QUERY
|
|
# testtbl is empty
|
|
select * from testtbl
|
|
---- TYPES
|
|
bigint, string, int
|
|
---- RESULTS
|
|
====
|
|
---- QUERY
|
|
# month ends at 12
|
|
select int_col from alltypessmall where month > 100
|
|
---- TYPES
|
|
int
|
|
---- RESULTS
|
|
====
|
|
---- QUERY
|
|
# Empty partitioned table test
|
|
select field from emptytable
|
|
---- TYPES
|
|
string
|
|
---- RESULTS
|
|
====
|
|
---- QUERY
|
|
# Constant conjunct.
|
|
select t1.id, t2.id
|
|
from functional.alltypestiny t1
|
|
left outer join functional.alltypes t2
|
|
on t1.id = t2.id
|
|
where false
|
|
---- TYPES
|
|
int, int
|
|
---- RESULTS
|
|
====
|
|
---- QUERY
|
|
# Constant conjunct in query block with an aggregation.
|
|
select count(int_col), avg(double_col), count(*)
|
|
from functional.alltypes
|
|
where null
|
|
---- TYPES
|
|
bigint, double, bigint
|
|
---- RESULTS
|
|
0,NULL,0
|
|
====
|
|
---- QUERY
|
|
# Constant conjunct in inline view.
|
|
select e.id, f.id
|
|
from functional.alltypessmall f
|
|
inner join
|
|
(select t1.id
|
|
from functional.alltypestiny t1
|
|
left outer join functional.alltypes t2
|
|
on t1.id = t2.id
|
|
where 1 + 3 > 10) e
|
|
on e.id = f.id
|
|
---- TYPES
|
|
int, int
|
|
---- RESULTS
|
|
====
|
|
---- QUERY
|
|
# Limit 0
|
|
select t1.id, t2.id
|
|
from functional.alltypestiny t1
|
|
left outer join functional.alltypes t2
|
|
on t1.id = t2.id
|
|
limit 0
|
|
---- TYPES
|
|
int, int
|
|
---- RESULTS
|
|
====
|
|
---- QUERY
|
|
# Limit 0 in query block with an aggregation
|
|
select count(int_col), avg(double_col), count(*)
|
|
from functional.alltypes
|
|
limit 0
|
|
---- TYPES
|
|
bigint, double, bigint
|
|
---- RESULTS
|
|
====
|
|
---- QUERY
|
|
# Limit 0 in inline view
|
|
select e.id, f.id
|
|
from functional.alltypessmall f
|
|
inner join
|
|
(select t1.id
|
|
from functional.alltypestiny t1
|
|
left outer join functional.alltypes t2
|
|
on t1.id = t2.id
|
|
limit 0) e
|
|
on e.id = f.id
|
|
---- TYPES
|
|
int, int
|
|
---- RESULTS
|
|
====
|
|
---- QUERY
|
|
# IMPALA-1234: Analytic with constant empty result set failed precondition check in FE
|
|
select MIN(int_col) OVER () FROM alltypes limit 0
|
|
---- RESULTS
|
|
---- TYPES
|
|
INT
|
|
====
|
|
---- QUERY
|
|
# IMPALA-1524: Materialize all tuples produced by an EmptySet node.
|
|
SELECT
|
|
COALESCE(580, MAX(t2.year), 150) AS int_col FROM (
|
|
SELECT
|
|
t1.bool_col,
|
|
COALESCE(LAG(-826, 69) OVER (
|
|
ORDER BY t1.bool_col DESC, COALESCE(t2.int_col, t2.smallint_col, t2.id)), 279, -764) AS int_col,
|
|
COALESCE(t2.int_col, t2.smallint_col, t2.id) AS int_col_2
|
|
FROM functional.alltypestiny t1
|
|
INNER JOIN functional.alltypestiny t2
|
|
ON ((t2.bigint_col) = (t1.id)) AND ((t2.timestamp_col) = (t1.timestamp_col))) t1
|
|
INNER JOIN functional.alltypes t2 ON (t2.year) = (t1.int_col_2)
|
|
WHERE (-339.22) IN (-922.68, -254.84)
|
|
---- RESULTS
|
|
580
|
|
---- TYPES
|
|
INT
|
|
====
|
|
---- QUERY
|
|
# IMPALA-1960: Exprs in the aggregation that reference slots from an inline view when
|
|
# the select stmt has an empty select-project-join portion.
|
|
select sum(T.id), count(T.int_col)
|
|
from
|
|
(select id, int_col, bigint_col from functional.alltypestiny) T
|
|
where false
|
|
---- RESULTS
|
|
NULL,0
|
|
---- TYPES
|
|
BIGINT, BIGINT
|
|
====
|
|
---- QUERY
|
|
# IMPALA-2088: Test empty union operands with analytic functions.
|
|
select lead(-496, 81) over (order by t1.double_col desc, t1.id asc)
|
|
from functional.alltypestiny t1 where 5 = 6
|
|
union
|
|
select 794.67
|
|
from functional.alltypes t1 where 5 = 6
|
|
union all
|
|
select coalesce(10.4, int_col)
|
|
from functional.alltypes where false
|
|
---- RESULTS
|
|
---- TYPES
|
|
DECIMAL
|
|
====
|
|
---- QUERY
|
|
# IMPALA-2406: condition filters out all rows from subquery during planning.
|
|
select *
|
|
from (select 10 as i, 2 as j, '2013' as s) as t
|
|
where t.i < 10;
|
|
---- RESULTS
|
|
---- TYPES
|
|
TINYINT,TINYINT,STRING
|
|
====
|