Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support enum with index 0 (#8533) #8548

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion dbms/src/DataTypes/DataTypeEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ 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))
{
if (!value)
return {};
throw Exception{"Unexpected value " + toString(value) + " for type " + getName(), ErrorCodes::LOGICAL_ERROR};
}

return it->second;
}
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Flash/Coprocessor/ArrowColCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void flashEnumColToArrowCol(
}
}
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);
const auto & enum_name = enum_type->getNameForValue(static_cast<const DataTypeEnum16::FieldType>(enum_value));
TiDBEnum ti_enum(enum_value, enum_name);
Expand Down
24 changes: 24 additions & 0 deletions tests/fullstack-test2/ddl/alter_column_enum.test
Original file line number Diff line number Diff line change
Expand Up @@ -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