mirror of
https://github.com/apache/impala.git
synced 2026-01-19 00:00:54 -05:00
DATE values describe a particular year/month/day in the form
yyyy-MM-dd. For example: DATE '2019-02-15'. DATE values do not have a
time of day component. The range of values supported for the DATE type
is 0000-01-01 to 9999-12-31.
This initial DATE type support covers TEXT and HBASE fileformats only.
'DateValue' is used as the internal type to represent DATE values.
The changes are as follows:
- Support for DATE literal syntax.
- Explicit casting between DATE and other types (note that invalid
casts will fail with an error just like invalid DECIMAL_V2 casts,
while failed casts to other types do no lead to warning or error):
- from STRING to DATE. The string value must be formatted as
yyyy-MM-dd HH:mm:ss.SSSSSSSSS. The date component is mandatory,
the time component is optional. If the time component is
present, it will be truncated silently.
- from DATE to STRING. The resulting string value is formatted as
yyyy-MM-dd.
- from TIMESTAMP to DATE. The source timestamp's time of day
component is ignored.
- from DATE to TIMESTAMP. The target timestamp's time of day
component is set to 00:00:00.
- Implicit casting between DATE and other types:
- from STRING to DATE if the source string value is used in a
context where a DATE value is expected.
- from DATE to TIMESTAMP if the source date value is used in a
context where a TIMESTAMP value is expected.
- Since STRING -> DATE, STRING -> TIMESTAMP and DATE -> TIMESTAMP
implicit conversions are now all possible, the existing function
overload resolution logic is not adequate anymore.
For example, it resolves the
if(false, '2011-01-01', DATE '1499-02-02') function call to the
if(BOOLEAN, TIMESTAMP, TIMESTAMP) version of the overloaded
function, instead of the if(BOOLEAN, DATE, DATE) version.
This is clearly wrong, so the function overload resolution logic had
to be changed to resolve function calls to the best-fit overloaded
function definition if there are multiple applicable candidates.
An overloaded function definition is an applicable candidate for a
function call if each actual parameter in the function call either
matches the corresponding formal parameter's type (without casting)
or is implicitly castable to that type.
When looking for the best-fit applicable candidate, a parameter
match score (i.e. the number of actual parameters in the function
call that match their corresponding formal parameter's type without
casting) is calculated and the applicable candidate with the highest
parameter match score is chosen.
There's one more issue that the new resolution logic has to address:
if two applicable candidates have the same parameter match score and
the only difference between the two is that the first one requires a
STRING -> TIMESTAMP implicit cast for some of its parameters while
the second one requires a STRING -> DATE implicit cast for the same
parameters then the first candidate has to be chosen not to break
backward compatibility.
E.g: year('2019-02-15') function call must resolve to
year(TIMESTAMP) instead of year(DATE). Note, that year(DATE) is not
implemented yet, so this is not an issue at the moment but it will
be in the future.
When the resolution algorithm considers overloaded function
definitions, first it orders them lexicographically by the types in
their parameter lists. To ensure the backward compatible behavior
Primitivetype.DATE enum value has to come after
PrimitiveType.TIMESTAMP.
- Codegen infrastructure changes for expression evaluation.
- 'IS [NOT] NULL' and '[NOT] IN' predicates.
- Common comparison operators (including the 'BETWEEN' operator).
- Infrastructure changes for built-in functions.
- Some built-in functions: conditional, aggregate, analytical and
math functions.
- C++ UDF/UDA support.
- Support partitioning and grouping by DATE.
- Beeswax, HiveServer2 support.
These items are tightly coupled and it makes sense to implement them
in one change-set.
Testing:
- A new partitioned TEXT table 'functional.date_tbl' (and the
corresponding HBASE table 'functional_hbase.date_tbl') was
introduced for DATE-related tests.
- BE and FE tests were extended to cover DATE type.
- E2E tests:
- since DATE type is supported for TEXT and HBASE fileformats
only, most DATE tests were implemented separately in
tests/query_test/test_date_queries.py.
Note, that this change-set is not a complete DATE type implementation,
but it lays the foundation for future work:
- Add date support to the random query generator.
- Implement a complete set of built-in functions.
- Add Parquet support.
- Add Kudu support.
- Optionally support Avro and ORC.
For further details, see IMPALA-6169.
Change-Id: Iea8155ef09557e0afa2f8b2d0b2dc9d0896dc30f
Reviewed-on: http://gerrit.cloudera.org:8080/12481
Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
181 lines
4.3 KiB
Plaintext
181 lines
4.3 KiB
Plaintext
====
|
|
---- QUERY
|
|
select hll(int_col) from functional.alltypestiny;
|
|
---- RESULTS
|
|
'2'
|
|
---- TYPES
|
|
string
|
|
====
|
|
---- QUERY
|
|
select test_count(int_col) from functional.alltypestiny;
|
|
---- RESULTS
|
|
8
|
|
---- TYPES
|
|
bigint
|
|
====
|
|
---- QUERY
|
|
select test_count(int_col) from functional.alltypesagg;
|
|
---- RESULTS
|
|
10980
|
|
---- TYPES
|
|
bigint
|
|
====
|
|
---- QUERY
|
|
select sum_small_decimal(c3) from functional.decimal_tiny;
|
|
---- RESULTS
|
|
45.00
|
|
---- TYPES
|
|
decimal
|
|
====
|
|
---- QUERY
|
|
select trunc_sum(double_col),sum(double_col) from functional_parquet.alltypes where id < 5555;
|
|
---- RESULTS
|
|
252348,252348.5
|
|
---- TYPES
|
|
bigint,double
|
|
====
|
|
---- QUERY
|
|
select arg_is_const(int_col, 1) from functional_parquet.alltypes;
|
|
---- RESULTS
|
|
true
|
|
---- TYPES
|
|
boolean
|
|
====
|
|
---- QUERY
|
|
# Test with even number of input rows.
|
|
select toggle_null(id), count(*)
|
|
from functional_parquet.alltypesagg
|
|
---- RESULTS
|
|
NULL,11000
|
|
---- TYPES
|
|
int,bigint
|
|
====
|
|
---- QUERY
|
|
# Test with odd number of input rows.
|
|
select toggle_null(id), count(*)
|
|
from functional_parquet.alltypesagg
|
|
where id <= 9998
|
|
---- RESULTS
|
|
1,10999
|
|
---- TYPES
|
|
int,bigint
|
|
====
|
|
---- QUERY
|
|
# Test that input NULLs are passed to aggregate functions ok.
|
|
select count_nulls(tinyint_col), count(*)
|
|
from functional.alltypesagg
|
|
---- RESULTS
|
|
2000,11000
|
|
---- TYPES
|
|
bigint,bigint
|
|
====
|
|
---- QUERY
|
|
# Test that all types are exposed via the FunctionContext correctly.
|
|
# This relies on asserts in the UDA funciton
|
|
select agg_intermediate(int_col), count(*)
|
|
from functional.alltypesagg
|
|
---- RESULTS
|
|
NULL,11000
|
|
---- TYPES
|
|
bigint,bigint
|
|
====
|
|
---- QUERY
|
|
# Test that all types are exposed via the FunctionContext correctly.
|
|
# This relies on asserts in the UDA funciton
|
|
select agg_decimal_intermediate(cast(c3 as decimal(2,1)), 2), count(*)
|
|
from functional.decimal_tiny
|
|
---- RESULTS
|
|
NULL,100
|
|
---- TYPES
|
|
decimal,bigint
|
|
====
|
|
---- QUERY
|
|
# Test that all types are exposed via the FunctionContext correctly.
|
|
# This relies on asserts in the UDA funciton
|
|
select agg_date_intermediate(date_col, 2), count(*)
|
|
from functional.date_tbl
|
|
---- RESULTS
|
|
NULL,22
|
|
---- TYPES
|
|
date,bigint
|
|
====
|
|
---- QUERY
|
|
# Test that all types are exposed via the FunctionContext correctly.
|
|
# This includes distinct aggregate expression to test IMPALA-5251.
|
|
# It also relies on asserts in the UDA funciton.
|
|
select
|
|
agg_string_intermediate(cast(c1 as decimal(20,10)), 1000, "foobar"),
|
|
agg_decimal_intermediate(cast(c3 as decimal(2,1)), 2),
|
|
agg_date_intermediate(date_col, 2),
|
|
agg_intermediate(int_col),
|
|
avg(c2),
|
|
min(c3-c1),
|
|
max(c1+c3),
|
|
count(distinct int_col),
|
|
sum(distinct int_col),
|
|
max(date_col)
|
|
from
|
|
functional.alltypesagg,
|
|
functional.decimal_tiny,
|
|
functional.date_tbl
|
|
---- RESULTS
|
|
100,NULL,NULL,NULL,160.499890,-10.0989,11.8989,999,499500,9999-12-31
|
|
---- TYPES
|
|
decimal,decimal,date,bigint,decimal,decimal,decimal,bigint,bigint,date
|
|
====
|
|
---- QUERY
|
|
# Test that all types are exposed via the FunctionContext correctly.
|
|
# This includes distinct aggregate expression to test IMPALA-5251.
|
|
# It also relies on asserts in the UDA funciton.
|
|
select
|
|
agg_string_intermediate(cast(c1 as decimal(20,10)), 1000, "foobar"),
|
|
agg_decimal_intermediate(cast(c3 as decimal(2,1)), 2),
|
|
agg_date_intermediate(date_col, 2),
|
|
agg_intermediate(int_col),
|
|
ndv(c2),
|
|
sum(distinct c1)/count(distinct c1),
|
|
ndv(date_col)
|
|
from
|
|
functional.alltypesagg,
|
|
functional.decimal_tiny,
|
|
functional.date_tbl
|
|
group by
|
|
year,month,day
|
|
---- RESULTS
|
|
100,NULL,NULL,NULL,99,5.499450,16
|
|
100,NULL,NULL,NULL,99,5.499450,16
|
|
100,NULL,NULL,NULL,99,5.499450,16
|
|
100,NULL,NULL,NULL,99,5.499450,16
|
|
100,NULL,NULL,NULL,99,5.499450,16
|
|
100,NULL,NULL,NULL,99,5.499450,16
|
|
100,NULL,NULL,NULL,99,5.499450,16
|
|
100,NULL,NULL,NULL,99,5.499450,16
|
|
100,NULL,NULL,NULL,99,5.499450,16
|
|
100,NULL,NULL,NULL,99,5.499450,16
|
|
100,NULL,NULL,NULL,99,5.499450,16
|
|
---- TYPES
|
|
decimal,decimal,date,bigint,bigint,decimal,bigint
|
|
====
|
|
---- QUERY
|
|
# Test that char intermediate works as expected. The function char_intermediate_sum()
|
|
# computes the sum with an intermediate int.
|
|
select year, month, day, char_intermediate_sum(int_col), sum(int_col)
|
|
from functional.alltypesagg
|
|
group by year, month, day
|
|
order by year, month, day
|
|
---- RESULTS
|
|
2010,1,1,499500,499500
|
|
2010,1,2,499500,499500
|
|
2010,1,3,499500,499500
|
|
2010,1,4,499500,499500
|
|
2010,1,5,499500,499500
|
|
2010,1,6,499500,499500
|
|
2010,1,7,499500,499500
|
|
2010,1,8,499500,499500
|
|
2010,1,9,499500,499500
|
|
2010,1,10,499500,499500
|
|
2010,1,NULL,495000,495000
|
|
---- TYPES
|
|
int,int,int,int,bigint
|
|
====
|