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

quick fix for decimal encode #210

Merged
merged 3 commits into from
Aug 30, 2019
Merged
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
9 changes: 9 additions & 0 deletions dbms/src/Storages/Transaction/Codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,15 @@ void EncodeDecimalImpl(const T & dec, PrecType prec, ScaleType frac, std::string
{
static_assert(IsDecimal<T>);

// Scale must (if not, then we have bugs) be the same as TiDB expected, but precision will be
// trimmed to as minimal as possible by TiFlash decimal implementation. TiDB doesn't allow
// decimal with precision less than scale, therefore in theory we should align value's precision
// according to data type. But TiDB somehow happens to allow precision not equal to data type,
// of which we take advantage to make such a handy fix.
if (prec < frac)
{
prec = frac;
}
constexpr Int32 decimal_mod = powers10[digitsPerWord];
ss << UInt8(prec) << UInt8(frac);

Expand Down