From d93ad92aebd50d24a5f87d04ab7485ada49aeba0 Mon Sep 17 00:00:00 2001 From: Yakov Olkhovskiy Date: Mon, 16 Dec 2024 23:08:12 +0000 Subject: [PATCH] fix test --- src/Columns/tests/gtest_weak_hash_32.cpp | 35 ++++++++++++++++++++---- src/IO/WriteHelpers.h | 10 ++++++- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/Columns/tests/gtest_weak_hash_32.cpp b/src/Columns/tests/gtest_weak_hash_32.cpp index 3143d0ff83c..879ef0900ce 100644 --- a/src/Columns/tests/gtest_weak_hash_32.cpp +++ b/src/Columns/tests/gtest_weak_hash_32.cpp @@ -21,9 +21,10 @@ using namespace DB; template -void checkColumn( +void checkColumnImpl( const WeakHash32::Container & hash, - const PaddedPODArray & eq_class) + const PaddedPODArray & 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) + 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 +void checkColumn( + const WeakHash32::Container & hash, + const PaddedPODArray & eq_class) +{ + checkColumnImpl(hash, eq_class); +} + +template +void checkColumn( + const WeakHash32::Container & hash, + const PaddedPODArray & 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) diff --git a/src/IO/WriteHelpers.h b/src/IO/WriteHelpers.h index 55c38eea141..55cb630739b 100644 --- a/src/IO/WriteHelpers.h +++ b/src/IO/WriteHelpers.h @@ -1143,7 +1143,7 @@ void writeDecimalFractional(const T & x, UInt32 scale, WriteBuffer & ostr, bool } template -void writeText(Decimal x, UInt32 scale, WriteBuffer & ostr, bool trailing_zeros, +void writeText(Decimal 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 +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;