Skip to content

Commit

Permalink
*: use StaticExprContext instead of mock context to build expression
Browse files Browse the repository at this point in the history
  • Loading branch information
lcwangchao committed Jun 25, 2024
1 parent b3ed886 commit 3da045d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pkg/ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -4259,9 +4259,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))
Expand Down
2 changes: 1 addition & 1 deletion pkg/table/tables/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ go_library(
"//pkg/errno",
"//pkg/expression",
"//pkg/expression/context",
"//pkg/expression/contextstatic",
"//pkg/kv",
"//pkg/meta",
"//pkg/meta/autoid",
Expand All @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions pkg/table/tables/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3da045d

Please sign in to comment.