MakeEvalContextStatic converts the `exprctx.StaticConvertibleEvalContext` to `EvalContext`.
(ctx exprctx.StaticConvertibleEvalContext)
| 488 | |
| 489 | // MakeEvalContextStatic converts the `exprctx.StaticConvertibleEvalContext` to `EvalContext`. |
| 490 | func MakeEvalContextStatic(ctx exprctx.StaticConvertibleEvalContext) *EvalContext { |
| 491 | typeCtx := ctx.TypeCtx() |
| 492 | errCtx := ctx.ErrCtx() |
| 493 | |
| 494 | // TODO: at least provide some optional eval prop provider which is suitable to be used in the static context. |
| 495 | props := make([]exprctx.OptionalEvalPropProvider, 0, exprctx.OptPropsCnt) |
| 496 | |
| 497 | params := variable.NewPlanCacheParamList() |
| 498 | for _, param := range ctx.AllParamValues() { |
| 499 | params.Append(param) |
| 500 | } |
| 501 | |
| 502 | // TODO: use a more structural way to replace the closure. |
| 503 | // These closure makes sure the fields which may be changed in the execution of the next statement will not be embedded into them, to make |
| 504 | // sure it's safe to call them after the session continues to execute other statements. |
| 505 | staticCtx := NewEvalContext( |
| 506 | WithWarnHandler(ctx.GetWarnHandler()), |
| 507 | WithSQLMode(ctx.SQLMode()), |
| 508 | WithTypeFlags(typeCtx.Flags()), |
| 509 | WithLocation(typeCtx.Location()), |
| 510 | WithErrLevelMap(errCtx.LevelMap()), |
| 511 | WithCurrentDB(ctx.CurrentDB()), |
| 512 | WithCurrentTime(func() func() (time.Time, error) { |
| 513 | currentTime, currentTimeErr := ctx.CurrentTime() |
| 514 | |
| 515 | return func() (time.Time, error) { |
| 516 | return currentTime, currentTimeErr |
| 517 | } |
| 518 | }()), |
| 519 | WithMaxAllowedPacket(ctx.GetMaxAllowedPacket()), |
| 520 | WithDefaultWeekFormatMode(ctx.GetDefaultWeekFormatMode()), |
| 521 | WithDivPrecisionIncrement(ctx.GetDivPrecisionIncrement()), |
| 522 | WithParamList(params), |
| 523 | WithUserVarsReader(ctx.GetUserVarsReader().Clone()), |
| 524 | WithOptionalProperty(props...), |
| 525 | WithEnableRedactLog(ctx.GetTiDBRedactLog()), |
| 526 | ) |
| 527 | |
| 528 | return staticCtx |
| 529 | } |