mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-22 09:40:49 +00:00
add normal parent
This commit is contained in:
parent
0d1a8ea2a1
commit
02b2b38716
@ -130,7 +130,7 @@ void CacheDictionary::toParent(const PaddedPODArray<Key> & ids, PaddedPODArray<K
|
||||
{
|
||||
const auto null_value = std::get<UInt64>(hierarchical_attribute->null_values);
|
||||
|
||||
getItemsNumberImpl<UInt64, UInt64>("anime", *hierarchical_attribute, ids, out, [&](const size_t) { return null_value; });
|
||||
getItemsNumberImpl<UInt64, UInt64>(*hierarchical_attribute, ids, out, [&](const size_t) { return null_value; });
|
||||
}
|
||||
|
||||
|
||||
@ -255,7 +255,7 @@ void CacheDictionary::getString(const std::string & attribute_name, const Padded
|
||||
|
||||
const auto null_value = StringRef{std::get<String>(attribute.null_values)};
|
||||
|
||||
getItemsString(attribute_name, attribute, ids, out, [&](const size_t) { return null_value; });
|
||||
getItemsString(attribute, ids, out, [&](const size_t) { return null_value; });
|
||||
}
|
||||
|
||||
void CacheDictionary::getString(
|
||||
@ -264,7 +264,7 @@ void CacheDictionary::getString(
|
||||
auto & attribute = getAttribute(attribute_name);
|
||||
checkAttributeType(this, attribute_name, attribute.type, AttributeUnderlyingType::utString);
|
||||
|
||||
getItemsString(attribute_name, attribute, ids, out, [&](const size_t row) { return def->getDataAt(row); });
|
||||
getItemsString(attribute, ids, out, [&](const size_t row) { return def->getDataAt(row); });
|
||||
}
|
||||
|
||||
void CacheDictionary::getString(
|
||||
@ -273,7 +273,7 @@ void CacheDictionary::getString(
|
||||
auto & attribute = getAttribute(attribute_name);
|
||||
checkAttributeType(this, attribute_name, attribute.type, AttributeUnderlyingType::utString);
|
||||
|
||||
getItemsString(attribute_name, attribute, ids, out, [&](const size_t) { return StringRef{def}; });
|
||||
getItemsString(attribute, ids, out, [&](const size_t) { return StringRef{def}; });
|
||||
}
|
||||
|
||||
template<class... Ts>
|
||||
@ -489,7 +489,7 @@ void CacheDictionary::createAttributes()
|
||||
for (const auto & attribute : dict_struct.attributes)
|
||||
{
|
||||
attribute_index_by_name.emplace(attribute.name, attributes.size());
|
||||
attributes.push_back(createAttributeWithType(attribute.underlying_type, attribute.null_value));
|
||||
attributes.push_back(createAttributeWithTypeAndName(attribute.underlying_type, attribute.name, attribute.null_value));
|
||||
|
||||
if (attribute.hierarchical)
|
||||
{
|
||||
@ -501,9 +501,9 @@ void CacheDictionary::createAttributes()
|
||||
}
|
||||
}
|
||||
|
||||
CacheDictionary::Attribute CacheDictionary::createAttributeWithType(const AttributeUnderlyingType type, const Field & null_value)
|
||||
CacheDictionary::Attribute CacheDictionary::createAttributeWithTypeAndName(const AttributeUnderlyingType type, const String & name, const Field & null_value)
|
||||
{
|
||||
Attribute attr{type, {}, {}};
|
||||
Attribute attr{type, name, {}, {}};
|
||||
|
||||
switch (type)
|
||||
{
|
||||
@ -544,50 +544,25 @@ void CacheDictionary::setDefaultAttributeValue(Attribute & attribute, const Key
|
||||
{
|
||||
switch (attribute.type)
|
||||
{
|
||||
case AttributeUnderlyingType::utUInt8:
|
||||
std::get<ContainerPtrType<UInt8>>(attribute.arrays)[idx] = std::get<UInt8>(attribute.null_values);
|
||||
#define DISPATCH(TYPE) \
|
||||
case AttributeUnderlyingType::ut##TYPE: \
|
||||
std::get<ContainerPtrType<TYPE>>(attribute.arrays)[idx] = std::get<TYPE>(attribute.null_values); /* NOLINT */ \
|
||||
break;
|
||||
case AttributeUnderlyingType::utUInt16:
|
||||
std::get<ContainerPtrType<UInt16>>(attribute.arrays)[idx] = std::get<UInt16>(attribute.null_values);
|
||||
break;
|
||||
case AttributeUnderlyingType::utUInt32:
|
||||
std::get<ContainerPtrType<UInt32>>(attribute.arrays)[idx] = std::get<UInt32>(attribute.null_values);
|
||||
break;
|
||||
case AttributeUnderlyingType::utUInt64:
|
||||
std::get<ContainerPtrType<UInt64>>(attribute.arrays)[idx] = std::get<UInt64>(attribute.null_values);
|
||||
break;
|
||||
case AttributeUnderlyingType::utUInt128:
|
||||
std::get<ContainerPtrType<UInt128>>(attribute.arrays)[idx] = std::get<UInt128>(attribute.null_values);
|
||||
break;
|
||||
case AttributeUnderlyingType::utInt8:
|
||||
std::get<ContainerPtrType<Int8>>(attribute.arrays)[idx] = std::get<Int8>(attribute.null_values);
|
||||
break;
|
||||
case AttributeUnderlyingType::utInt16:
|
||||
std::get<ContainerPtrType<Int16>>(attribute.arrays)[idx] = std::get<Int16>(attribute.null_values);
|
||||
break;
|
||||
case AttributeUnderlyingType::utInt32:
|
||||
std::get<ContainerPtrType<Int32>>(attribute.arrays)[idx] = std::get<Int32>(attribute.null_values);
|
||||
break;
|
||||
case AttributeUnderlyingType::utInt64:
|
||||
std::get<ContainerPtrType<Int64>>(attribute.arrays)[idx] = std::get<Int64>(attribute.null_values);
|
||||
break;
|
||||
case AttributeUnderlyingType::utFloat32:
|
||||
std::get<ContainerPtrType<Float32>>(attribute.arrays)[idx] = std::get<Float32>(attribute.null_values);
|
||||
break;
|
||||
case AttributeUnderlyingType::utFloat64:
|
||||
std::get<ContainerPtrType<Float64>>(attribute.arrays)[idx] = std::get<Float64>(attribute.null_values);
|
||||
break;
|
||||
|
||||
case AttributeUnderlyingType::utDecimal32:
|
||||
std::get<ContainerPtrType<Decimal32>>(attribute.arrays)[idx] = std::get<Decimal32>(attribute.null_values);
|
||||
break;
|
||||
case AttributeUnderlyingType::utDecimal64:
|
||||
std::get<ContainerPtrType<Decimal64>>(attribute.arrays)[idx] = std::get<Decimal64>(attribute.null_values);
|
||||
break;
|
||||
case AttributeUnderlyingType::utDecimal128:
|
||||
std::get<ContainerPtrType<Decimal128>>(attribute.arrays)[idx] = std::get<Decimal128>(attribute.null_values);
|
||||
break;
|
||||
|
||||
DISPATCH(UInt8)
|
||||
DISPATCH(UInt16)
|
||||
DISPATCH(UInt32)
|
||||
DISPATCH(UInt64)
|
||||
DISPATCH(UInt128)
|
||||
DISPATCH(Int8)
|
||||
DISPATCH(Int16)
|
||||
DISPATCH(Int32)
|
||||
DISPATCH(Int64)
|
||||
DISPATCH(Decimal32)
|
||||
DISPATCH(Decimal64)
|
||||
DISPATCH(Decimal128)
|
||||
DISPATCH(Float32)
|
||||
DISPATCH(Float64)
|
||||
#undef DISPATCH
|
||||
case AttributeUnderlyingType::utString:
|
||||
{
|
||||
const auto & null_value_ref = std::get<String>(attribute.null_values);
|
||||
@ -611,37 +586,38 @@ void CacheDictionary::setAttributeValue(Attribute & attribute, const Key idx, co
|
||||
switch (attribute.type)
|
||||
{
|
||||
case AttributeUnderlyingType::utUInt8:
|
||||
std::get<ContainerPtrType<UInt8>>(attribute.arrays)[idx] = value.get<UInt64>();
|
||||
/// Strange code. Why UInt8 and UInt64? I looked through the history. It's always been like this.
|
||||
std::get<ContainerPtrType<UInt8>>(attribute.arrays)[idx] = value.safeGet<UInt64>();
|
||||
break;
|
||||
case AttributeUnderlyingType::utUInt16:
|
||||
std::get<ContainerPtrType<UInt16>>(attribute.arrays)[idx] = value.get<UInt64>();
|
||||
std::get<ContainerPtrType<UInt16>>(attribute.arrays)[idx] = value.safeGet<UInt64>();
|
||||
break;
|
||||
case AttributeUnderlyingType::utUInt32:
|
||||
std::get<ContainerPtrType<UInt32>>(attribute.arrays)[idx] = value.get<UInt64>();
|
||||
std::get<ContainerPtrType<UInt32>>(attribute.arrays)[idx] = value.safeGet<UInt64>();
|
||||
break;
|
||||
case AttributeUnderlyingType::utUInt64:
|
||||
std::get<ContainerPtrType<UInt64>>(attribute.arrays)[idx] = value.get<UInt64>();
|
||||
std::get<ContainerPtrType<UInt64>>(attribute.arrays)[idx] = value.safeGet<UInt64>();
|
||||
break;
|
||||
case AttributeUnderlyingType::utUInt128:
|
||||
std::get<ContainerPtrType<UInt128>>(attribute.arrays)[idx] = value.get<UInt128>();
|
||||
std::get<ContainerPtrType<UInt128>>(attribute.arrays)[idx] = value.safeGet<UInt128>();
|
||||
break;
|
||||
case AttributeUnderlyingType::utInt8:
|
||||
std::get<ContainerPtrType<Int8>>(attribute.arrays)[idx] = value.get<Int64>();
|
||||
std::get<ContainerPtrType<Int8>>(attribute.arrays)[idx] = value.safeGet<Int64>();
|
||||
break;
|
||||
case AttributeUnderlyingType::utInt16:
|
||||
std::get<ContainerPtrType<Int16>>(attribute.arrays)[idx] = value.get<Int64>();
|
||||
std::get<ContainerPtrType<Int16>>(attribute.arrays)[idx] = value.safeGet<Int64>();
|
||||
break;
|
||||
case AttributeUnderlyingType::utInt32:
|
||||
std::get<ContainerPtrType<Int32>>(attribute.arrays)[idx] = value.get<Int64>();
|
||||
std::get<ContainerPtrType<Int32>>(attribute.arrays)[idx] = value.safeGet<Int64>();
|
||||
break;
|
||||
case AttributeUnderlyingType::utInt64:
|
||||
std::get<ContainerPtrType<Int64>>(attribute.arrays)[idx] = value.get<Int64>();
|
||||
std::get<ContainerPtrType<Int64>>(attribute.arrays)[idx] = value.safeGet<Int64>();
|
||||
break;
|
||||
case AttributeUnderlyingType::utFloat32:
|
||||
std::get<ContainerPtrType<Float32>>(attribute.arrays)[idx] = value.get<Float64>();
|
||||
std::get<ContainerPtrType<Float32>>(attribute.arrays)[idx] = value.safeGet<Float64>();
|
||||
break;
|
||||
case AttributeUnderlyingType::utFloat64:
|
||||
std::get<ContainerPtrType<Float64>>(attribute.arrays)[idx] = value.get<Float64>();
|
||||
std::get<ContainerPtrType<Float64>>(attribute.arrays)[idx] = value.safeGet<Float64>();
|
||||
break;
|
||||
|
||||
case AttributeUnderlyingType::utDecimal32:
|
||||
|
@ -240,6 +240,7 @@ private:
|
||||
struct Attribute final
|
||||
{
|
||||
AttributeUnderlyingType type;
|
||||
String name;
|
||||
AttributeValue null_values;
|
||||
std::variant<
|
||||
ContainerPtrType<UInt8>,
|
||||
@ -262,14 +263,14 @@ private:
|
||||
|
||||
void createAttributes();
|
||||
|
||||
Attribute createAttributeWithType(const AttributeUnderlyingType type, const Field & null_value);
|
||||
Attribute createAttributeWithTypeAndName(const AttributeUnderlyingType type, const String & name, const Field & null_value);
|
||||
|
||||
template <typename AttributeType, typename OutputType, typename DefaultGetter>
|
||||
void getItemsNumberImpl(const std::string & attribute_name,
|
||||
void getItemsNumberImpl(
|
||||
Attribute & attribute, const PaddedPODArray<Key> & ids, ResultArrayType<OutputType> & out, DefaultGetter && get_default) const;
|
||||
|
||||
template <typename DefaultGetter>
|
||||
void getItemsString(const std::string & attribute_name, Attribute & attribute, const PaddedPODArray<Key> & ids, ColumnString * out, DefaultGetter && get_default) const;
|
||||
void getItemsString(Attribute & attribute, const PaddedPODArray<Key> & ids, ColumnString * out, DefaultGetter && get_default) const;
|
||||
|
||||
PaddedPODArray<Key> getCachedIds() const;
|
||||
|
||||
|
@ -36,7 +36,7 @@ namespace ErrorCodes
|
||||
}
|
||||
|
||||
template <typename AttributeType, typename OutputType, typename DefaultGetter>
|
||||
void CacheDictionary::getItemsNumberImpl(const std::string & attribute_name,
|
||||
void CacheDictionary::getItemsNumberImpl(
|
||||
Attribute & attribute, const PaddedPODArray<Key> & ids, ResultArrayType<OutputType> & out, DefaultGetter && get_default) const
|
||||
{
|
||||
/// First fill everything with default values
|
||||
@ -158,7 +158,7 @@ void CacheDictionary::getItemsNumberImpl(const std::string & attribute_name,
|
||||
|
||||
/// Add updated keys to asnwer.
|
||||
|
||||
const size_t attribute_index = getAttributeIndex(attribute_name);
|
||||
const size_t attribute_index = getAttributeIndex(attribute.name);
|
||||
|
||||
for (auto & [key, value] : update_unit_ptr->found_ids)
|
||||
{
|
||||
@ -171,7 +171,7 @@ void CacheDictionary::getItemsNumberImpl(const std::string & attribute_name,
|
||||
}
|
||||
|
||||
template <typename DefaultGetter>
|
||||
void CacheDictionary::getItemsString(const std::string & attribute_name,
|
||||
void CacheDictionary::getItemsString(
|
||||
Attribute & attribute, const PaddedPODArray<Key> & ids, ColumnString * out, DefaultGetter && get_default) const
|
||||
{
|
||||
const auto rows = ext::size(ids);
|
||||
@ -324,7 +324,7 @@ void CacheDictionary::getItemsString(const std::string & attribute_name,
|
||||
tryPushToUpdateQueueOrThrow(update_unit_ptr);
|
||||
waitForCurrentUpdateFinish(update_unit_ptr);
|
||||
|
||||
const size_t attribute_index = getAttributeIndex(attribute_name);
|
||||
const size_t attribute_index = getAttributeIndex(attribute.name);
|
||||
|
||||
/// Only calculate the total length.
|
||||
for (auto & [key, value] : update_unit_ptr->found_ids)
|
||||
@ -357,12 +357,7 @@ void CacheDictionary::getItemsString(const std::string & attribute_name,
|
||||
{
|
||||
const auto found_it = update_unit_ptr->found_ids.find(id);
|
||||
if (found_it->second.found)
|
||||
{
|
||||
std::cout << "size " << found_it->second.values.size() << std::endl;
|
||||
std::cout << "attribute_index " << attribute_index << std::endl;
|
||||
value = std::get<String>(found_it->second.values[attribute_index]);
|
||||
}
|
||||
|
||||
else
|
||||
value = get_default(row);
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace DB
|
||||
auto & attribute = getAttribute(attribute_name); \
|
||||
checkAttributeType(this, attribute_name, attribute.type, AttributeUnderlyingType::ut##TYPE); \
|
||||
const auto null_value = std::get<TYPE>(attribute.null_values); \
|
||||
getItemsNumberImpl<TYPE, TYPE>(attribute_name, attribute, ids, out, [&](const size_t) { return null_value; }); \
|
||||
getItemsNumberImpl<TYPE, TYPE>(attribute, ids, out, [&](const size_t) { return null_value; }); \
|
||||
}
|
||||
|
||||
DEFINE(UInt8)
|
||||
|
@ -12,7 +12,7 @@ namespace DB
|
||||
{ \
|
||||
auto & attribute = getAttribute(attribute_name); \
|
||||
checkAttributeType(this, attribute_name, attribute.type, AttributeUnderlyingType::ut##TYPE); \
|
||||
getItemsNumberImpl<TYPE, TYPE>(attribute_name, attribute, ids, out, [&](const size_t row) { return def[row]; }); \
|
||||
getItemsNumberImpl<TYPE, TYPE>(attribute, ids, out, [&](const size_t row) { return def[row]; }); \
|
||||
}
|
||||
|
||||
DEFINE(UInt8)
|
||||
|
@ -9,7 +9,7 @@ namespace DB
|
||||
{ \
|
||||
auto & attribute = getAttribute(attribute_name); \
|
||||
checkAttributeType(this, attribute_name, attribute.type, AttributeUnderlyingType::ut##TYPE); \
|
||||
getItemsNumberImpl<TYPE, TYPE>(attribute_name, attribute, ids, out, [&](const size_t) { return def; }); \
|
||||
getItemsNumberImpl<TYPE, TYPE>(attribute, ids, out, [&](const size_t) { return def; }); \
|
||||
}
|
||||
|
||||
DEFINE(UInt8)
|
||||
|
Loading…
Reference in New Issue
Block a user