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

Fix an invalid default value cause bootstrap failed #4916

Merged
merged 12 commits into from
May 27, 2022
19 changes: 17 additions & 2 deletions dbms/src/Storages/Transaction/TiDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <Storages/Transaction/Collator.h>
#include <Storages/Transaction/SchemaNameMapper.h>
#include <Storages/Transaction/TiDB.h>
#include <cmath>

namespace DB
{
Expand Down Expand Up @@ -110,14 +111,28 @@ Field ColumnInfo::defaultValueToField() const
}
switch (tp)
{
// TODO: Consider unsigned?
JaySon-Huang marked this conversation as resolved.
Show resolved Hide resolved
// Integer Type.
case TypeTiny:
case TypeShort:
case TypeLong:
case TypeLongLong:
case TypeInt24:
return value.convert<Int64>();
{
// In c++, cast a unsigned integer to signed integer will not change the value.
// like 9223372036854775808 which is larger than the maximum value of Int64,
// static_cast<UInt64>(static_cast<Int64>(9223372036854775808)) == 9223372036854775808
// so we don't need consider unsigned here.
try
{
return value.convert<Int64>();
}
catch (...)
{
// due to https://github.com/pingcap/tidb/issues/34881
// we do this to avoid exception in older version of TiDB.
return static_cast<Int64>(std::llround(value.convert<double>()));
}
}
case TypeBit:
{
// TODO: We shall use something like `orig_default_bit`, which will never change once created,
Expand Down