Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
|
#include <timestamp-value.h>
Public Member Functions | |
TimestampValue () | |
TimestampValue (const boost::gregorian::date &d, const boost::posix_time::time_duration &t) | |
TimestampValue (const boost::posix_time::ptime &t) | |
TimestampValue (const TimestampValue &tv) | |
TimestampValue (const char *str, int len) | |
TimestampValue (const char *str, int len, const DateTimeFormatContext &dt_ctx) | |
template<typename Number > | |
TimestampValue (Number unix_time) | |
TimestampValue (int64_t unix_time, int64_t nanos) | |
TimestampValue (double unix_time) | |
void | ToTimestampVal (impala_udf::TimestampVal *tv) const |
void | ToPtime (boost::posix_time::ptime *ptp) const |
bool | HasDate () const |
bool | HasTime () const |
bool | HasDateOrTime () const |
bool | HasDateAndTime () const |
std::string | DebugString () const |
int | Format (const DateTimeFormatContext &dt_ctx, int len, char *buff) |
time_t | ToUnixTime () const |
double | ToSubsecondUnixTime () const |
void | UtcToLocal () |
void | set_date (const boost::gregorian::date d) |
void | set_time (const boost::posix_time::time_duration t) |
const boost::gregorian::date & | date () const |
const boost::posix_time::time_duration & | time () const |
TimestampValue & | operator= (const boost::posix_time::ptime &ptime) |
bool | operator== (const TimestampValue &other) const |
bool | operator!= (const TimestampValue &other) const |
bool | operator< (const TimestampValue &other) const |
bool | operator<= (const TimestampValue &other) const |
bool | operator> (const TimestampValue &other) const |
bool | operator>= (const TimestampValue &other) const |
uint32_t | Hash (int seed=0) const |
Static Public Member Functions | |
static TimestampValue | LocalTime () |
static TimestampValue | FromTimestampVal (const impala_udf::TimestampVal &udf_value) |
static size_t | Size () |
Static Public Attributes | |
static const char * | LLVM_CLASS_NAME = "class.impala::TimestampValue" |
Private Member Functions | |
boost::posix_time::ptime | UnixTimeToPtime (time_t unix_time) const |
Private Attributes | |
boost::posix_time::time_duration | time_ |
8 bytes - stores the nanoseconds within the current day More... | |
boost::gregorian::date | date_ |
4 -bytes - stores the date as a day More... | |
Static Private Attributes | |
static const double | ONE_BILLIONTH = 0.000000001 |
Friends | |
class | UnusedClass |
Represents either a (1) date and time, (2) a date with an undefined time, or (3) a time with an undefined date. In all cases, times have up to nanosecond resolution and the minimum and maximum dates are 1400-01-01 and 10000-12-31. This type is similar to Postgresql TIMESTAMP WITHOUT TIME ZONE datatype and MySQL's DATETIME datatype. Note that because TIMESTAMP does not contain time zone information, the time zone must be inferred by the context when needed. For example, suppose the current date and time is Jan 15 2015 5:37:56 PM PST: SELECT NOW(); – Returns '2015-01-15 17:37:56' - implicit time zone of NOW() return value is PST SELECT TO_UTC_TIMESTAMP(NOW(), "PST"); – Returns '2015-01-16 01:54:21' - implicit time zone is UTC, input time zone specified by second parameter. Hive describes this data type as "Timestamps are interpreted to be timezoneless and stored as an offset from the UNIX epoch." but storing a value as an offset from Unix epoch, which is defined as being in UTC, is impossible unless the time zone for the value is known. If all files stored values relative to the epoch, then there would be no reason to interpret values as timezoneless. TODO: Document what situation leads to #2 at the top. Cases #1 and 3 can be created with literals. A literal "2000-01-01" results in a value with a "00:00:00" time component. It may not be possible to actually create case #2 though the code implies it is possible. For collect timings, prefer the functions in util/time.h. If this class is used for timings, the local time should never be used since it is affected by daylight savings. Also keep in mind that the time component rolls over at midnight so the date should always be checked when determining a duration.
Definition at line 65 of file timestamp-value.h.
|
inline |
Definition at line 67 of file timestamp-value.h.
Referenced by LocalTime().
|
inline |
Definition at line 69 of file timestamp-value.h.
|
inline |
Definition at line 73 of file timestamp-value.h.
|
inline |
Definition at line 76 of file timestamp-value.h.
impala::TimestampValue::TimestampValue | ( | const char * | str, |
int | len | ||
) |
Definition at line 35 of file timestamp-value.cc.
References date_, impala::TimestampParser::Parse(), and time_.
impala::TimestampValue::TimestampValue | ( | const char * | str, |
int | len, | ||
const DateTimeFormatContext & | dt_ctx | ||
) |
Definition at line 39 of file timestamp-value.cc.
References date_, impala::TimestampParser::Parse(), and time_.
|
inlineexplicit |
Unix time (seconds since 1970-01-01 UTC by definition) constructors. Conversion to local time will be done if FLAGS_use_local_tz_for_unix_timestamp_conversions is true.
Definition at line 84 of file timestamp-value.h.
References UnixTimeToPtime().
|
inline |
Definition at line 88 of file timestamp-value.h.
References UnixTimeToPtime().
|
inlineexplicit |
Definition at line 94 of file timestamp-value.h.
References ONE_BILLIONTH, and UnixTimeToPtime().
|
inline |
Definition at line 189 of file timestamp-value.h.
References date_.
Referenced by impala::TimestampFunctions::DateAddSub(), impala::TimestampFunctions::DateDiff(), impala::TimestampFunctions::DayOfMonth(), impala::TimestampFunctions::DayOfWeek(), impala::TimestampFunctions::DayOfYear(), impala::TimezoneDatabase::FindTimezone(), impala::TimestampFunctions::Month(), impala::KeyNormalizer::NormalizeTimestamp(), impala::TEST(), impala::TimestampFunctions::TimeAddSub(), impala::TimestampFunctions::ToDate(), impala::TimestampFunctions::ToUtc(), impala::UdfBuiltins::Trunc(), TruncW(), TruncWW(), impala::ValidateTimestamp(), impala::TimestampFunctions::WeekOfYear(), and impala::TimestampFunctions::Year().
|
inline |
Definition at line 137 of file timestamp-value.h.
References date_, HasDate(), HasTime(), and time_.
Referenced by impala::ImpalaServer::ExpireSessions(), impala::ImpalaServer::GetSessionState(), impala::ImpalaServer::LogAuditRecord(), impala::operator<<(), impala::PrintSample(), impala::ImpalaServer::QueryStateToJson(), and impala::ImpalaServer::SessionsUrlCallback().
int impala::TimestampValue::Format | ( | const DateTimeFormatContext & | dt_ctx, |
int | len, | ||
char * | buff | ||
) |
Formats the timestamp using the given date/time context and places the result in the string buffer. The size of the buffer should be at least dt_ctx.fmt_out_len + 1. A string terminator will be appended to the string. dt_ctx – the date/time context containing the format to use len – the length of the buffer buff – the buffer that will hold the result Returns the number of characters copied in to the buffer (minus the terminator)
Definition at line 44 of file timestamp-value.cc.
References date_, impala::TimestampParser::Format(), and time_.
Referenced by impala::TimestampFunctions::FromUnix(), and impala::TEST().
|
inlinestatic |
Returns a TimestampValue converted from a TimestampVal. The caller must ensure the TimestampVal does not represent a NULL.
Definition at line 111 of file timestamp-value.h.
References impala_udf::TimestampVal::date, date_, impala_udf::AnyVal::is_null, time_, and impala_udf::TimestampVal::time_of_day.
Referenced by impala::CastFunctions::CastToStringVal(), impala::ExprContext::GetValue(), impala::MathFunctions::LeastGreatest(), impala::AggregateFunctions::Max(), impala::AggregateFunctions::Min(), impala::PrintSample(), impala::AggFnEvaluator::SetDstSlot(), impala::AggregateFunctions::TimestampAvgRemove(), impala::AggregateFunctions::TimestampAvgUpdate(), and impala::UdfBuiltins::Trunc().
|
inline |
Definition at line 132 of file timestamp-value.h.
References date_.
Referenced by impala::TimestampFunctions::DateAddSub(), impala::TimestampFunctions::DateDiff(), impala::TimestampFunctions::DayOfMonth(), impala::TimestampFunctions::DayOfWeek(), impala::TimestampFunctions::DayOfYear(), DebugString(), HasDateAndTime(), HasDateOrTime(), impala::TimestampFunctions::Month(), impala::ImpalaServer::QueryStateToJson(), impala::TEST(), impala::TimestampFunctions::TimeAddSub(), ToUnixTime(), impala::TimestampFunctions::Unix(), impala::TimestampFunctions::UnixFromString(), impala::TimestampFunctions::WeekOfYear(), and impala::TimestampFunctions::Year().
|
inline |
Definition at line 135 of file timestamp-value.h.
References HasDate(), and HasTime().
Referenced by impala::HdfsParquetScanner::ColumnReader< T >::ConvertSlot(), and UtcToLocal().
|
inline |
Definition at line 134 of file timestamp-value.h.
References HasDate(), and HasTime().
Referenced by impala::CastFunctions::CastToTimestampVal(), impala::TimestampFunctions::FromUtc(), impala::TimestampFunctions::Now(), impala::ExprTest::TestValidTimestampValue(), ToTimestampVal(), impala::TimestampFunctions::ToUtc(), and impala::TextConverter::WriteSlot().
|
inline |
Definition at line 223 of file timestamp-value.h.
References date_, impala::hash, impala::HashUtil::Hash(), and time_.
Referenced by impala::AnyValUtil::Hash(), and impala::hash_value().
|
inline |
Definition at line 133 of file timestamp-value.h.
References time_.
Referenced by DebugString(), HasDateAndTime(), HasDateOrTime(), impala::TimestampFunctions::Hour(), impala::TimestampFunctions::Minute(), impala::TimestampFunctions::Second(), impala::TEST(), and ToSubsecondUnixTime().
|
inlinestatic |
Returns the current local time with microsecond accuracy. This should not be used to time something because it is affected by adjustments to the system clock such as a daylight savings or a manual correction by a system admin. For timings, use functions in util/time.h.
Definition at line 105 of file timestamp-value.h.
References TimestampValue().
Referenced by impala::ImpalaServer::ConnectionStart(), impala::ImpalaServer::QueryExecState::Done(), impala::ImpalaServer::ImpalaServer(), impala::ImpalaServer::PrepareQueryContext(), and impala::StatestoreSubscriber::RecoveryModeChecker().
|
inline |
Definition at line 202 of file timestamp-value.h.
|
inline |
Definition at line 204 of file timestamp-value.h.
|
inline |
Definition at line 208 of file timestamp-value.h.
|
inline |
Definition at line 192 of file timestamp-value.h.
|
inline |
Definition at line 198 of file timestamp-value.h.
|
inline |
Definition at line 211 of file timestamp-value.h.
|
inline |
Definition at line 215 of file timestamp-value.h.
|
inline |
Definition at line 187 of file timestamp-value.h.
References date_.
|
inline |
Definition at line 188 of file timestamp-value.h.
References time_.
|
inlinestatic |
Definition at line 219 of file timestamp-value.h.
Referenced by impala::RawValue::PrintValueAsBytes().
|
inline |
Definition at line 190 of file timestamp-value.h.
References time_.
Referenced by impala::TimestampFunctions::DateAddSub(), impala::TimestampFunctions::Hour(), impala::TimestampFunctions::Minute(), impala::TimestampFunctions::Second(), impala::TEST(), impala::TimestampFunctions::TimeAddSub(), impala::TimestampFunctions::ToUtc(), impala::UdfBuiltins::Trunc(), and impala::ValidateTimestamp().
|
inline |
Definition at line 128 of file timestamp-value.h.
Referenced by impala::TimestampFunctions::FromUtc().
|
inline |
Definition at line 175 of file timestamp-value.h.
References HasTime(), LIKELY, ONE_BILLIONTH, time_, and ToUnixTime().
Referenced by impala::ImpalaServer::QueryStateToJson(), impala::AggregateFunctions::TimestampAvgRemove(), and impala::AggregateFunctions::TimestampAvgUpdate().
|
inline |
Returns a TimestampVal representation in the output variable. The caller must ensure the TimestampValue instance has a valid date or time before calling.
Definition at line 121 of file timestamp-value.h.
References impala_udf::TimestampVal::date, date_, HasDateOrTime(), impala_udf::AnyVal::is_null, time_, and impala_udf::TimestampVal::time_of_day.
Referenced by impala::DecimalOperators::CastToTimestampVal(), impala::CastFunctions::CastToTimestampVal(), impala::TimestampFunctions::DateAddSub(), impala::TimestampFunctions::FromUtc(), impala::SlotRef::GetTimestampVal(), impala::MathFunctions::LeastGreatest(), impala::TimestampFunctions::Now(), impala::AggregateFunctions::TimestampAvgGetValue(), and impala::UdfBuiltins::Trunc().
|
inline |
Returns the Unix time (seconds since the Unix epoch) representation. The time zone interpretation of the TimestampValue instance is determined by FLAGS_use_local_tz_for_unix_timestamp_conversions. If the flag is true, the instance is interpreted as a local value. If the flag is false, UTC is assumed. In either case, the caller should ensure that the TimestampValue instance is a valid date before the call.
Definition at line 164 of file timestamp-value.h.
References date_, HasDate(), and time_.
Referenced by impala::TEST(), impala::ExprTest::TestTimestampValue(), ToSubsecondUnixTime(), impala::TimestampFunctions::Unix(), and impala::TimestampFunctions::UnixFromString().
|
inlineprivate |
Return a ptime representation of the given Unix time (seconds since the Unix epoch). The time zone of the resulting ptime is determined by FLAGS_use_local_tz_for_unix_timestamp_conversions. If the flag is true, the value will be in the local time zone. If the flag is false, the value will be in UTC.
Unix times are represented internally in boost as 32 bit ints which limits the range of dates to 1901-2038 (https://svn.boost.org/trac/boost/ticket/3109), so libc functions will be used instead.
Definition at line 252 of file timestamp-value.h.
References UNLIKELY.
Referenced by TimestampValue().
void impala::TimestampValue::UtcToLocal | ( | ) |
Converts from UTC to local time in-place. The caller must ensure the TimestampValue this function is called upon has both a valid date and time.
Definition at line 48 of file timestamp-value.cc.
References date_, HasDateAndTime(), time_, and UNLIKELY.
Referenced by impala::HdfsParquetScanner::ColumnReader< T >::ConvertSlot().
|
friend |
Definition at line 231 of file timestamp-value.h.
|
private |
4 -bytes - stores the date as a day
Definition at line 246 of file timestamp-value.h.
Referenced by date(), DebugString(), Format(), FromTimestampVal(), HasDate(), Hash(), operator<(), operator=(), operator==(), operator>(), set_date(), TimestampValue(), ToPtime(), ToTimestampVal(), ToUnixTime(), and UtcToLocal().
|
static |
Definition at line 228 of file timestamp-value.h.
Referenced by impala::LlvmCodeGen::LoadImpalaIR().
|
staticprivate |
Used when converting a time with fractional seconds which are stored as in integer to a Unix time stored as a double.
Definition at line 235 of file timestamp-value.h.
Referenced by TimestampValue(), and ToSubsecondUnixTime().
|
private |
8 bytes - stores the nanoseconds within the current day
Boost ptime leaves a gap in the structure, so we swap the order to make it 12 contiguous bytes. We then must convert to and from the boost ptime data type. See IMP-87 for more information on why using ptime with the 4 byte gap is problematic.
Definition at line 243 of file timestamp-value.h.
Referenced by DebugString(), Format(), FromTimestampVal(), Hash(), HasTime(), operator<(), operator=(), operator==(), operator>(), set_time(), time(), TimestampValue(), ToPtime(), ToSubsecondUnixTime(), ToTimestampVal(), ToUnixTime(), and UtcToLocal().