Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
timestamp-functions.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 
16 #ifndef IMPALA_EXPRS_TIMESTAMP_FUNCTIONS_H
17 #define IMPALA_EXPRS_TIMESTAMP_FUNCTIONS_H
18 
19 #include <boost/date_time/posix_time/posix_time.hpp>
20 #include <boost/date_time/gregorian/gregorian.hpp>
21 #include <boost/date_time/time_zone_base.hpp>
22 #include <boost/date_time/local_time/local_time.hpp>
23 #include <boost/thread/thread.hpp>
24 
25 #include "runtime/string-value.h"
27 #include "udf/udf.h"
28 
29 using namespace impala_udf;
30 
31 using namespace impala_udf;
32 
33 namespace impala {
34 
35 class Expr;
36 class OpcodeRegistry;
37 class TupleRow;
38 
41  public:
43  static void UnixAndFromUnixPrepare(FunctionContext* context,
45  static void UnixAndFromUnixClose(FunctionContext* context,
47 
49  static BigIntVal Unix(FunctionContext* context, const StringVal& string_val,
50  const StringVal& fmt);
52  static BigIntVal Unix(FunctionContext* context, const TimestampVal& tv_val);
54  static BigIntVal Unix(FunctionContext* context);
55 
56  static BigIntVal UnixFromString(FunctionContext* context, const StringVal& sv);
57 
61  template <class TIME>
62  static StringVal FromUnix(FunctionContext* context, const TIME& unix_time);
63  template <class TIME>
64  static StringVal FromUnix(FunctionContext* context, const TIME& unix_time,
65  const StringVal& fmt);
66 
68  static TimestampVal FromUtc(FunctionContext* context,
69  const TimestampVal& ts_val, const StringVal& tz_string_val);
70  static TimestampVal ToUtc(FunctionContext* context,
71  const TimestampVal& ts_val, const StringVal& tz_string_val);
72 
74  static StringVal DayName(FunctionContext* context, const TimestampVal& dow);
75 
77  static IntVal Year(FunctionContext* context, const TimestampVal& ts_val);
78  static IntVal Month(FunctionContext* context, const TimestampVal& ts_val);
79  static IntVal DayOfWeek(FunctionContext* context, const TimestampVal& ts_val);
80  static IntVal DayOfMonth(FunctionContext* context, const TimestampVal& ts_val);
81  static IntVal DayOfYear(FunctionContext* context, const TimestampVal& ts_val);
82  static IntVal WeekOfYear(FunctionContext* context, const TimestampVal& ts_val);
83  static IntVal Hour(FunctionContext* context, const TimestampVal& ts_val);
84  static IntVal Minute(FunctionContext* context, const TimestampVal& ts_val);
85  static IntVal Second(FunctionContext* context, const TimestampVal& ts_val);
86 
88  static TimestampVal Now(FunctionContext* context);
89  static StringVal ToDate(FunctionContext* context, const TimestampVal& ts_val);
90  static IntVal DateDiff(FunctionContext* context, const TimestampVal& ts_val1,
91  const TimestampVal& ts_val2);
92 
94  template <bool ISADD, class VALTYPE, class UNIT>
95  static TimestampVal DateAddSub(FunctionContext* context, const TimestampVal& ts_value,
96  const VALTYPE& count);
97 
99  template <bool ISADD, class VALTYPE, class UNIT>
100  static TimestampVal TimeAddSub(FunctionContext* context, const TimestampVal& ts_value,
101  const VALTYPE& count);
102 
105  static StringValue* CheckFormat(StringValue* format);
106 
108  static void ReportBadFormat(FunctionContext* context,
109  const StringVal& format, bool is_error);
110 
111  private:
113  static const char* MONDAY;
114  static const char* TUESDAY;
115  static const char* WEDNESDAY;
116  static const char* THURSDAY;
117  static const char* FRIDAY;
118  static const char* SATURDAY;
119  static const char* SUNDAY;
120 };
121 
124  public:
126  ~TimezoneDatabase();
127 
131  static boost::local_time::time_zone_ptr FindTimezone(const std::string& tz,
132  const TimestampValue& tv);
133 
135  static const boost::local_time::time_zone_ptr TIMEZONE_MSK_2011_NODST;
136 
137  private:
138  static const char* TIMEZONE_DATABASE_STR;
139  static boost::local_time::tz_database tz_database_;
140  static std::vector<std::string> tz_region_list_;
141 };
142 
143 } // namespace impala
144 
145 #endif
static const char * MONDAY
Static result values for DayName() function.
Functions to load and access the timestamp database.
static std::vector< std::string > tz_region_list_
This object has a compatible storage format with boost::ptime.
Definition: udf.h:495
uint64_t count
TODO: Reconsider whether this class needs to exist.
static boost::local_time::tz_database tz_database_
static const char * TIMEZONE_DATABASE_STR
static const boost::local_time::time_zone_ptr TIMEZONE_MSK_2011_NODST
Moscow Timezone No Daylight Savings Time (GMT+4), for use after March 2011.