Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#4916
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
Lloyd-Pottiger authored and ti-chi-bot committed Jul 11, 2022
1 parent 26557c2 commit 6c22b5f
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions dbms/src/Storages/Transaction/TiDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <Storages/Transaction/SchemaNameMapper.h>
#include <Storages/Transaction/TiDB.h>

#include <cmath>

namespace DB
{
extern const UInt8 TYPE_CODE_LITERAL;
Expand Down Expand Up @@ -45,6 +47,7 @@ Field ColumnInfo::defaultValueToField() const
}
switch (tp)
{
<<<<<<< HEAD
// TODO: Consider unsigned?
// Integer Type.
case TypeTiny:
Expand All @@ -54,6 +57,41 @@ Field ColumnInfo::defaultValueToField() const
case TypeInt24:
return value.convert<Int64>();
case TypeBit:
=======
// Integer Type.
case TypeTiny:
case TypeShort:
case TypeLong:
case TypeLongLong:
case TypeInt24:
{
// 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,
// rather than `default_bit`, which could be altered.
// See https://github.com/pingcap/tidb/issues/17641 and https://github.com/pingcap/tidb/issues/17642
const auto & bit_value = default_bit_value;
// TODO: There might be cases that `orig_default` is not null but `default_bit` is null,
// i.e. bit column added with an default value but later modified to another.
// For these cases, neither `orig_default` (may get corrupted) nor `default_bit` (modified) is correct.
// This is a bug anyway, we choose to make it simple, i.e. use `default_bit`.
if (bit_value.isEmpty())
>>>>>>> ca3e1c6be8 (Fix an invalid default value cause bootstrap failed (#4916))
{
// TODO: We shall use something like `orig_default_bit`, which will never change once created,
// rather than `default_bit`, which could be altered.
Expand Down Expand Up @@ -531,7 +569,16 @@ catch (const Poco::Exception & e)
/// IndexColumnInfo ///
///////////////////////

<<<<<<< HEAD
IndexColumnInfo::IndexColumnInfo(Poco::JSON::Object::Ptr json) { deserialize(json); }
=======
IndexColumnInfo::IndexColumnInfo(Poco::JSON::Object::Ptr json)
: offset()
, length()
{
deserialize(json);
}
>>>>>>> ca3e1c6be8 (Fix an invalid default value cause bootstrap failed (#4916))

Poco::JSON::Object::Ptr IndexColumnInfo::getJSONObject() const
try
Expand Down Expand Up @@ -575,7 +622,21 @@ catch (const Poco::Exception & e)
////// IndexInfo //////
///////////////////////

<<<<<<< HEAD
IndexInfo::IndexInfo(Poco::JSON::Object::Ptr json) { deserialize(json); }
=======
IndexInfo::IndexInfo(Poco::JSON::Object::Ptr json)
: id()
, state()
, index_type()
, is_unique()
, is_primary()
, is_invisible()
, is_global()
{
deserialize(json);
}
>>>>>>> ca3e1c6be8 (Fix an invalid default value cause bootstrap failed (#4916))
Poco::JSON::Object::Ptr IndexInfo::getJSONObject() const
try
{
Expand Down

0 comments on commit 6c22b5f

Please sign in to comment.