forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split ComplexKeyCacheDictionary to faster compile (part2)
- Loading branch information
1 parent
86a587e
commit 82134e4
Showing
4 changed files
with
157 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
dbms/src/Dictionaries/ComplexKeyCacheDictionary_createAttributeWithType.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include <Dictionaries/ComplexKeyCacheDictionary.h> | ||
|
||
namespace DB | ||
{ | ||
|
||
ComplexKeyCacheDictionary::Attribute ComplexKeyCacheDictionary::createAttributeWithType(const AttributeUnderlyingType type, const Field & null_value) | ||
{ | ||
Attribute attr{type}; | ||
|
||
switch (type) | ||
{ | ||
case AttributeUnderlyingType::UInt8: | ||
std::get<UInt8>(attr.null_values) = null_value.get<UInt64>(); | ||
std::get<ContainerPtrType<UInt8>>(attr.arrays) = std::make_unique<ContainerType<UInt8>>(size); | ||
bytes_allocated += size * sizeof(UInt8); | ||
break; | ||
case AttributeUnderlyingType::UInt16: | ||
std::get<UInt16>(attr.null_values) = null_value.get<UInt64>(); | ||
std::get<ContainerPtrType<UInt16>>(attr.arrays) = std::make_unique<ContainerType<UInt16>>(size); | ||
bytes_allocated += size * sizeof(UInt16); | ||
break; | ||
case AttributeUnderlyingType::UInt32: | ||
std::get<UInt32>(attr.null_values) = null_value.get<UInt64>(); | ||
std::get<ContainerPtrType<UInt32>>(attr.arrays) = std::make_unique<ContainerType<UInt32>>(size); | ||
bytes_allocated += size * sizeof(UInt32); | ||
break; | ||
case AttributeUnderlyingType::UInt64: | ||
std::get<UInt64>(attr.null_values) = null_value.get<UInt64>(); | ||
std::get<ContainerPtrType<UInt64>>(attr.arrays) = std::make_unique<ContainerType<UInt64>>(size); | ||
bytes_allocated += size * sizeof(UInt64); | ||
break; | ||
case AttributeUnderlyingType::Int8: | ||
std::get<Int8>(attr.null_values) = null_value.get<Int64>(); | ||
std::get<ContainerPtrType<Int8>>(attr.arrays) = std::make_unique<ContainerType<Int8>>(size); | ||
bytes_allocated += size * sizeof(Int8); | ||
break; | ||
case AttributeUnderlyingType::Int16: | ||
std::get<Int16>(attr.null_values) = null_value.get<Int64>(); | ||
std::get<ContainerPtrType<Int16>>(attr.arrays) = std::make_unique<ContainerType<Int16>>(size); | ||
bytes_allocated += size * sizeof(Int16); | ||
break; | ||
case AttributeUnderlyingType::Int32: | ||
std::get<Int32>(attr.null_values) = null_value.get<Int64>(); | ||
std::get<ContainerPtrType<Int32>>(attr.arrays) = std::make_unique<ContainerType<Int32>>(size); | ||
bytes_allocated += size * sizeof(Int32); | ||
break; | ||
case AttributeUnderlyingType::Int64: | ||
std::get<Int64>(attr.null_values) = null_value.get<Int64>(); | ||
std::get<ContainerPtrType<Int64>>(attr.arrays) = std::make_unique<ContainerType<Int64>>(size); | ||
bytes_allocated += size * sizeof(Int64); | ||
break; | ||
case AttributeUnderlyingType::Float32: | ||
std::get<Float32>(attr.null_values) = null_value.get<Float64>(); | ||
std::get<ContainerPtrType<Float32>>(attr.arrays) = std::make_unique<ContainerType<Float32>>(size); | ||
bytes_allocated += size * sizeof(Float32); | ||
break; | ||
case AttributeUnderlyingType::Float64: | ||
std::get<Float64>(attr.null_values) = null_value.get<Float64>(); | ||
std::get<ContainerPtrType<Float64>>(attr.arrays) = std::make_unique<ContainerType<Float64>>(size); | ||
bytes_allocated += size * sizeof(Float64); | ||
break; | ||
case AttributeUnderlyingType::String: | ||
std::get<String>(attr.null_values) = null_value.get<String>(); | ||
std::get<ContainerPtrType<StringRef>>(attr.arrays) = std::make_unique<ContainerType<StringRef>>(size); | ||
bytes_allocated += size * sizeof(StringRef); | ||
if (!string_arena) | ||
string_arena = std::make_unique<ArenaWithFreeLists>(); | ||
break; | ||
} | ||
|
||
return attr; | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
dbms/src/Dictionaries/ComplexKeyCacheDictionary_setAttributeValue.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <Dictionaries/ComplexKeyCacheDictionary.h> | ||
|
||
namespace DB | ||
{ | ||
|
||
void ComplexKeyCacheDictionary::setAttributeValue(Attribute & attribute, const size_t idx, const Field & value) const | ||
{ | ||
switch (attribute.type) | ||
{ | ||
case AttributeUnderlyingType::UInt8: std::get<ContainerPtrType<UInt8>>(attribute.arrays)[idx] = value.get<UInt64>(); break; | ||
case AttributeUnderlyingType::UInt16: std::get<ContainerPtrType<UInt16>>(attribute.arrays)[idx] = value.get<UInt64>(); break; | ||
case AttributeUnderlyingType::UInt32: std::get<ContainerPtrType<UInt32>>(attribute.arrays)[idx] = value.get<UInt64>(); break; | ||
case AttributeUnderlyingType::UInt64: std::get<ContainerPtrType<UInt64>>(attribute.arrays)[idx] = value.get<UInt64>(); break; | ||
case AttributeUnderlyingType::Int8: std::get<ContainerPtrType<Int8>>(attribute.arrays)[idx] = value.get<Int64>(); break; | ||
case AttributeUnderlyingType::Int16: std::get<ContainerPtrType<Int16>>(attribute.arrays)[idx] = value.get<Int64>(); break; | ||
case AttributeUnderlyingType::Int32: std::get<ContainerPtrType<Int32>>(attribute.arrays)[idx] = value.get<Int64>(); break; | ||
case AttributeUnderlyingType::Int64: std::get<ContainerPtrType<Int64>>(attribute.arrays)[idx] = value.get<Int64>(); break; | ||
case AttributeUnderlyingType::Float32: std::get<ContainerPtrType<Float32>>(attribute.arrays)[idx] = value.get<Float64>(); break; | ||
case AttributeUnderlyingType::Float64: std::get<ContainerPtrType<Float64>>(attribute.arrays)[idx] = value.get<Float64>(); break; | ||
case AttributeUnderlyingType::String: | ||
{ | ||
const auto & string = value.get<String>(); | ||
auto & string_ref = std::get<ContainerPtrType<StringRef>>(attribute.arrays)[idx]; | ||
const auto & null_value_ref = std::get<String>(attribute.null_values); | ||
|
||
/// free memory unless it points to a null_value | ||
if (string_ref.data && string_ref.data != null_value_ref.data()) | ||
string_arena->free(const_cast<char *>(string_ref.data), string_ref.size); | ||
|
||
const auto size = string.size(); | ||
if (size != 0) | ||
{ | ||
auto string_ptr = string_arena->alloc(size + 1); | ||
std::copy(string.data(), string.data() + size + 1, string_ptr); | ||
string_ref = StringRef{string_ptr, size}; | ||
} | ||
else | ||
string_ref = {}; | ||
|
||
break; | ||
} | ||
} | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
dbms/src/Dictionaries/ComplexKeyCacheDictionary_setDefaultAttributeValue.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <Dictionaries/ComplexKeyCacheDictionary.h> | ||
|
||
namespace DB | ||
{ | ||
|
||
void ComplexKeyCacheDictionary::setDefaultAttributeValue(Attribute & attribute, const size_t idx) const | ||
{ | ||
switch (attribute.type) | ||
{ | ||
case AttributeUnderlyingType::UInt8: std::get<ContainerPtrType<UInt8>>(attribute.arrays)[idx] = std::get<UInt8>(attribute.null_values); break; | ||
case AttributeUnderlyingType::UInt16: std::get<ContainerPtrType<UInt16>>(attribute.arrays)[idx] = std::get<UInt16>(attribute.null_values); break; | ||
case AttributeUnderlyingType::UInt32: std::get<ContainerPtrType<UInt32>>(attribute.arrays)[idx] = std::get<UInt32>(attribute.null_values); break; | ||
case AttributeUnderlyingType::UInt64: std::get<ContainerPtrType<UInt64>>(attribute.arrays)[idx] = std::get<UInt64>(attribute.null_values); break; | ||
case AttributeUnderlyingType::Int8: std::get<ContainerPtrType<Int8>>(attribute.arrays)[idx] = std::get<Int8>(attribute.null_values); break; | ||
case AttributeUnderlyingType::Int16: std::get<ContainerPtrType<Int16>>(attribute.arrays)[idx] = std::get<Int16>(attribute.null_values); break; | ||
case AttributeUnderlyingType::Int32: std::get<ContainerPtrType<Int32>>(attribute.arrays)[idx] = std::get<Int32>(attribute.null_values); break; | ||
case AttributeUnderlyingType::Int64: std::get<ContainerPtrType<Int64>>(attribute.arrays)[idx] = std::get<Int64>(attribute.null_values); break; | ||
case AttributeUnderlyingType::Float32: std::get<ContainerPtrType<Float32>>(attribute.arrays)[idx] = std::get<Float32>(attribute.null_values); break; | ||
case AttributeUnderlyingType::Float64: std::get<ContainerPtrType<Float64>>(attribute.arrays)[idx] = std::get<Float64>(attribute.null_values); break; | ||
case AttributeUnderlyingType::String: | ||
{ | ||
const auto & null_value_ref = std::get<String>(attribute.null_values); | ||
auto & string_ref = std::get<ContainerPtrType<StringRef>>(attribute.arrays)[idx]; | ||
|
||
if (string_ref.data != null_value_ref.data()) | ||
{ | ||
if (string_ref.data) | ||
string_arena->free(const_cast<char *>(string_ref.data), string_ref.size); | ||
|
||
string_ref = StringRef{null_value_ref}; | ||
} | ||
|
||
break; | ||
} | ||
} | ||
} | ||
|
||
} |