Files
impala/testdata/workloads/functional-query/queries/QueryTest/hdfs-partitions.test
Attila Jeges f0678b06e6 IMPALA-7369: part 1: Implement TRUNC, DATE_TRUNC, EXTRACT, DATE_PART functions for DATE
These functions are somewhat similar in that each of them takes a DATE
argument and a time unit to work with.

They work identically to the corresponding TIMESTAMP functions. The
only difference is that the DATE functions don't accept time-of-day
units.

TRUNC(DATE d, STRING unit)
Truncates a DATE value to the specified time unit. The 'unit' argument
is case insensitive. This argument string can be one of:
  SYYYY, YYYY, YEAR, SYEAR, YYY, YY, Y: Year.
  Q: Quarter.
  MONTH, MON, MM, RM: Month.
  DDD, DD, J: Day.
  DAY, DY, D: Starting day (Monday) of the week.
  WW: Truncates to the most recent date, no later than 'd', which is
      on the same day of the week as the first day of year.
  W: Truncates to the most recent date, no later than 'd', which is on
     the same day of the week as the first day of month.

The impelementation mirrors Impala's TRUNC(TIMESTAMP ts, STRING unit)
function. Hive and Oracle SQL have a similar function too.
Reference:
http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions201.htm
.

DATE_TRUNC(STRING unit, DATE d)
Truncates a DATE value to the specified precision. The 'unit' argument
is case insensitive. This argument string can be one of: DAY, WEEK,
MONTH, YEAR, DECADE, CENTURY, MILLENNIUM.

The implementation mirrors Impala's DATE_TRUNC(STRING unit,
TIMESTAMP ts) function. Vertica has a similar function too.
Reference:
https://my.vertica.com/docs/8.1.x/HTML/index.htm#Authoring/
    SQLReferenceManual/Functions/Date-Time/DATE_TRUNC.htm
.

EXTRACT(DATE d, STRING unit), EXTRACT(unit FROM DATE d)
Returns one of the numeric date fields from a DATE value. The 'unit'
string can be one of YEAR, QUARTER, MONTH, DAY. This argument value is
case-insensitive.

The implementation mirrors that Impala's EXTRACT(TIMESTAMP ts,
STRING unit). Hive and Oracle SQL have a similar function too.
Reference:
http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions050.htm
.

DATE_PART(STRING unit, DATE date)
Similar to EXTRACT(), with the argument order reversed. Supports the
same date units as EXTRACT().

The implementation mirrors Impala's DATE_PART(STRING unit,
TIMESTAMP ts) function.

Change-Id: I843358a45eb5faa2c134994600546fc1d0a797c8
Reviewed-on: http://gerrit.cloudera.org:8080/13363
Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
2019-06-05 14:23:23 +00:00

183 lines
3.0 KiB
Plaintext

====
---- QUERY
select year, count(*) from alltypes group by 1 order by 1 limit 10
---- RESULTS
2009,3650
2010,3650
---- TYPES
INT, BIGINT
====
---- QUERY
select month, count(*) from alltypes group by 1 order by 1 limit 100
---- RESULTS
1,620
2,560
3,620
4,600
5,620
6,600
7,620
8,620
9,600
10,620
11,600
12,620
---- TYPES
INT, BIGINT
====
---- QUERY
select year, month, count(*) from alltypes group by 1, 2 order by 1, 2 limit 100
---- RESULTS
2009,1,310
2009,2,280
2009,3,310
2009,4,300
2009,5,310
2009,6,300
2009,7,310
2009,8,310
2009,9,300
2009,10,310
2009,11,300
2009,12,310
2010,1,310
2010,2,280
2010,3,310
2010,4,300
2010,5,310
2010,6,300
2010,7,310
2010,8,310
2010,9,300
2010,10,310
2010,11,300
2010,12,310
---- TYPES
INT, INT, BIGINT
====
---- QUERY
select count(*) from alltypes where year=2009
---- RESULTS
3650
---- TYPES
BIGINT
====
---- QUERY
# still works if 'year' needs a cast
select count(*) from alltypes where year = 2009.0
---- RESULTS
3650
---- TYPES
BIGINT
====
---- QUERY
# finds bindings for partition keys regardless of order of operands
select count(*) from alltypes where 2009 = year
---- RESULTS
3650
---- TYPES
BIGINT
====
---- QUERY
select count(*) from alltypes where 2009.0 = year
---- RESULTS
3650
---- TYPES
BIGINT
====
---- QUERY
select count(*) from alltypes where month=1
---- RESULTS
620
---- TYPES
BIGINT
====
---- QUERY
select count(*) from alltypes where year=2009 and month=1
---- RESULTS
310
---- TYPES
BIGINT
====
---- QUERY
select count(*) from alltypes where year=2009 and month > 6
---- RESULTS
1840
---- TYPES
BIGINT
====
---- QUERY
select count(*) from alltypes where year=2009 and month < 6
---- RESULTS
1510
---- TYPES
BIGINT
====
---- QUERY
select count(*) from alltypes where year<=2009 and month < 6
---- RESULTS
1510
---- TYPES
BIGINT
====
---- QUERY
select count(*) from alltypes where month < 9 and month > 6
---- RESULTS
1240
---- TYPES
BIGINT
====
---- QUERY
select count(*) from alltypes where year < 2010 and year < 2009 and month > 6
---- RESULTS
0
---- TYPES
BIGINT
====
---- QUERY
select count(*) from alltypes where year < 2010 and month > 6 and month > 12
---- RESULTS
0
---- TYPES
BIGINT
====
---- QUERY
# Test multi files partitioned table (hdfs)
select count(*) from alltypesaggmultifiles where day is not null
---- RESULTS
10000
---- TYPES
BIGINT
====
---- QUERY
# Test partition pruning when a binary predicate contains a NullLiteral
select count(*) from alltypestiny where year != null or year = null
---- RESULTS
0
---- TYPES
BIGINT
====
---- QUERY
# Test partition pruning when an IN predicate contains a NullLiteral
select count(*) from alltypesagg where day in (1, null)
---- RESULTS
1000
---- TYPES
BIGINT
====
---- QUERY
# Test partition pruning when a NOT IN predicate contains a NullLiteral
select count(*) from alltypesagg where day not in (1, 2, null)
---- RESULTS
0
---- TYPES
BIGINT
====
---- QUERY
# IMPALA-2514: DCHECK on ExprContext::Close()
select int_col from functional.alltypes
where year=date_part('yyyyMMMdd hh:mm:ss', current_timestamp());
---- CATCH
InternalException: Invalid Date Part Field: yyyyMMMdd hh:mm:ss
====