1#include "ComplexKeyCacheDictionary.h"
2
3namespace DB
4{
5void ComplexKeyCacheDictionary::setAttributeValue(Attribute & attribute, const size_t idx, const Field & value) const
6{
7 switch (attribute.type)
8 {
9 case AttributeUnderlyingType::utUInt8:
10 std::get<ContainerPtrType<UInt8>>(attribute.arrays)[idx] = value.get<UInt64>();
11 break;
12 case AttributeUnderlyingType::utUInt16:
13 std::get<ContainerPtrType<UInt16>>(attribute.arrays)[idx] = value.get<UInt64>();
14 break;
15 case AttributeUnderlyingType::utUInt32:
16 std::get<ContainerPtrType<UInt32>>(attribute.arrays)[idx] = value.get<UInt64>();
17 break;
18 case AttributeUnderlyingType::utUInt64:
19 std::get<ContainerPtrType<UInt64>>(attribute.arrays)[idx] = value.get<UInt64>();
20 break;
21 case AttributeUnderlyingType::utUInt128:
22 std::get<ContainerPtrType<UInt128>>(attribute.arrays)[idx] = value.get<UInt128>();
23 break;
24 case AttributeUnderlyingType::utInt8:
25 std::get<ContainerPtrType<Int8>>(attribute.arrays)[idx] = value.get<Int64>();
26 break;
27 case AttributeUnderlyingType::utInt16:
28 std::get<ContainerPtrType<Int16>>(attribute.arrays)[idx] = value.get<Int64>();
29 break;
30 case AttributeUnderlyingType::utInt32:
31 std::get<ContainerPtrType<Int32>>(attribute.arrays)[idx] = value.get<Int64>();
32 break;
33 case AttributeUnderlyingType::utInt64:
34 std::get<ContainerPtrType<Int64>>(attribute.arrays)[idx] = value.get<Int64>();
35 break;
36 case AttributeUnderlyingType::utFloat32:
37 std::get<ContainerPtrType<Float32>>(attribute.arrays)[idx] = value.get<Float64>();
38 break;
39 case AttributeUnderlyingType::utFloat64:
40 std::get<ContainerPtrType<Float64>>(attribute.arrays)[idx] = value.get<Float64>();
41 break;
42
43 case AttributeUnderlyingType::utDecimal32:
44 std::get<ContainerPtrType<Decimal32>>(attribute.arrays)[idx] = value.get<Decimal32>();
45 break;
46 case AttributeUnderlyingType::utDecimal64:
47 std::get<ContainerPtrType<Decimal64>>(attribute.arrays)[idx] = value.get<Decimal64>();
48 break;
49 case AttributeUnderlyingType::utDecimal128:
50 std::get<ContainerPtrType<Decimal128>>(attribute.arrays)[idx] = value.get<Decimal128>();
51 break;
52
53 case AttributeUnderlyingType::utString:
54 {
55 const auto & string = value.get<String>();
56 auto & string_ref = std::get<ContainerPtrType<StringRef>>(attribute.arrays)[idx];
57 const auto & null_value_ref = std::get<String>(attribute.null_values);
58
59 /// free memory unless it points to a null_value
60 if (string_ref.data && string_ref.data != null_value_ref.data())
61 string_arena->free(const_cast<char *>(string_ref.data), string_ref.size);
62
63 const auto str_size = string.size();
64 if (str_size != 0)
65 {
66 auto str_ptr = string_arena->alloc(str_size);
67 std::copy(string.data(), string.data() + str_size, str_ptr);
68 string_ref = StringRef{str_ptr, str_size};
69 }
70 else
71 string_ref = {};
72
73 break;
74 }
75 }
76}
77
78}
79