Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
timestamp-parse-util.cc
Go to the documentation of this file.
1 // Copyright 2013 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 
16 #include <boost/assign/list_of.hpp>
17 
18 namespace assign = boost::assign;
19 using boost::unordered_map;
20 
21 namespace impala {
22 
24 unordered_map<StringValue, int> TimestampParser::REV_MONTH_INDEX;
27 DateTimeFormatContext TimestampParser::DEFAULT_DATE_CTX;
28 DateTimeFormatContext TimestampParser::DEFAULT_TIME_CTX;
29 DateTimeFormatContext TimestampParser::DEFAULT_DATE_TIME_CTX[10];
30 DateTimeFormatContext TimestampParser::DEFAULT_ISO_DATE_TIME_CTX[10];
31 DateTimeFormatContext TimestampParser::DEFAULT_TIME_FRAC_CTX[10];
32 
35  // This needs to be lazily init'd because a StringValues hash function will be invoked
36  // for each entry that's placed in the map. The hash function expects that
37  // CpuInfo::Init() has already been called.
38  REV_MONTH_INDEX = assign::map_list_of
39  (StringValue("jan"), 1)(StringValue("feb"), 2)(StringValue("mar"), 3)
40  (StringValue("apr"), 4)(StringValue("may"), 5)(StringValue("jun"), 6)
41  (StringValue("jul"), 7)(StringValue("aug"), 8)(StringValue("sep"), 9)
42  (StringValue("oct"), 10)(StringValue("nov"), 11)(StringValue("dec"), 12);
43 
44  // Setup the default date/time context yyyy-MM-dd HH:mm:ss.SSSSSSSSS
45  const char* DATE_TIME_CTX_FMT = "yyyy-MM-dd HH:mm:ss.SSSSSSSSS";
46  const int FRACTIONAL_MAX_LEN = 9;
47  for (int i = FRACTIONAL_MAX_LEN; i >= 0; --i) {
48  DEFAULT_DATE_TIME_CTX[i].Reset(DATE_TIME_CTX_FMT,
49  DEFAULT_DATE_TIME_FMT_LEN - (FRACTIONAL_MAX_LEN - i));
51  }
52 
53  // Setup the default ISO date/time context yyyy-MM-ddTHH:mm:ss.SSSSSSSSS
54  for (int i = FRACTIONAL_MAX_LEN; i >= 0; --i) {
55  DEFAULT_ISO_DATE_TIME_CTX[i].Reset("yyyy-MM-ddTHH:mm:ss.SSSSSSSSS",
56  DEFAULT_DATE_TIME_FMT_LEN - (FRACTIONAL_MAX_LEN - i));
58  }
59 
60  // Setup the short default date/time context yyyy-MM-dd HH:mm:ss
61  DEFAULT_SHORT_DATE_TIME_CTX.Reset("yyyy-MM-dd HH:mm:ss",
64 
65  // Setup the short default ISO date/time context yyyy-MM-ddTHH:mm:ss
66  DEFAULT_SHORT_ISO_DATE_TIME_CTX.Reset("yyyy-MM-ddTHH:mm:ss",
69 
70  // Setup the default short date context yyyy-MM-dd
73 
74  // Setup the default short time context HH:mm:ss
77 
78  // Setup the default short time context with fractional seconds HH:mm:ss.SSSSSSSSS
79  for (int i = FRACTIONAL_MAX_LEN; i >= 0; --i) {
80  DEFAULT_TIME_FRAC_CTX[i].Reset(DATE_TIME_CTX_FMT + 11,
81  DEFAULT_TIME_FRAC_FMT_LEN - (FRACTIONAL_MAX_LEN - i));
83  }
84  // Flag that the parser is ready.
86 }
87 
88 }
static DateTimeFormatContext DEFAULT_DATE_TIME_CTX[10]
static const int DEFAULT_TIME_FRAC_FMT_LEN
static bool ParseFormatTokens(DateTimeFormatContext *dt_ctx)
static boost::unordered_map< StringValue, int > REV_MONTH_INDEX
Lazily initialized pseudo-constant hashmap for mapping month names to an index.
void Reset(const char *fmt, int fmt_len)
static bool initialized_
Used to indicate if the parsing state has been initialized.
static const int DEFAULT_DATE_TIME_FMT_LEN
static const int DEFAULT_DATE_FMT_LEN
Constants to hold default format lengths.
static DateTimeFormatContext DEFAULT_TIME_FRAC_CTX[10]
static DateTimeFormatContext DEFAULT_TIME_CTX
static DateTimeFormatContext DEFAULT_SHORT_DATE_TIME_CTX
static DateTimeFormatContext DEFAULT_ISO_DATE_TIME_CTX[10]
static const int DEFAULT_SHORT_DATE_TIME_FMT_LEN
static DateTimeFormatContext DEFAULT_DATE_CTX
static DateTimeFormatContext DEFAULT_SHORT_ISO_DATE_TIME_CTX
static const int DEFAULT_TIME_FMT_LEN