| 27 | using namespace datetime_parse_util; |
| 28 | |
| 29 | Status CastFormatExpr::OpenEvaluator(FunctionContext::FunctionStateScope scope, |
| 30 | RuntimeState* state, ScalarExprEvaluator* eval) const { |
| 31 | DCHECK(eval != nullptr); |
| 32 | RETURN_IF_ERROR(ScalarFnCall::OpenEvaluator(scope, state, eval)); |
| 33 | if (scope != FunctionContext::FRAGMENT_LOCAL) return Status::OK(); |
| 34 | DCHECK_GE(fn_ctx_idx_, 0); |
| 35 | FunctionContext* fn_ctx = eval->fn_context(fn_ctx_idx_); |
| 36 | |
| 37 | std::unique_ptr<DateTimeFormatContext> dt_ctx = |
| 38 | std::make_unique<DateTimeFormatContext>(format_.c_str(), format_.length()); |
| 39 | bool accept_time_toks = (fn_ctx->GetReturnType().type != FunctionContext::TYPE_DATE && |
| 40 | fn_ctx->GetArgType(0)->type != FunctionContext::TYPE_DATE); |
| 41 | IsoSqlFormatTokenizer format_tokenizer(dt_ctx.get(), GetCastMode(fn_ctx), |
| 42 | accept_time_toks); |
| 43 | FormatTokenizationResult parse_result = format_tokenizer.Tokenize(); |
| 44 | if (parse_result != FormatTokenizationResult::SUCCESS) { |
| 45 | ReportBadFormat(fn_ctx, parse_result, StringVal(format_.c_str()), true); |
| 46 | return Status(TErrorCode::INTERNAL_ERROR, fn_ctx->error_msg()); |
| 47 | } |
| 48 | dt_ctx->SetCenturyBreakAndCurrentTime(*fn_ctx->impl()->state()->now()); |
| 49 | fn_ctx->SetFunctionState(scope, dt_ctx.release()); |
| 50 | |
| 51 | return Status::OK(); |
| 52 | } |
| 53 | |
| 54 | void CastFormatExpr::CloseEvaluator(FunctionContext::FunctionStateScope scope, |
| 55 | RuntimeState* state, ScalarExprEvaluator* eval) const { |
nothing calls this directly
no test coverage detected