-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executor: migrate test-infra to testify for aggregate_test.go (#29903)
- Loading branch information
1 parent
7aa86cc
commit e448d93
Showing
5 changed files
with
340 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2021 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 executor_test | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/pingcap/tidb/testkit" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAggInDisk(t *testing.T) { | ||
store, clean := testkit.CreateMockStore(t) | ||
defer clean() | ||
tk := testkit.NewTestKit(t, store) | ||
tk.MustExec("use test") | ||
tk.MustExec("set tidb_hashagg_final_concurrency = 1;") | ||
tk.MustExec("set tidb_hashagg_partial_concurrency = 1;") | ||
tk.MustExec("set tidb_mem_quota_query = 4194304") | ||
tk.MustExec("drop table if exists t1") | ||
tk.MustExec("create table t(a int)") | ||
sql := "insert into t values (0)" | ||
for i := 1; i <= 200; i++ { | ||
sql += fmt.Sprintf(",(%v)", i) | ||
} | ||
sql += ";" | ||
tk.MustExec(sql) | ||
rows := tk.MustQuery("desc analyze select /*+ HASH_AGG() */ avg(t1.a) from t t1 join t t2 group by t1.a, t2.a;").Rows() | ||
for _, row := range rows { | ||
length := len(row) | ||
line := fmt.Sprintf("%v", row) | ||
disk := fmt.Sprintf("%v", row[length-1]) | ||
if strings.Contains(line, "HashAgg") { | ||
require.False(t, strings.Contains(disk, "0 Bytes")) | ||
require.True(t, strings.Contains(disk, "MB") || | ||
strings.Contains(disk, "KB") || | ||
strings.Contains(disk, "Bytes")) | ||
} | ||
} | ||
|
||
// Add code cover | ||
// Test spill chunk. Add a line to avoid tmp spill chunk is always full. | ||
tk.MustExec("insert into t values(0)") | ||
tk.MustQuery("select sum(tt.b) from ( select /*+ HASH_AGG() */ avg(t1.a) as b from t t1 join t t2 group by t1.a, t2.a) as tt").Check( | ||
testkit.Rows("4040100.0000")) | ||
// Test no groupby and no data. | ||
tk.MustExec("drop table t;") | ||
tk.MustExec("create table t(c int, c1 int);") | ||
tk.MustQuery("select /*+ HASH_AGG() */ count(c) from t;").Check(testkit.Rows("0")) | ||
tk.MustQuery("select /*+ HASH_AGG() */ count(c) from t group by c1;").Check(testkit.Rows()) | ||
} |
Oops, something went wrong.