mirror of
https://github.com/apache/impala.git
synced 2026-01-23 21:00:25 -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>
111 lines
4.3 KiB
C++
111 lines
4.3 KiB
C++
// Licensed to the Apache Software Foundation (ASF) under one
|
|
// or more contributor license agreements. See the NOTICE file
|
|
// distributed with this work for additional information
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
// to you under the Apache License, Version 2.0 (the
|
|
// "License"); you may not use this file except in compliance
|
|
// with the License. You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing,
|
|
// software distributed under the License is distributed on an
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
// KIND, either express or implied. See the License for the
|
|
// specific language governing permissions and limitations
|
|
// under the License.
|
|
|
|
|
|
#ifndef IMPALA_EXPRS_UTILITY_FUNCTIONS_H
|
|
#define IMPALA_EXPRS_UTILITY_FUNCTIONS_H
|
|
|
|
#include "udf/udf.h"
|
|
|
|
namespace impala {
|
|
|
|
using impala_udf::FunctionContext;
|
|
using impala_udf::AnyVal;
|
|
using impala_udf::BooleanVal;
|
|
using impala_udf::TinyIntVal;
|
|
using impala_udf::SmallIntVal;
|
|
using impala_udf::IntVal;
|
|
using impala_udf::BigIntVal;
|
|
using impala_udf::FloatVal;
|
|
using impala_udf::DoubleVal;
|
|
using impala_udf::TimestampVal;
|
|
using impala_udf::StringVal;
|
|
using impala_udf::DecimalVal;
|
|
using impala_udf::DateVal;
|
|
|
|
class Expr;
|
|
class OpcodeRegistry;
|
|
class TupleRow;
|
|
|
|
class UtilityFunctions {
|
|
public:
|
|
/// Implementations of the FnvHash function. Returns the Fowler-Noll-Vo hash of the
|
|
/// input as an int64_t.
|
|
template <typename T> static BigIntVal FnvHash(FunctionContext* ctx,
|
|
const T& input_val);
|
|
static BigIntVal FnvHashString(FunctionContext* ctx, const StringVal& input_val);
|
|
static BigIntVal FnvHashTimestamp(FunctionContext* ctx, const TimestampVal& input_val);
|
|
static BigIntVal FnvHashDecimal(FunctionContext* ctx, const DecimalVal& input_val);
|
|
|
|
/// Implementations of the MurmurHash function. Returns the Murmur hash of the
|
|
/// input as an int64_t.
|
|
template <typename T> static BigIntVal MurmurHash(FunctionContext* ctx,
|
|
const T& input_val);
|
|
static BigIntVal MurmurHashString(FunctionContext* ctx, const StringVal& input_val);
|
|
static BigIntVal MurmurHashTimestamp(FunctionContext* ctx, const TimestampVal& input_val);
|
|
static BigIntVal MurmurHashDecimal(FunctionContext* ctx, const DecimalVal& input_val);
|
|
|
|
/// Implementation of the user() function. Returns the username of the user who executed
|
|
/// this function.
|
|
static StringVal User(FunctionContext* ctx);
|
|
|
|
/// Implementation of the effective_user() builtin. Returns the username of the
|
|
/// effective user for authorization purposes.
|
|
static StringVal EffectiveUser(FunctionContext* ctx);
|
|
|
|
/// Implementation of the version() function. Returns the version string.
|
|
static StringVal Version(FunctionContext* ctx);
|
|
|
|
/// Implementation of the pid() function. Returns the pid of the impalad that initiated
|
|
/// this query.
|
|
static IntVal Pid(FunctionContext* ctx);
|
|
|
|
/// Testing function that sleeps for the specified number of milliseconds. Returns true.
|
|
static BooleanVal Sleep(FunctionContext* ctx, const IntVal& milliseconds);
|
|
|
|
/// Implementation of the current_database() function. Returns the current default
|
|
/// database from the parent session of this query.
|
|
static StringVal CurrentDatabase(FunctionContext* ctx);
|
|
|
|
/// Implementation of the current_session() function. Returns the ID of the
|
|
/// parent session of this query.
|
|
static StringVal CurrentSession(FunctionContext* ctx);
|
|
|
|
/// Implementation of the Uuid() function.
|
|
static StringVal Uuid(FunctionContext* ctx);
|
|
static void UuidPrepare(FunctionContext* ctx,
|
|
FunctionContext::FunctionStateScope scope);
|
|
static void UuidClose(FunctionContext* ctx,
|
|
FunctionContext::FunctionStateScope scope);
|
|
|
|
/// Implementation of the coordinator() function.
|
|
/// Returns the name of the host where the coordinator is running.
|
|
static StringVal Coordinator(FunctionContext* ctx);
|
|
|
|
/// Implementation of the typeOf() function. Returns the type of the input
|
|
/// expression. input_val is not used and it is kept here in order to let
|
|
/// the compiler generate the corresponding fully-qualified function name.
|
|
template <typename T> static StringVal TypeOf(FunctionContext* ctx, const T& input_val);
|
|
|
|
private:
|
|
static StringVal GenUuid(FunctionContext* ctx);
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|