Files
impala/testdata/workloads/functional-query/queries/QueryTest/misc.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

159 lines
2.8 KiB
Plaintext

====
---- QUERY
# Test to select from table with additional columns at the end that are not in the
# schema and with missing columns
select * from tblwithraggedcolumns
---- RESULTS
'hello',1
'\\r\\r\\n',NULL
'',NULL
'foo',2
'a',3
'',NULL
'b',4
'c',NULL
'd',NULL
'ColumnWithCarriageReturn',123
'at16bytes',NULL
'NoDelimiter',0
---- TYPES
string, int
====
---- QUERY
select int_col from tblwithraggedcolumns
---- RESULTS
0
1
123
2
3
4
NULL
NULL
NULL
NULL
NULL
NULL
---- TYPES
int
====
---- QUERY
select str_col from tblwithraggedcolumns
---- RESULTS
'hello'
'\\r\\r\\n'
''
'foo'
'a'
''
'b'
'c'
'd'
'ColumnWithCarriageReturn'
'at16bytes'
'NoDelimiter'
---- TYPES
string
====
---- QUERY
# Quoting test
SELECT `table_alias`.`int_col` AS `default_int_col`
FROM `functional`.`alltypes` `table_alias`
GROUP BY `default_int_col`
LIMIT 10
---- RESULTS
0
7
3
9
4
6
1
5
2
8
---- TYPES
int
====
---- QUERY
# Test string-literal escape sequences
SELECT ASCII("\0"), ASCII("\\"), ASCII("\b"), ASCII("\n"), ASCII("\r"), ASCII("\t"), ASCII("\Z")
---- RESULTS
0,92,8,10,13,9,26
---- TYPES
int, int, int, int, int, int, int
====
---- QUERY
# Test escaping non-escape chars. We expect the escape to be simply removed.
SELECT ASCII("\a"), ASCII("\X"), ASCII("\z"), ASCII("\?"), ASCII("\*")
---- RESULTS
97,88,122,63,42
---- TYPES
int, int, int, int, int
====
---- QUERY
# Test escaping '%' and '_' which handled specially.
# We expect '\\%' and '\%' to result in '\%' (similarly for '_')
SELECT "\%", "\\%", "\_", "\\_"
---- RESULTS
'\\%','\\%','\\_','\\_'
---- TYPES
string, string, string, string
====
---- QUERY
# Test query filed in IMPALA-65
SELECT "quote \"", 'quote \''
---- RESULTS
'quote "','quote '''
---- TYPES
string, string
====
---- QUERY
# Select from table that contains unsupported primitive types
SELECT int_col, str_col, bigint_col from functional.unsupported_types
---- RESULTS
0,'aaaa',0
1,'bbbb',10
2,'cccc',20
NULL,'NULL',NULL
4,'eeee',40
---- TYPES
int, string, bigint
====
---- QUERY
# where clause is a SlotRef
SELECT count(*) from functional.alltypes where bool_col
---- RESULTS
3650
---- TYPES
bigint
====
---- QUERY
# having clause is a SlotRef
SELECT count(*) from functional.alltypes group by bool_col having bool_col
---- RESULTS
3650
---- TYPES
bigint
====
---- QUERY
# IMPALA-3812: Verfiy that the correct error message is shown when the star expansion adds
# the BINARY unsupported type to the select list.
select * from functional.unsupported_types
---- CATCH
Unsupported type 'BINARY' in 'functional.unsupported_types.bin_col'.
====
---- QUERY
# IMPALA-3812: Verfiy that DATE type is displayed correctly in the describe table.
describe functional.unsupported_types
---- RESULTS
'int_col','int',''
'dec_col','decimal(10,0)',''
'date_col','date',''
'str_col','string',''
'bin_col','binary',''
'bigint_col','bigint',''
---- TYPES
STRING, STRING, STRING
====