Files
impala/testdata/workloads/functional-query/queries/QueryTest/hbase-inserts.test
Attila Jeges b5805de3e6 IMPALA-7368: Add initial support for DATE type
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>
2019-04-23 13:33:57 +00:00

236 lines
5.8 KiB
Plaintext

====
---- QUERY
insert into table insertalltypesagg
select id, bigint_col, bool_col, date_string_col, day, double_col, float_col,
int_col, month, smallint_col, string_col, timestamp_col, tinyint_col, year from functional.alltypesagg
---- RESULTS
: 11000
====
---- QUERY
select id, bool_col from insertalltypesagg
WHERE id > 300
ORDER BY id
LIMIT 2
---- RESULTS
301,false
302,true
---- TYPES
INT, BOOLEAN
====
---- QUERY
insert into table insertalltypesagg
select 9999999, bigint_col, false, date_string_col, day, double_col, float_col,
int_col, month, smallint_col, string_col, timestamp_col, tinyint_col, year from functional.alltypesagg
---- RESULTS
: 11000
====
---- QUERY
select id, bool_col from insertalltypesagg
WHERE id = 9999999
ORDER BY id
LIMIT 2
---- RESULTS
9999999,false
---- TYPES
INT, BOOLEAN
====
---- QUERY
# test insert into ... select *
# using limit 1 to reduce execution time
insert into table insertalltypesagg
select * from insertalltypesagg limit 1
---- RESULTS
: 1
====
---- QUERY
# test inserting Hive's default text representation of NULL '\N'
# and make sure a scan returns the string and not NULL
insert into table insertalltypesagg
select 9999999, bigint_col, false, "\\N", day, double_col, float_col,
int_col, month, smallint_col, "\\N", timestamp_col, tinyint_col, year from functional.alltypesagg limit 1
---- RESULTS
: 1
====
---- QUERY
select id, date_string_col, string_col from insertalltypesagg
where id = 9999999
---- RESULTS
9999999,'\\N','\\N'
---- TYPES
INT, STRING, STRING
====
---- QUERY
insert into table insertalltypesaggbinary
select id, bigint_col, bool_col, date_string_col, day, double_col, float_col,
int_col, month, smallint_col, string_col, timestamp_col, tinyint_col, year from functional.alltypesagg
---- RESULTS
: 11000
====
---- QUERY
select count(*) from (
select hb.* from insertalltypesaggbinary hb, functional.alltypesagg a
where hb.id = a.id
and (hb.bigint_col = a.bigint_col or
(hb.bigint_col is null and a.bigint_col is null))
and (hb.bool_col = a.bool_col or
(hb.bool_col is null and a.bool_col is null))
and (hb.date_string_col = a.date_string_col or
(hb.date_string_col is null and a.date_string_col is null))
and (hb.double_col = a.double_col or
(hb.double_col is null and a.double_col is null))
and (hb.float_col = a.float_col or
(hb.float_col is null and a.float_col is null))
and (hb.int_col = a.int_col or
(hb.int_col is null and a.int_col is null))
and (hb.smallint_col = a.smallint_col or
(hb.smallint_col is null and a.smallint_col is null))
and (hb.tinyint_col = a.tinyint_col or
(hb.tinyint_col is null and a.tinyint_col is null))
and (hb.string_col = a.string_col or
(hb.string_col is null and a.string_col is null))
and (hb.timestamp_col = a.timestamp_col or
(hb.timestamp_col is null and a.timestamp_col is null))
) x
---- RESULTS
11000
---- TYPES
BIGINT
====
---- QUERY
select id, bool_col from insertalltypesaggbinary
WHERE id > 300
ORDER BY id
LIMIT 2
---- RESULTS
301,false
302,true
---- TYPES
INT, BOOLEAN
====
---- QUERY
insert into table insertalltypesaggbinary
select 9999999, bigint_col, false, date_string_col, day, double_col, float_col,
int_col, month, smallint_col, string_col, timestamp_col, tinyint_col, year from functional.alltypesagg
---- RESULTS
: 11000
====
---- QUERY
select id, bool_col from insertalltypesaggbinary
WHERE id = 9999999
ORDER BY id
LIMIT 2
---- RESULTS
9999999,false
---- TYPES
INT, BOOLEAN
====
---- QUERY
# test insert into ... select *
# using limit 1 to reduce execution time
insert into table insertalltypesaggbinary
select * from insertalltypesaggbinary limit 1
---- RESULTS
: 1
====
---- QUERY
# test inserting Hive's default text representation of NULL '\N'
# and make sure a scan returns the string and not NULL
insert into table insertalltypesaggbinary
select 9999999, bigint_col, false, "\\N", day, double_col, float_col,
int_col, month, smallint_col, "\\N", timestamp_col, tinyint_col, year from functional.alltypesagg limit 1
---- RESULTS
: 1
====
---- QUERY
select id, date_string_col, string_col from insertalltypesaggbinary
where id = 9999999
---- RESULTS
9999999,'\\N','\\N'
---- TYPES
INT, STRING, STRING
====
---- QUERY
#IMPALA-715 handle large string value
insert into table insertalltypesagg(id, string_col) values(9999999, rpad('a', 50000, 'b'))
---- RESULTS
: 1
====
---- QUERY
select id, length(string_col) from insertalltypesagg
WHERE id = 9999999
---- RESULTS
9999999,50000
---- TYPES
INT, INT
====
---- QUERY
# IMPALA-2133
insert into table insertalltypesagg (id, string_col) values (99999999, 'William\'s'), (999999999, "Other\"s")
---- RESULTS
: 2
====
---- QUERY
select id, string_col from insertalltypesagg where id = 99999999
---- RESULTS
99999999,'William''s'
---- TYPES
INT, STRING
====
---- QUERY
select id, string_col from insertalltypesagg where string_col = 'William\'s'
---- RESULTS
99999999,'William''s'
---- TYPES
INT, STRING
====
---- QUERY
select id, string_col from insertalltypesagg where string_col = "Other\"s"
---- RESULTS
999999999,'Other"s'
---- TYPES
INT, STRING
====
---- QUERY
insert into table insert_date_tbl
select id_col, date_col, date_part
from functional.date_tbl
---- RESULTS
: 22
====
---- QUERY
select id_col, date_col from insert_date_tbl
WHERE id_col > 20
ORDER BY id_col
LIMIT 2
---- RESULTS
21,0001-06-22
22,0001-06-23
---- TYPES
INT, DATE
====
---- QUERY
insert into table insert_date_tbl
select 9999999, date_col, '1521-12-13'
from functional.date_tbl
---- RESULTS
: 22
====
---- QUERY
select id_col, date_part from insert_date_tbl
WHERE id_col = 9999999
ORDER BY id_col
LIMIT 2
---- RESULTS
9999999,1521-12-13
---- TYPES
INT, DATE
====
---- QUERY
# test insert into ... select *
# using limit 1 to reduce execution time
insert into table insert_date_tbl
select * from insert_date_tbl limit 1
---- RESULTS
: 1
====