This commit is contained in:
Yakov Olkhovskiy 2024-12-16 23:08:12 +00:00
parent 7adfc52353
commit d93ad92aeb
2 changed files with 38 additions and 7 deletions

View File

@ -21,9 +21,10 @@
using namespace DB;
template <typename T>
void checkColumn(
void checkColumnImpl(
const WeakHash32::Container & hash,
const PaddedPODArray<T> & eq_class)
const PaddedPODArray<T> & eq_class,
UInt32 scale = 0)
{
ASSERT_EQ(hash.size(), eq_class.size());
@ -41,7 +42,12 @@ void checkColumn(
else
{
if (it->second != hash[i])
std::cout << "Different hashes for the same equivalent class (" << toString(val) << ")\n";
{
if constexpr (is_decimal<T>)
std::cout << "Different hashes for the same equivalent class (" << toString(val, scale) << ")\n";
else
std::cout << "Different hashes for the same equivalent class (" << toString(val) << ")\n";
}
ASSERT_EQ(it->second, hash[i]);
}
@ -49,6 +55,23 @@ void checkColumn(
}
}
template <typename T>
void checkColumn(
const WeakHash32::Container & hash,
const PaddedPODArray<T> & eq_class)
{
checkColumnImpl(hash, eq_class);
}
template <is_decimal T>
void checkColumn(
const WeakHash32::Container & hash,
const PaddedPODArray<T> & eq_class,
UInt32 scale)
{
checkColumnImpl(hash, eq_class, scale);
}
TEST(WeakHash32, ColumnVectorU8)
{
auto col = ColumnUInt8::create();
@ -230,7 +253,7 @@ TEST(WeakHash32, ColumnDecimal32)
WeakHash32 hash = col->getWeakHash32();
checkColumn(hash.getData(), col->getData());
checkColumn(hash.getData(), col->getData(), col->getScale());
}
TEST(WeakHash32, ColumnDecimal64)
@ -246,7 +269,7 @@ TEST(WeakHash32, ColumnDecimal64)
WeakHash32 hash = col->getWeakHash32();
checkColumn(hash.getData(), col->getData());
checkColumn(hash.getData(), col->getData(), col->getScale());
}
TEST(WeakHash32, ColumnDecimal128)
@ -262,7 +285,7 @@ TEST(WeakHash32, ColumnDecimal128)
WeakHash32 hash = col->getWeakHash32();
checkColumn(hash.getData(), col->getData());
checkColumn(hash.getData(), col->getData(), col->getScale());
}
TEST(WeakHash32, ColumnString1)

View File

@ -1143,7 +1143,7 @@ void writeDecimalFractional(const T & x, UInt32 scale, WriteBuffer & ostr, bool
}
template <typename T>
void writeText(Decimal<T> x, UInt32 scale, WriteBuffer & ostr, bool trailing_zeros,
void writeText(Decimal<T> x, UInt32 scale, WriteBuffer & ostr, bool trailing_zeros = false,
bool fixed_fractional_length = false, UInt32 fractional_length = 0)
{
T part = DecimalUtils::getWholePart(x, scale);
@ -1327,6 +1327,14 @@ inline String toString(const T & x)
return buf.str();
}
template <is_decimal T>
inline String toString(const T & x, UInt32 scale)
{
WriteBufferFromOwnString buf;
writeText(x, scale, buf);
return buf.str();
}
inline String toString(const CityHash_v1_0_2::uint128 & hash)
{
WriteBufferFromOwnString buf;