# 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.

# Preparation.
=> DBGInvoke __enable_schema_sync_service('true')

=> DBGInvoke __drop_tidb_table(default, test)
=> drop table if exists default.test



# Data.
=> DBGInvoke __mock_tidb_table(default, test, 'col_1 String, col_2 Int64')
=> DBGInvoke __refresh_mapped_table_schema(default, test)
=> DBGInvoke __put_region(4, 0, 100, default, test)
=> DBGInvoke __put_region(5, 100, 200, default, test)
=> DBGInvoke __put_region(6, 200, 300, default, test)

# shuffle agg with empty table
=> DBGInvoke tidb_query('select count(col_1) from default.test group by col_2', 4,'mpp_query:true,mpp_partition_num:3')

=> DBGInvoke __raft_insert_row(default, test, 4, 50, 'test1', 666)
=> DBGInvoke __raft_insert_row(default, test, 4, 51, 'test2', 666)
=> DBGInvoke __raft_insert_row(default, test, 4, 52, 'test3', 777)
=> DBGInvoke __raft_insert_row(default, test, 4, 53, 'test4', 888)
=> DBGInvoke __raft_insert_row(default, test, 5, 150, 'test1', 666)
=> DBGInvoke __raft_insert_row(default, test, 5, 151, 'test2', 666)
=> DBGInvoke __raft_insert_row(default, test, 5, 152, 'test3', 777)
=> DBGInvoke __raft_insert_row(default, test, 5, 153, 'test4', 888)
=> DBGInvoke __raft_insert_row(default, test, 6, 250, 'test1', 666)
=> DBGInvoke __raft_insert_row(default, test, 6, 251, 'test2', 666)
=> DBGInvoke __raft_insert_row(default, test, 6, 252, 'test3', 777)
=> DBGInvoke __raft_insert_row(default, test, 6, 253, 'test4', 888)

# shuffle agg
=> DBGInvoke tidb_query('select count(col_1), col_2 from default.test group by col_2', 4,'mpp_query:true,mpp_partition_num:3')
┌─exchange_receiver_0─┬─exchange_receiver_1─┐
│                   6 │                 666 │
│                   3 │                 777 │
│                   3 │                 888 │
└─────────────────────┴─────────────────────┘

# Clean up.
=> DBGInvoke __drop_tidb_table(default, test)
=> drop table if exists default.test
