From 5bc133e92d2fade6443d7410972e6438f2c60367 Mon Sep 17 00:00:00 2001 From: "TONG, Zhigao" Date: Mon, 18 Dec 2023 17:28:54 +0800 Subject: [PATCH 1/3] This is an automated cherry-pick of #8533 Signed-off-by: ti-chi-bot --- dbms/src/DataTypes/DataTypeEnum.h | 13 +++++++++- dbms/src/Flash/Coprocessor/ArrowColCodec.cpp | 14 +++++++++++ .../ddl/alter_column_enum.test | 24 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/dbms/src/DataTypes/DataTypeEnum.h b/dbms/src/DataTypes/DataTypeEnum.h index d2251e85662..a8ee6fd239f 100644 --- a/dbms/src/DataTypes/DataTypeEnum.h +++ b/dbms/src/DataTypes/DataTypeEnum.h @@ -81,11 +81,22 @@ class DataTypeEnum final : public IDataTypeEnum std::string getName() const override { return name; } const char * getFamilyName() const override; - const StringRef & getNameForValue(const FieldType & value) const + StringRef getNameForValue(const FieldType & value) const { const auto it = value_to_name_map.find(value); if (it == std::end(value_to_name_map)) +<<<<<<< HEAD throw Exception{"Unexpected value " + toString(value) + " for type " + getName(), ErrorCodes::LOGICAL_ERROR}; +======= + { + if (!value) + return {}; + + throw Exception{ + "Unexpected value " + toString(value) + " for type " + getName(), + ErrorCodes::LOGICAL_ERROR}; + } +>>>>>>> 6212eb1e53 (Support enum with index 0 (#8533)) return it->second; } diff --git a/dbms/src/Flash/Coprocessor/ArrowColCodec.cpp b/dbms/src/Flash/Coprocessor/ArrowColCodec.cpp index 36b9f1a6b89..625307f6aa5 100644 --- a/dbms/src/Flash/Coprocessor/ArrowColCodec.cpp +++ b/dbms/src/Flash/Coprocessor/ArrowColCodec.cpp @@ -280,10 +280,24 @@ void flashEnumColToArrowCol( continue; } } +<<<<<<< HEAD auto enum_value = (UInt64)flash_col->getElement(i); if (enum_value == 0 || enum_value > enum_value_size) throw TiFlashException("number of enum overflow enum boundary", Errors::Coprocessor::Internal); TiDBEnum ti_enum(enum_value, enum_type->getNameForValue((const DataTypeEnum16::FieldType)enum_value)); +======= + auto enum_value = static_cast(flash_col->getElement(i)); + if (enum_value > enum_value_size) + throw TiFlashException( + Errors::Coprocessor::Internal, + "number of enum value {} overflow enum boundary {}", + enum_value, + enum_value_size); + + TiDBEnum ti_enum( + enum_value, + enum_type->getNameForValue(static_cast(enum_value))); +>>>>>>> 6212eb1e53 (Support enum with index 0 (#8533)) dag_column.append(ti_enum); } } diff --git a/tests/fullstack-test2/ddl/alter_column_enum.test b/tests/fullstack-test2/ddl/alter_column_enum.test index e3bf0016a01..90759cce7f7 100644 --- a/tests/fullstack-test2/ddl/alter_column_enum.test +++ b/tests/fullstack-test2/ddl/alter_column_enum.test @@ -41,4 +41,28 @@ mysql> set session tidb_isolation_read_engines='tiflash'; select * from test.a1 | 4 | D | +----+------+ +mysql> SET SESSION SQL_MODE = ''; insert into test.a1 values (5,''); + +mysql> set session tidb_isolation_read_engines='tiflash'; select * from test.a1 order by id; ++----+------+ +| id | name | ++----+------+ +| 1 | A | +| 2 | B | +| 3 | C | +| 4 | D | +| 5 | | ++----+------+ + +mysql> set session tidb_isolation_read_engines='tiflash'; select name+0 from test.a1 order by id; ++--------+ +| name+0 | ++--------+ +| 1 | +| 2 | +| 3 | +| 4 | +| 0 | ++--------+ + mysql> drop table if exists test.a1 From 09f90ecee7698a4e096150fe4485bcb1eb4b20e8 Mon Sep 17 00:00:00 2001 From: "TONG, Zhigao" Date: Mon, 18 Dec 2023 17:46:33 +0800 Subject: [PATCH 2/3] Update DataTypeEnum.h --- dbms/src/DataTypes/DataTypeEnum.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/dbms/src/DataTypes/DataTypeEnum.h b/dbms/src/DataTypes/DataTypeEnum.h index a8ee6fd239f..7a510e57f8c 100644 --- a/dbms/src/DataTypes/DataTypeEnum.h +++ b/dbms/src/DataTypes/DataTypeEnum.h @@ -85,18 +85,11 @@ class DataTypeEnum final : public IDataTypeEnum { const auto it = value_to_name_map.find(value); if (it == std::end(value_to_name_map)) -<<<<<<< HEAD - throw Exception{"Unexpected value " + toString(value) + " for type " + getName(), ErrorCodes::LOGICAL_ERROR}; -======= { if (!value) return {}; - - throw Exception{ - "Unexpected value " + toString(value) + " for type " + getName(), - ErrorCodes::LOGICAL_ERROR}; + throw Exception{"Unexpected value " + toString(value) + " for type " + getName(), ErrorCodes::LOGICAL_ERROR}; } ->>>>>>> 6212eb1e53 (Support enum with index 0 (#8533)) return it->second; } From 13a84443ea4e0fc6ea000b71a7a7d5b9c272ff69 Mon Sep 17 00:00:00 2001 From: "TONG, Zhigao" Date: Mon, 18 Dec 2023 17:49:20 +0800 Subject: [PATCH 3/3] Update ArrowColCodec.cpp --- dbms/src/Flash/Coprocessor/ArrowColCodec.cpp | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/dbms/src/Flash/Coprocessor/ArrowColCodec.cpp b/dbms/src/Flash/Coprocessor/ArrowColCodec.cpp index 625307f6aa5..b79b46db566 100644 --- a/dbms/src/Flash/Coprocessor/ArrowColCodec.cpp +++ b/dbms/src/Flash/Coprocessor/ArrowColCodec.cpp @@ -280,24 +280,10 @@ void flashEnumColToArrowCol( continue; } } -<<<<<<< HEAD auto enum_value = (UInt64)flash_col->getElement(i); - if (enum_value == 0 || enum_value > enum_value_size) + if (enum_value > enum_value_size) throw TiFlashException("number of enum overflow enum boundary", Errors::Coprocessor::Internal); TiDBEnum ti_enum(enum_value, enum_type->getNameForValue((const DataTypeEnum16::FieldType)enum_value)); -======= - auto enum_value = static_cast(flash_col->getElement(i)); - if (enum_value > enum_value_size) - throw TiFlashException( - Errors::Coprocessor::Internal, - "number of enum value {} overflow enum boundary {}", - enum_value, - enum_value_size); - - TiDBEnum ti_enum( - enum_value, - enum_type->getNameForValue(static_cast(enum_value))); ->>>>>>> 6212eb1e53 (Support enum with index 0 (#8533)) dag_column.append(ti_enum); } }