mirror of
https://github.com/apache/impala.git
synced 2026-02-02 06:00:36 -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>
121 lines
4.2 KiB
Plaintext
121 lines
4.2 KiB
Plaintext
# Test implicit and explicit casts. Binary predicates containing an explicit cast
|
|
# cannot be offered to the data source.
|
|
select * from functional.alltypes_datasource
|
|
where tinyint_col < 256 and
|
|
float_col != 0 and
|
|
cast(int_col as bigint) < 10
|
|
---- PLAN
|
|
PLAN-ROOT SINK
|
|
|
|
|
00:SCAN DATA SOURCE [functional.alltypes_datasource]
|
|
data source predicates: tinyint_col < 256
|
|
predicates: float_col != 0, CAST(int_col AS BIGINT) < 10
|
|
row-size=116B cardinality=500
|
|
====
|
|
# The first four predicates are in a form that can be offered to the data source
|
|
# and the first and third will be accepted (it accepts every other conjunct).
|
|
# The second and fourth will be evaluated by Impala. The negated predicates,
|
|
# i.e. NOT <PREDICATE>, are not in a form able to be offered to the data source,
|
|
# so they will always be evaluated by Impala.
|
|
select * from functional.alltypes_datasource
|
|
where 10 > int_col and
|
|
5 > double_col and
|
|
string_col != "Foo" and
|
|
string_col != "Bar" and
|
|
not true = bool_col and
|
|
not 5.0 = double_col
|
|
---- PLAN
|
|
PLAN-ROOT SINK
|
|
|
|
|
00:SCAN DATA SOURCE [functional.alltypes_datasource]
|
|
data source predicates: int_col < 10, string_col != 'Foo'
|
|
predicates: double_col < 5, NOT bool_col = TRUE, NOT double_col = 5.0, string_col != 'Bar'
|
|
row-size=116B cardinality=500
|
|
====
|
|
# The 3rd predicate is not in a form that can be offered to the data source so
|
|
# the 4th will be offered and accepted instead.
|
|
select * from functional.alltypes_datasource
|
|
where int_col < 10 and
|
|
double_col > 5 and
|
|
string_col in ("Foo", "Bar") and
|
|
bool_col != false
|
|
---- PLAN
|
|
PLAN-ROOT SINK
|
|
|
|
|
00:SCAN DATA SOURCE [functional.alltypes_datasource]
|
|
data source predicates: int_col < 10, bool_col != FALSE
|
|
predicates: double_col > 5, string_col IN ('Foo', 'Bar')
|
|
row-size=116B cardinality=500
|
|
====
|
|
# Tests that all predicates from the On-clause are applied (IMPALA-805)
|
|
# and that slot equivalences are enforced at lowest possible plan node
|
|
# for tables produced by a data source.
|
|
select 1 from functional.alltypes_datasource a
|
|
inner join functional.alltypes_datasource b
|
|
# equivalence class
|
|
on a.id = b.id and a.id = b.int_col and a.id = b.bigint_col
|
|
and a.tinyint_col = b.id and a.smallint_col = b.id
|
|
and a.int_col = b.id and a.bigint_col = b.id
|
|
# redundant predicates to test minimal spanning tree of equivalent slots
|
|
where a.tinyint_col = a.smallint_col and a.int_col = a.bigint_col
|
|
---- PLAN
|
|
PLAN-ROOT SINK
|
|
|
|
|
02:HASH JOIN [INNER JOIN]
|
|
| hash predicates: a.id = b.id
|
|
| row-size=35B cardinality=500
|
|
|
|
|
|--01:SCAN DATA SOURCE [functional.alltypes_datasource b]
|
|
|--predicates: b.id = b.int_col, b.id = b.bigint_col
|
|
| row-size=0B cardinality=500
|
|
|
|
|
00:SCAN DATA SOURCE [functional.alltypes_datasource a]
|
|
predicates: a.id = a.int_col, a.id = a.tinyint_col, a.int_col = a.bigint_col, a.tinyint_col = a.smallint_col
|
|
row-size=0B cardinality=500
|
|
====
|
|
# Tests that <=>, IS DISTINCT FROM, and IS NOT DISTINCT FROM all can be offered to the
|
|
# data source.
|
|
select * from functional.alltypes_datasource
|
|
where id <=> 1
|
|
and bool_col <=> true
|
|
and tinyint_col IS DISTINCT FROM 2
|
|
and smallint_col IS DISTINCT FROM 3
|
|
and int_col is not distinct from 4
|
|
and bigint_col is not distinct from 5
|
|
---- PLAN
|
|
PLAN-ROOT SINK
|
|
|
|
|
00:SCAN DATA SOURCE [functional.alltypes_datasource]
|
|
data source predicates: id IS NOT DISTINCT FROM 1, tinyint_col IS DISTINCT FROM 2, int_col IS NOT DISTINCT FROM 4
|
|
predicates: bigint_col IS NOT DISTINCT FROM 5, bool_col IS NOT DISTINCT FROM TRUE, smallint_col IS DISTINCT FROM 3
|
|
row-size=116B cardinality=500
|
|
====
|
|
# EmptySet datasource
|
|
select * from functional.alltypes_datasource
|
|
where id <=> 1 and id = 2
|
|
and bool_col <=> true
|
|
and tinyint_col IS DISTINCT FROM 2
|
|
and smallint_col IS DISTINCT FROM 3
|
|
and int_col is not distinct from 4
|
|
and bigint_col is not distinct from 5
|
|
---- PLAN
|
|
PLAN-ROOT SINK
|
|
|
|
|
00:EMPTYSET
|
|
====
|
|
# IMPALA-5602: If a query contains predicates that are all pushed to the datasource and
|
|
# there is a limit, then the query should not incorrectly run with 'small query'
|
|
# optimization.
|
|
select * from functional.alltypes_datasource where id = 1 limit 15
|
|
---- DISTRIBUTEDPLAN
|
|
PLAN-ROOT SINK
|
|
|
|
|
01:EXCHANGE [UNPARTITIONED]
|
|
| limit: 15
|
|
|
|
|
00:SCAN DATA SOURCE [functional.alltypes_datasource]
|
|
data source predicates: id = 1
|
|
limit: 15
|
|
row-size=116B cardinality=15
|
|
====
|