MCPcopy Create free account
hub / github.com/apache/impala / TokenizeByStr

Method TokenizeByStr

be/src/runtime/datetime-simple-date-format-parser.cc:223–356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221}
222
223bool SimpleDateFormatTokenizer::TokenizeByStr( DateTimeFormatContext* dt_ctx,
224 bool accept_time_toks) {
225 DCHECK(dt_ctx != NULL);
226 DCHECK(dt_ctx->fmt != NULL);
227 DCHECK_GT(dt_ctx->fmt_len, 0);
228 DCHECK_EQ(dt_ctx->toks.size(), 0);
229 const char* str_begin = dt_ctx->fmt;
230 const char* str_end = str_begin + dt_ctx->fmt_len;
231 const char* str = str_begin;
232 const char* tok_end;
233
234 // Parse the 4-digit year
235 tok_end = ParseDigitToken(str, str_end);
236 if (tok_end - str == 4) {
237 dt_ctx->toks.push_back(
238 DateTimeFormatToken(YEAR, str - str_begin, tok_end - str, str));
239 str = tok_end;
240
241 // Check for the date separator '-'
242 tok_end = ParseSeparatorToken(str, str_end, '-');
243 if (tok_end - str != 1) return false;
244 dt_ctx->toks.push_back(
245 DateTimeFormatToken(SEPARATOR, str - str_begin, tok_end - str, str));
246 str = tok_end;
247
248 // Parse the 1 or 2 digit month.
249 tok_end = ParseDigitToken(str, str_end);
250 if (tok_end - str != 1 && tok_end - str != 2) return false;
251 dt_ctx->toks.push_back(
252 DateTimeFormatToken(MONTH_IN_YEAR, str - str_begin, tok_end - str, str));
253 str = tok_end;
254
255 // Check for the date separator '-'
256 tok_end = ParseSeparatorToken(str, str_end, '-');
257 if (tok_end - str != 1) return false;
258 dt_ctx->toks.push_back(
259 DateTimeFormatToken(SEPARATOR, str - str_begin, tok_end - str, str));
260 str = tok_end;
261
262 // Parse the 1 or 2 digit day in month
263 tok_end = ParseDigitToken(str, str_end);
264 if (tok_end - str != 1 && tok_end - str != 2) return false;
265 dt_ctx->toks.push_back(
266 DateTimeFormatToken(DAY_IN_MONTH, str - str_begin, tok_end - str, str));
267 str = tok_end;
268 dt_ctx->has_date_toks = true;
269
270 // If the string ends here, we only have a date component
271 if (str == str_end) return true;
272 // If time tokens are not accepted, string should have ended here.
273 if (!accept_time_toks) return false;
274
275 // Check for the space between date and time component
276 if (*str != ' ' && *str != 'T') return false;
277 char sep = *str;
278 tok_end = ParseSeparatorToken(str, str_end, sep);
279 if (tok_end - str < 1) return false;
280 // IMPALA-6641: Multiple spaces are okay, 'T' separator must be single

Callers

nothing calls this directly

Calls 3

DateTimeFormatTokenClass · 0.85
push_backMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected