Skip to content

Commit

Permalink
*: improve store bazel config
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
  • Loading branch information
hawkingrei committed Feb 15, 2023
1 parent a774575 commit 3580399
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
5 changes: 4 additions & 1 deletion planner/core/internal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "internal",
srcs = ["testkit.go"],
srcs = [
"testkit.go",
"util.go",
],
importpath = "github.com/pingcap/tidb/planner/core/internal",
visibility = ["//planner/core:__subpackages__"],
deps = [
Expand Down
13 changes: 0 additions & 13 deletions planner/core/internal/testkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import (

"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/expression/aggregation"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/store/mockstore/unistore"
"github.com/stretchr/testify/require"
Expand All @@ -45,17 +43,6 @@ func SetTiFlashReplica(t *testing.T, dom *domain.Domain, dbName, tableName strin
}
}

// WrapCastForAggFuncs wraps the args of an aggregate function with a cast function.
// If the mode is FinalMode or Partial2Mode, we do not need to wrap cast upon the args,
// since the types of the args are already the expected.
func WrapCastForAggFuncs(sctx sessionctx.Context, aggFuncs []*aggregation.AggFuncDesc) {
for i := range aggFuncs {
if aggFuncs[i].Mode != aggregation.FinalMode && aggFuncs[i].Mode != aggregation.Partial2Mode {
aggFuncs[i].WrapCastForAggArgs(sctx)
}
}
}

// WithMockTiFlash sets the mockStore to have N TiFlash stores (naming as tiflash0, tiflash1, ...).
func WithMockTiFlash(nodes int) mockstore.MockTiKVStoreOption {
return mockstore.WithMultipleOptions(
Expand Down
31 changes: 31 additions & 0 deletions planner/core/internal/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2023 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package internal

import (
"github.com/pingcap/tidb/expression/aggregation"
"github.com/pingcap/tidb/sessionctx"
)

// WrapCastForAggFuncs wraps the args of an aggregate function with a cast function.
// If the mode is FinalMode or Partial2Mode, we do not need to wrap cast upon the args,
// since the types of the args are already the expected.
func WrapCastForAggFuncs(sctx sessionctx.Context, aggFuncs []*aggregation.AggFuncDesc) {
for i := range aggFuncs {
if aggFuncs[i].Mode != aggregation.FinalMode && aggFuncs[i].Mode != aggregation.Partial2Mode {
aggFuncs[i].WrapCastForAggArgs(sctx)
}
}
}

0 comments on commit 3580399

Please sign in to comment.