Attempt to normalize big integers

This commit is contained in:
Alexey Milovidov 2021-04-25 13:02:19 +03:00
parent 76a5d023e0
commit 9eb60086b0
3 changed files with 21 additions and 14 deletions

View File

@ -251,7 +251,9 @@ TEST(WeakHash32, ColumnVectorU128)
{ {
for (uint64_t i = 0; i < 65536; ++i) for (uint64_t i = 0; i < 65536; ++i)
{ {
UInt128 val(i << 32u, i << 32u); UInt128 val;
val.items[0] = i << 32u;
val.items[1] = i << 32u;
data.push_back(val); data.push_back(val);
eq_data.push_back(i); eq_data.push_back(i);
} }
@ -328,7 +330,7 @@ TEST(WeakHash32, ColumnDecimal128)
WeakHash32 hash(col->size()); WeakHash32 hash(col->size());
col->updateWeakHash32(hash); col->updateWeakHash32(hash);
checkColumn(hash.getData(), col->getData(), [&](size_t row) { return std::to_string(Int64(col->getElement(row))); }); checkColumn(hash.getData(), col->getData(), [&](size_t row) { return std::to_string(Int128(col->getElement(row).value)); });
} }
TEST(WeakHash32, ColumnString1) TEST(WeakHash32, ColumnString1)

View File

@ -5,11 +5,16 @@
#include <Common/HashTable/HashMap.h> #include <Common/HashTable/HashMap.h>
#include <Common/HashTable/HashSet.h> #include <Common/HashTable/HashSet.h>
#include <Common/HashTable/Hash.h>
#include <IO/ReadBufferFromString.h> #include <IO/ReadBufferFromString.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
using namespace DB;
/// To test dump functionality without using other hashes that can change /// To test dump functionality without using other hashes that can change
template <typename T> template <typename T>
struct DummyHash struct DummyHash
@ -251,14 +256,14 @@ TEST(HashTable, SerializationDeserialization)
cont.insert(2); cont.insert(2);
cont.insert(3); cont.insert(3);
DB::WriteBufferFromOwnString wb; WriteBufferFromOwnString wb;
cont.writeText(wb); cont.writeText(wb);
std::string expected = "3,1,2,3"; std::string expected = "3,1,2,3";
ASSERT_EQ(wb.str(), expected); ASSERT_EQ(wb.str(), expected);
DB::ReadBufferFromString rb(expected); ReadBufferFromString rb(expected);
Cont deserialized; Cont deserialized;
deserialized.readText(rb); deserialized.readText(rb);
@ -273,10 +278,10 @@ TEST(HashTable, SerializationDeserialization)
cont.insert(2); cont.insert(2);
cont.insert(3); cont.insert(3);
DB::WriteBufferFromOwnString wb; WriteBufferFromOwnString wb;
cont.write(wb); cont.write(wb);
DB::ReadBufferFromString rb(wb.str()); ReadBufferFromString rb(wb.str());
Cont deserialized; Cont deserialized;
deserialized.read(rb); deserialized.read(rb);
@ -286,23 +291,23 @@ TEST(HashTable, SerializationDeserialization)
using Cont = HashSet<int, DummyHash<int>, HashTableGrower<1>>; using Cont = HashSet<int, DummyHash<int>, HashTableGrower<1>>;
Cont cont; Cont cont;
DB::WriteBufferFromOwnString wb; WriteBufferFromOwnString wb;
cont.writeText(wb); cont.writeText(wb);
std::string expected = "0"; std::string expected = "0";
ASSERT_EQ(wb.str(), expected); ASSERT_EQ(wb.str(), expected);
DB::ReadBufferFromString rb(expected); ReadBufferFromString rb(expected);
Cont deserialized; Cont deserialized;
deserialized.readText(rb); deserialized.readText(rb);
ASSERT_EQ(convertToSet(cont), convertToSet(deserialized)); ASSERT_EQ(convertToSet(cont), convertToSet(deserialized));
} }
{ {
using Cont = HashSet<DB::UInt128, DB::UInt128TrivialHash>; using Cont = HashSet<UInt128, UInt128TrivialHash>;
Cont cont; Cont cont;
DB::WriteBufferFromOwnString wb; WriteBufferFromOwnString wb;
cont.write(wb); cont.write(wb);
std::string expected; std::string expected;
@ -310,7 +315,7 @@ TEST(HashTable, SerializationDeserialization)
ASSERT_EQ(wb.str(), expected); ASSERT_EQ(wb.str(), expected);
DB::ReadBufferFromString rb(expected); ReadBufferFromString rb(expected);
Cont deserialized; Cont deserialized;
deserialized.read(rb); deserialized.read(rb);

View File

@ -248,7 +248,7 @@ INSTANTIATE_TEST_SUITE_P(Merge, ReplicatedMergeTreeLogEntryDataTest,
.new_part_type = MergeTreeDataPartType::WIDE, .new_part_type = MergeTreeDataPartType::WIDE,
// Format version 5 // Format version 5
.new_part_uuid = UUID(UInt128(123456789, 10111213141516)), .new_part_uuid = UUID(UInt128(std::initializer_list<UInt64>{123456789, 10111213141516})),
.create_time = 123, .create_time = 123,
}, },
@ -273,7 +273,7 @@ INSTANTIATE_TEST_SUITE_P(Merge, ReplicatedMergeTreeLogEntryDataTest,
.new_part_type = MergeTreeDataPartType::WIDE, .new_part_type = MergeTreeDataPartType::WIDE,
// Mixing features // Mixing features
.new_part_uuid = UUID(UInt128(123456789, 10111213141516)), .new_part_uuid = UUID(UInt128(std::initializer_list<UInt64>{123456789, 10111213141516})),
.deduplicate = true, .deduplicate = true,
.deduplicate_by_columns = {"foo", "bar", "qux"}, .deduplicate_by_columns = {"foo", "bar", "qux"},
@ -288,7 +288,7 @@ INSTANTIATE_TEST_SUITE_P(Merge, ReplicatedMergeTreeLogEntryDataTest,
.new_part_type = MergeTreeDataPartType::WIDE, .new_part_type = MergeTreeDataPartType::WIDE,
// Mixing features // Mixing features
.new_part_uuid = UUID(UInt128(123456789, 10111213141516)), .new_part_uuid = UUID(UInt128(std::initializer_list<UInt64>{123456789, 10111213141516})),
.deduplicate = true, .deduplicate = true,
.deduplicate_by_columns = {"name with space", "\"column\"", "'column'", "колонка", "\u30ab\u30e9\u30e0", "\x01\x03 column \x10\x11\x12"}, .deduplicate_by_columns = {"name with space", "\"column\"", "'column'", "колонка", "\u30ab\u30e9\u30e0", "\x01\x03 column \x10\x11\x12"},