Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::TimestampValue Class Reference

#include <timestamp-value.h>

Collaboration diagram for impala::TimestampValue:

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
 
TimestampValueoperator= (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
 

Detailed Description

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.

Constructor & Destructor Documentation

impala::TimestampValue::TimestampValue ( )
inline

Definition at line 67 of file timestamp-value.h.

Referenced by LocalTime().

impala::TimestampValue::TimestampValue ( const boost::gregorian::date &  d,
const boost::posix_time::time_duration &  t 
)
inline

Definition at line 69 of file timestamp-value.h.

impala::TimestampValue::TimestampValue ( const boost::posix_time::ptime &  t)
inline

Definition at line 73 of file timestamp-value.h.

impala::TimestampValue::TimestampValue ( const TimestampValue tv)
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_.

template<typename Number >
impala::TimestampValue::TimestampValue ( Number  unix_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().

impala::TimestampValue::TimestampValue ( int64_t  unix_time,
int64_t  nanos 
)
inline

Definition at line 88 of file timestamp-value.h.

References UnixTimeToPtime().

impala::TimestampValue::TimestampValue ( double  unix_time)
inlineexplicit

Definition at line 94 of file timestamp-value.h.

References ONE_BILLIONTH, and UnixTimeToPtime().

Member Function Documentation

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().

bool impala::TimestampValue::HasDateAndTime ( ) const
inline
uint32_t impala::TimestampValue::Hash ( int  seed = 0) const
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().

static TimestampValue impala::TimestampValue::LocalTime ( )
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().

bool impala::TimestampValue::operator!= ( const TimestampValue other) const
inline

Definition at line 202 of file timestamp-value.h.

bool impala::TimestampValue::operator< ( const TimestampValue other) const
inline

Definition at line 204 of file timestamp-value.h.

References date_, and time_.

bool impala::TimestampValue::operator<= ( const TimestampValue other) const
inline

Definition at line 208 of file timestamp-value.h.

TimestampValue& impala::TimestampValue::operator= ( const boost::posix_time::ptime &  ptime)
inline

Definition at line 192 of file timestamp-value.h.

References date_, and time_.

bool impala::TimestampValue::operator== ( const TimestampValue other) const
inline

Definition at line 198 of file timestamp-value.h.

References date_, and time_.

bool impala::TimestampValue::operator> ( const TimestampValue other) const
inline

Definition at line 211 of file timestamp-value.h.

References date_, and time_.

bool impala::TimestampValue::operator>= ( const TimestampValue other) const
inline

Definition at line 215 of file timestamp-value.h.

void impala::TimestampValue::set_date ( const boost::gregorian::date  d)
inline

Definition at line 187 of file timestamp-value.h.

References date_.

void impala::TimestampValue::set_time ( const boost::posix_time::time_duration  t)
inline

Definition at line 188 of file timestamp-value.h.

References time_.

static size_t impala::TimestampValue::Size ( )
inlinestatic

Definition at line 219 of file timestamp-value.h.

Referenced by impala::RawValue::PrintValueAsBytes().

void impala::TimestampValue::ToPtime ( boost::posix_time::ptime *  ptp) const
inline

Definition at line 128 of file timestamp-value.h.

References date_, and time_.

Referenced by impala::TimestampFunctions::FromUtc().

double impala::TimestampValue::ToSubsecondUnixTime ( ) const
inline
time_t impala::TimestampValue::ToUnixTime ( ) const
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().

boost::posix_time::ptime impala::TimestampValue::UnixTimeToPtime ( time_t  unix_time) const
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().

Friends And Related Function Documentation

friend class UnusedClass
friend

Definition at line 231 of file timestamp-value.h.

Member Data Documentation

boost::gregorian::date impala::TimestampValue::date_
private
const char * impala::TimestampValue::LLVM_CLASS_NAME = "class.impala::TimestampValue"
static

Definition at line 228 of file timestamp-value.h.

Referenced by impala::LlvmCodeGen::LoadImpalaIR().

const double impala::TimestampValue::ONE_BILLIONTH = 0.000000001
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().

boost::posix_time::time_duration impala::TimestampValue::time_
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().


The documentation for this class was generated from the following files: