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

Method CastToDateVal

be/src/exprs/cast-functions-ir.cc:546–573  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

544}
545
546DateVal CastFunctions::CastToDateVal(FunctionContext* ctx, const StringVal& val) {
547 DCHECK(ctx != nullptr);
548 if (val.is_null) return DateVal::null();
549 const char* string_val = reinterpret_cast<const char*>(val.ptr);
550 const DateTimeFormatContext* format_ctx =
551 reinterpret_cast<const DateTimeFormatContext*>(
552 ctx->GetFunctionState(FunctionContext::FRAGMENT_LOCAL));
553 DateValue dv;
554 if (format_ctx != nullptr) {
555 dv = DateValue::ParseIsoSqlFormat(string_val, val.len, *format_ctx);
556 } else {
557 dv = DateValue::ParseSimpleDateFormat(string_val, val.len, true);
558 }
559 if (UNLIKELY(!dv.IsValid())) {
560 string invalid_val = string(string_val, val.len);
561 string error_msg;
562 if (format_ctx == nullptr) {
563 error_msg = Substitute("String to Date parse failed. Invalid string val: '$0'",
564 invalid_val);
565 } else {
566 error_msg = Substitute("String to Date parse failed. Input '$0' doesn't match "
567 "with format '$1'", invalid_val, format_ctx->fmt);
568 }
569 ctx->SetError(error_msg.c_str());
570 return DateVal::null();
571 }
572 return dv.ToDateVal();
573}
574
575DateVal CastFunctions::CastToDateVal(FunctionContext* ctx, const TimestampVal& val) {
576 if (val.is_null) return DateVal::null();

Callers

nothing calls this directly

Calls 6

SubstituteFunction · 0.85
GetFunctionStateMethod · 0.80
ToDateValMethod · 0.80
DaysSinceUnixEpochMethod · 0.80
IsValidMethod · 0.45
SetErrorMethod · 0.45

Tested by

no test coverage detected