From c63c2506e7b28dd70a323ebf8e44d52242e046df Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Wed, 19 Jun 2024 13:52:08 +0800 Subject: [PATCH] *: use `StaticExprContext` instead of mock context to build expression --- pkg/ddl/partition.go | 6 +++--- pkg/table/tables/BUILD.bazel | 2 +- pkg/table/tables/partition.go | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/ddl/partition.go b/pkg/ddl/partition.go index 4b0a43d451b90..1f35c7960cd25 100644 --- a/pkg/ddl/partition.go +++ b/pkg/ddl/partition.go @@ -33,6 +33,7 @@ import ( "github.com/pingcap/tidb/pkg/ddl/placement" "github.com/pingcap/tidb/pkg/domain/infosync" "github.com/pingcap/tidb/pkg/expression" + "github.com/pingcap/tidb/pkg/expression/contextstatic" "github.com/pingcap/tidb/pkg/infoschema" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta" @@ -59,7 +60,6 @@ import ( "github.com/pingcap/tidb/pkg/util/dbterror" "github.com/pingcap/tidb/pkg/util/hack" "github.com/pingcap/tidb/pkg/util/mathutil" - "github.com/pingcap/tidb/pkg/util/mock" decoder "github.com/pingcap/tidb/pkg/util/rowDecoder" "github.com/pingcap/tidb/pkg/util/slice" "github.com/pingcap/tidb/pkg/util/stringutil" @@ -4258,9 +4258,9 @@ func (cns columnNameSlice) At(i int) string { } func isPartExprUnsigned(ectx expression.EvalContext, tbInfo *model.TableInfo) bool { - // We should not rely on any configuration, system or session variables, so use a mock ctx! + // We should not rely on any configuration, system or session variables, so use a default context. // Same as in tables.newPartitionExpr - ctx := mock.NewContext() + ctx := contextstatic.NewStaticExprContext() expr, err := expression.ParseSimpleExpr(ctx, tbInfo.Partition.Expr, expression.WithTableInfo("", tbInfo)) if err != nil { logutil.DDLLogger().Error("isPartExpr failed parsing expression!", zap.Error(err)) diff --git a/pkg/table/tables/BUILD.bazel b/pkg/table/tables/BUILD.bazel index 84cbc629f1ef2..4392c47fcd9bd 100644 --- a/pkg/table/tables/BUILD.bazel +++ b/pkg/table/tables/BUILD.bazel @@ -18,6 +18,7 @@ go_library( "//pkg/errno", "//pkg/expression", "//pkg/expression/context", + "//pkg/expression/contextstatic", "//pkg/kv", "//pkg/meta", "//pkg/meta/autoid", @@ -43,7 +44,6 @@ go_library( "//pkg/util/generatedexpr", "//pkg/util/hack", "//pkg/util/logutil", - "//pkg/util/mock", "//pkg/util/ranger", "//pkg/util/rowcodec", "//pkg/util/sqlexec", diff --git a/pkg/table/tables/partition.go b/pkg/table/tables/partition.go index 0525258813866..1c6bf4b4af3ca 100644 --- a/pkg/table/tables/partition.go +++ b/pkg/table/tables/partition.go @@ -29,6 +29,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/tidb/pkg/errctx" "github.com/pingcap/tidb/pkg/expression" + "github.com/pingcap/tidb/pkg/expression/contextstatic" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/parser" "github.com/pingcap/tidb/pkg/parser/ast" @@ -44,7 +45,6 @@ import ( "github.com/pingcap/tidb/pkg/util/dbterror" "github.com/pingcap/tidb/pkg/util/hack" "github.com/pingcap/tidb/pkg/util/logutil" - "github.com/pingcap/tidb/pkg/util/mock" "github.com/pingcap/tidb/pkg/util/ranger" "github.com/pingcap/tidb/pkg/util/stringutil" "go.uber.org/zap" @@ -240,8 +240,8 @@ func initPartition(t *partitionedTable, def model.PartitionDefinition) (*partiti func newPartitionExpr(tblInfo *model.TableInfo, tp model.PartitionType, expr string, partCols []model.CIStr, defs []model.PartitionDefinition) (*PartitionExpr, error) { // a partitioned table cannot rely on session context/sql modes, so use a default one! - ctx := mock.NewContext() - dbName := model.NewCIStr(ctx.GetSessionVars().CurrentDB) + ctx := contextstatic.NewStaticExprContext() + dbName := model.NewCIStr(ctx.GetEvalCtx().CurrentDB()) columns, names, err := expression.ColumnInfos2ColumnsAndNames(ctx, dbName, tblInfo.Name, tblInfo.Cols(), tblInfo) if err != nil { return nil, err