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

#tidb version : https://github.com/pingcap/tidb/compare/master...bestwoody:support_enum_pushdown?expand=1
mysql> DROP TABLE if EXISTS test.shirts

mysql> CREATE TABLE test.shirts (name VARCHAR(40),     size ENUM('x-small', 'small', 'medium', 'large', 'x-large') )

mysql> INSERT INTO test.shirts (name, size) VALUES ('dress shirt','large'), ('t-shirt','medium'),   ('polo shirt','small')

mysql> analyze table test.shirts

mysql> ALTER TABLE test.shirts SET TIFLASH REPLICA 1

func> wait_table test shirts

mysql> set tidb_enforce_mpp=1; select sum(cast(size as decimal)) from test.shirts
+----------------------------+
| sum(cast(size as decimal)) |
+----------------------------+
|                          9 |
+----------------------------+

mysql> set tidb_enforce_mpp=1; select sum(cast(size as signed)) from test.shirts
+---------------------------+
| sum(cast(size as signed)) |
+---------------------------+
|                         9 |
+---------------------------+

mysql> set tidb_enforce_mpp=1; select sum(cast(size as unsigned)) from test.shirts
+-----------------------------+
| sum(cast(size as unsigned)) |
+-----------------------------+
|                           9 |
+-----------------------------+

mysql> set tidb_enforce_mpp=1; select sum(size) from test.shirts
+-----------+
| sum(size) |
+-----------+
|         9 |
+-----------+

mysql> set tidb_enforce_mpp=1; select sum(size + 0) from test.shirts
+---------------+
| sum(size + 0) |
+---------------+
|             9 |
+---------------+

mysql> set tidb_enforce_mpp=1; select sum(size + 0.0) from test.shirts;
+-----------------+
| sum(size + 0.0) |
+-----------------+
|               9 |
+-----------------+

mysql> set tidb_enforce_mpp=1; select sum(cast(size as double)) from test.shirts;
+---------------------------+
| sum(cast(size as double)) |
+---------------------------+
|                         9 |
+---------------------------+

mysql> set tidb_enforce_mpp=1; select sum(cast(size as real)) from test.shirts;
+-------------------------+
| sum(cast(size as real)) |
+-------------------------+
|                       9 |
+-------------------------+