mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-22 09:40:49 +00:00
Updated DictionaryDefaultValueExtractor interface
This commit is contained in:
parent
c4ffa2160f
commit
b7a150cc63
@ -271,11 +271,10 @@ ColumnPtr CacheDictionary::getColumn(
|
||||
{
|
||||
using Type = std::decay_t<decltype(dictionary_attribute_type)>;
|
||||
using AttributeType = typename Type::AttributeType;
|
||||
using ValueType = DictionaryValueType<AttributeType>;
|
||||
using ColumnProvider = DictionaryAttributeColumnProvider<AttributeType>;
|
||||
|
||||
const auto null_value = static_cast<ValueType>(std::get<AttributeType>(attribute.null_value));
|
||||
DictionaryDefaultValueExtractor<ValueType> default_value_extractor(null_value, default_values_column);
|
||||
|
||||
const auto null_value = std::get<AttributeType>(attribute.null_value);
|
||||
DictionaryDefaultValueExtractor<AttributeType> default_value_extractor(null_value, default_values_column);
|
||||
|
||||
auto column = ColumnProvider::getColumn(dictionary_attribute, keys_size);
|
||||
|
||||
@ -297,12 +296,12 @@ ColumnPtr CacheDictionary::getColumn(
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename AttributeType, typename OutputType>
|
||||
template <typename AttributeType, typename OutputType, typename DefaultValueExtractor>
|
||||
void CacheDictionary::getItemsNumberImpl(
|
||||
Attribute & attribute,
|
||||
Attribute & attribute,
|
||||
const PaddedPODArray<Key> & ids,
|
||||
ResultArrayType<OutputType> & out,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const
|
||||
DefaultValueExtractor & default_value_extractor) const
|
||||
{
|
||||
/// First fill everything with default values
|
||||
const auto rows = ext::size(ids);
|
||||
@ -427,7 +426,7 @@ void CacheDictionary::getItemsString(
|
||||
Attribute & attribute,
|
||||
const PaddedPODArray<Key> & ids,
|
||||
ColumnString * out,
|
||||
DictionaryDefaultValueExtractor<StringRef> & default_value_extractor) const
|
||||
DictionaryDefaultValueExtractor<String> & default_value_extractor) const
|
||||
{
|
||||
const auto rows = ext::size(ids);
|
||||
|
||||
|
@ -204,18 +204,18 @@ private:
|
||||
/* NOLINTNEXTLINE(readability-convert-member-functions-to-static) */
|
||||
Attribute createAttributeWithTypeAndName(const AttributeUnderlyingType type, const String & name, const Field & null_value);
|
||||
|
||||
template <typename AttributeType, typename OutputType>
|
||||
template <typename AttributeType, typename OutputType, typename DefaultValueExtractor>
|
||||
void getItemsNumberImpl(
|
||||
Attribute & attribute,
|
||||
const PaddedPODArray<Key> & ids,
|
||||
ResultArrayType<OutputType> & out,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const;
|
||||
DefaultValueExtractor & default_value_extractor) const;
|
||||
|
||||
void getItemsString(
|
||||
Attribute & attribute,
|
||||
const PaddedPODArray<Key> & ids,
|
||||
ColumnString * out,
|
||||
DictionaryDefaultValueExtractor<StringRef> & default_value_extractor) const;
|
||||
DictionaryDefaultValueExtractor<String> & default_value_extractor) const;
|
||||
|
||||
PaddedPODArray<Key> getCachedIds() const;
|
||||
|
||||
|
@ -91,11 +91,10 @@ ColumnPtr ComplexKeyCacheDictionary::getColumn(
|
||||
{
|
||||
using Type = std::decay_t<decltype(dictionary_attribute_type)>;
|
||||
using AttributeType = typename Type::AttributeType;
|
||||
using ValueType = DictionaryValueType<AttributeType>;
|
||||
using ColumnProvider = DictionaryAttributeColumnProvider<AttributeType>;
|
||||
using ColumnProvider = DictionaryAttributeColumnProvider<AttributeType>;
|
||||
|
||||
const auto null_value = ValueType{std::get<AttributeType>(attribute.null_values)};
|
||||
DictionaryDefaultValueExtractor<ValueType> default_value_extractor(null_value, default_values_column);
|
||||
const auto null_value = std::get<AttributeType>(attribute.null_values);
|
||||
DictionaryDefaultValueExtractor<AttributeType> default_value_extractor(null_value, default_values_column);
|
||||
|
||||
auto column = ColumnProvider::getColumn(dictionary_attribute, keys_size);
|
||||
|
||||
@ -248,12 +247,12 @@ ColumnUInt8::Ptr ComplexKeyCacheDictionary::hasKeys(const Columns & key_columns,
|
||||
}
|
||||
|
||||
|
||||
template <typename AttributeType, typename OutputType>
|
||||
template <typename AttributeType, typename OutputType, typename DefaultValueExtractor>
|
||||
void ComplexKeyCacheDictionary::getItemsNumberImpl(
|
||||
Attribute & attribute,
|
||||
Attribute & attribute,
|
||||
const Columns & key_columns,
|
||||
PaddedPODArray<OutputType> & out,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const
|
||||
DefaultValueExtractor & default_value_extractor) const
|
||||
{
|
||||
/// Mapping: <key> -> { all indices `i` of `key_columns` such that `key_columns[i]` = <key> }
|
||||
MapType<std::vector<size_t>> outdated_keys;
|
||||
@ -335,7 +334,7 @@ void ComplexKeyCacheDictionary::getItemsString(
|
||||
Attribute & attribute,
|
||||
const Columns & key_columns,
|
||||
ColumnString * out,
|
||||
DictionaryDefaultValueExtractor<StringRef> & default_value_extractor) const
|
||||
DictionaryDefaultValueExtractor<String> & default_value_extractor) const
|
||||
{
|
||||
const auto rows_num = key_columns.front()->size();
|
||||
/// save on some allocations
|
||||
|
@ -175,18 +175,18 @@ private:
|
||||
|
||||
Attribute createAttributeWithType(const AttributeUnderlyingType type, const Field & null_value);
|
||||
|
||||
template <typename AttributeType, typename OutputType>
|
||||
template <typename AttributeType, typename OutputType, typename DefaultValueExtractor>
|
||||
void getItemsNumberImpl(
|
||||
Attribute & attribute,
|
||||
const Columns & key_columns,
|
||||
PaddedPODArray<OutputType> & out,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const;
|
||||
DefaultValueExtractor & default_value_extractor) const;
|
||||
|
||||
void getItemsString(
|
||||
Attribute & attribute,
|
||||
const Columns & key_columns,
|
||||
ColumnString * out,
|
||||
DictionaryDefaultValueExtractor<StringRef> & default_value_extractor) const;
|
||||
DictionaryDefaultValueExtractor<String> & default_value_extractor) const;
|
||||
|
||||
template <typename PresentKeyHandler, typename AbsentKeyHandler>
|
||||
void update(
|
||||
|
@ -64,9 +64,10 @@ ColumnPtr ComplexKeyDirectDictionary::getColumn(
|
||||
using AttributeType = typename Type::AttributeType;
|
||||
using ValueType = DictionaryValueType<AttributeType>;
|
||||
using ColumnProvider = DictionaryAttributeColumnProvider<AttributeType>;
|
||||
|
||||
const auto null_value = std::get<ValueType>(attribute.null_values);
|
||||
DictionaryDefaultValueExtractor<ValueType> default_value_extractor(null_value, default_values_column);
|
||||
|
||||
const auto attribute_null_value = std::get<ValueType>(attribute.null_values);
|
||||
AttributeType null_value = static_cast<AttributeType>(attribute_null_value);
|
||||
DictionaryDefaultValueExtractor<AttributeType> default_value_extractor(std::move(null_value), default_values_column);
|
||||
|
||||
auto column = ColumnProvider::getColumn(dictionary_attribute, keys_size);
|
||||
|
||||
@ -94,7 +95,8 @@ ColumnPtr ComplexKeyDirectDictionary::getColumn(
|
||||
getItemsImpl<AttributeType, AttributeType>(
|
||||
attribute,
|
||||
key_columns,
|
||||
[&](const size_t row, const auto value, bool is_null) {
|
||||
[&](const size_t row, const auto value, bool is_null)
|
||||
{
|
||||
if (attribute.is_nullable)
|
||||
(*vec_null_map_to)[row] = is_null;
|
||||
|
||||
|
@ -65,10 +65,11 @@ ColumnPtr ComplexKeyHashedDictionary::getColumn(
|
||||
using Type = std::decay_t<decltype(dictionary_attribute_type)>;
|
||||
using AttributeType = typename Type::AttributeType;
|
||||
using ValueType = DictionaryValueType<AttributeType>;
|
||||
using ColumnProvider = DictionaryAttributeColumnProvider<AttributeType>;
|
||||
using ColumnProvider = DictionaryAttributeColumnProvider<AttributeType>;
|
||||
|
||||
const auto null_value = std::get<ValueType>(attribute.null_values);
|
||||
DictionaryDefaultValueExtractor<ValueType> default_value_extractor(null_value, default_values_column);
|
||||
const auto attribute_null_value = std::get<ValueType>(attribute.null_values);
|
||||
AttributeType null_value = attribute_null_value;
|
||||
DictionaryDefaultValueExtractor<AttributeType> default_value_extractor(std::move(null_value), default_values_column);
|
||||
|
||||
auto column = ColumnProvider::getColumn(dictionary_attribute, keys_size);
|
||||
|
||||
@ -370,12 +371,12 @@ ComplexKeyHashedDictionary::createAttribute(const DictionaryAttribute & attribut
|
||||
}
|
||||
|
||||
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter>
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter, typename DefaultValueExtractor>
|
||||
void ComplexKeyHashedDictionary::getItemsImpl(
|
||||
const Attribute & attribute,
|
||||
const Columns & key_columns,
|
||||
ValueSetter && set_value,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const
|
||||
DefaultValueExtractor & default_value_extractor) const
|
||||
{
|
||||
const auto & attr = std::get<ContainerType<AttributeType>>(attribute.maps);
|
||||
|
||||
|
@ -140,12 +140,12 @@ private:
|
||||
|
||||
Attribute createAttribute(const DictionaryAttribute & attribute, const Field & null_value);
|
||||
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter>
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter, typename DefaultValueExtractor>
|
||||
void getItemsImpl(
|
||||
const Attribute & attribute,
|
||||
const Columns & key_columns,
|
||||
ValueSetter && set_value,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const;
|
||||
DefaultValueExtractor & default_value_extractor) const;
|
||||
|
||||
template <typename T>
|
||||
bool setAttributeValueImpl(Attribute & attribute, const StringRef key, const T value);
|
||||
|
@ -233,7 +233,7 @@ Block DictionaryBlockInputStream<Key>::fillBlock(
|
||||
else
|
||||
{
|
||||
column = dictionary->getColumn(
|
||||
attribute.name,
|
||||
attribute.name,
|
||||
attribute.type,
|
||||
keys,
|
||||
data_types,
|
||||
|
@ -10,11 +10,16 @@
|
||||
namespace DB
|
||||
{
|
||||
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int TYPE_MISMATCH;
|
||||
}
|
||||
|
||||
/**
|
||||
* In Dictionaries implementation String attribute is stored in arena and StringRefs are pointing to it.
|
||||
*/
|
||||
template <typename DictionaryAttributeType>
|
||||
using DictionaryValueType =
|
||||
using DictionaryValueType =
|
||||
std::conditional_t<std::is_same_v<DictionaryAttributeType, String>, StringRef, DictionaryAttributeType>;
|
||||
|
||||
/**
|
||||
@ -24,9 +29,9 @@ template <typename DictionaryAttributeType>
|
||||
class DictionaryAttributeColumnProvider
|
||||
{
|
||||
public:
|
||||
using ColumnType =
|
||||
using ColumnType =
|
||||
std::conditional_t<std::is_same_v<DictionaryAttributeType, String>, ColumnString,
|
||||
std::conditional_t<IsDecimalNumber<DictionaryAttributeType>, ColumnDecimal<DictionaryAttributeType>,
|
||||
std::conditional_t<IsDecimalNumber<DictionaryAttributeType>, ColumnDecimal<DictionaryAttributeType>,
|
||||
ColumnVector<DictionaryAttributeType>>>;
|
||||
|
||||
using ColumnPtr = typename ColumnType::MutablePtr;
|
||||
@ -50,66 +55,60 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* DictionaryDefaultValueExtractor used to simplify getting default value for IDictionary function `getColumn`.
|
||||
* Provides interface for getting default value with operator[];
|
||||
*
|
||||
* If default_values_column is not null in constructor than this column values will be used as default values.
|
||||
* If default_values_column is null then attribute_default_value will be used.
|
||||
* DictionaryDefaultValueExtractor used to simplify getting default value for IDictionary function `getColumn`.
|
||||
* Provides interface for getting default value with operator[];
|
||||
*
|
||||
* If default_values_column is null then attribute_default_value will be used.
|
||||
* If default_values_column is not null in constructor than this column values will be used as default values.
|
||||
*/
|
||||
template <typename DefaultValueType>
|
||||
template <typename DictionaryAttributeType>
|
||||
class DictionaryDefaultValueExtractor
|
||||
{
|
||||
using ResultColumnType =
|
||||
std::conditional_t< std::is_same_v<DefaultValueType, StringRef>, ColumnString,
|
||||
std::conditional_t<IsDecimalNumber<DefaultValueType>, ColumnDecimal<DefaultValueType>,
|
||||
ColumnVector<DefaultValueType>>>;
|
||||
using DefaultColumnType = typename DictionaryAttributeColumnProvider<DictionaryAttributeType>::ColumnType;
|
||||
|
||||
public:
|
||||
DictionaryDefaultValueExtractor(DefaultValueType attribute_default_value, ColumnPtr default_values_column_ = nullptr)
|
||||
DictionaryDefaultValueExtractor(DictionaryAttributeType attribute_default_value, ColumnPtr default_values_column_ = nullptr)
|
||||
{
|
||||
if (default_values_column_ != nullptr)
|
||||
if (!default_values_column_)
|
||||
default_value = { std::move(attribute_default_value) };
|
||||
else
|
||||
{
|
||||
if (const auto * const default_col = checkAndGetColumn<ResultColumnType>(*default_values_column))
|
||||
if (const auto * const default_col = checkAndGetColumn<DefaultColumnType>(*default_values_column))
|
||||
{
|
||||
default_values_column = default_col;
|
||||
}
|
||||
else if (const auto * const default_col_const = checkAndGetColumnConst<ResultColumnType>(default_values_column_.get()))
|
||||
else if (const auto * const default_col_const = checkAndGetColumnConst<DefaultColumnType>(default_values_column_.get()))
|
||||
{
|
||||
/// TODO: Check String lifetime safety
|
||||
/// DefaultValueType for StringColumn is StringRef, but const column getValue will return String
|
||||
using ConstColumnValue = std::conditional_t<std::is_same_v<DefaultValueType, StringRef>, String, DefaultValueType>;
|
||||
default_value = std::make_optional<DefaultValueType>(default_col_const->template getValue<ConstColumnValue>());
|
||||
default_value = { default_col_const->template getValue<DictionaryAttributeType>() };
|
||||
}
|
||||
else
|
||||
throw Exception{"Type of default column is not the same as result type.", ErrorCodes::TYPE_MISMATCH};
|
||||
throw Exception{"Type of default column is not the same as dictionary attribute type.", ErrorCodes::TYPE_MISMATCH};
|
||||
}
|
||||
else
|
||||
default_value = std::make_optional<DefaultValueType>(attribute_default_value);
|
||||
}
|
||||
|
||||
DefaultValueType operator[](size_t row)
|
||||
DictionaryValueType<DictionaryAttributeType> operator[](size_t row)
|
||||
{
|
||||
if (default_value)
|
||||
return *default_value;
|
||||
|
||||
if constexpr (std::is_same_v<ResultColumnType, ColumnString>)
|
||||
return static_cast<DictionaryAttributeType>(*default_value);
|
||||
|
||||
if constexpr (std::is_same_v<DefaultColumnType, ColumnString>)
|
||||
return default_values_column->getDataAt(row);
|
||||
else
|
||||
return default_values_column->getData()[row];
|
||||
}
|
||||
private:
|
||||
const ResultColumnType * default_values_column = nullptr;
|
||||
std::optional<DefaultValueType> default_value = {};
|
||||
const DefaultColumnType * default_values_column = nullptr;
|
||||
std::optional<DictionaryAttributeType> default_value = {};
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns ColumnVector data as PaddedPodArray.
|
||||
*
|
||||
* Returns ColumnVector data as PaddedPodArray.
|
||||
|
||||
* If column is constant parameter backup_storage is used to store values.
|
||||
*/
|
||||
template <typename T>
|
||||
static const PaddedPODArray<T> & getColumnVectorData(
|
||||
const IDictionaryBase * dictionary [[maybe_unused]],
|
||||
const IDictionaryBase * dictionary,
|
||||
const ColumnPtr column,
|
||||
PaddedPODArray<T> & backup_storage)
|
||||
{
|
||||
|
@ -39,7 +39,7 @@ void DirectDictionary::toParent(const PaddedPODArray<Key> & ids, PaddedPODArray<
|
||||
{
|
||||
const auto null_value = std::get<UInt64>(hierarchical_attribute->null_values);
|
||||
DictionaryDefaultValueExtractor<UInt64> extractor(null_value);
|
||||
|
||||
|
||||
getItemsImpl<UInt64, UInt64>(
|
||||
*hierarchical_attribute,
|
||||
ids,
|
||||
@ -166,9 +166,10 @@ ColumnPtr DirectDictionary::getColumn(
|
||||
|
||||
using ValueType = DictionaryValueType<AttributeType>;
|
||||
using ColumnProvider = DictionaryAttributeColumnProvider<AttributeType>;
|
||||
|
||||
const auto null_value = std::get<ValueType>(attribute.null_values);
|
||||
DictionaryDefaultValueExtractor<ValueType> default_value_extractor(null_value, default_values_column);
|
||||
|
||||
const auto attribute_null_value = std::get<ValueType>(attribute.null_values);
|
||||
AttributeType null_value = static_cast<AttributeType>(attribute_null_value);
|
||||
DictionaryDefaultValueExtractor<AttributeType> default_value_extractor(std::move(null_value), default_values_column);
|
||||
|
||||
auto column = ColumnProvider::getColumn(dictionary_attribute, keys_size);
|
||||
|
||||
|
@ -131,9 +131,10 @@ ColumnPtr FlatDictionary::getColumn(
|
||||
using AttributeType = typename Type::AttributeType;
|
||||
using ValueType = DictionaryValueType<AttributeType>;
|
||||
using ColumnProvider = DictionaryAttributeColumnProvider<AttributeType>;
|
||||
|
||||
const auto null_value = std::get<ValueType>(attribute.null_values);
|
||||
DictionaryDefaultValueExtractor<ValueType> default_value_extractor(null_value, default_values_column);
|
||||
|
||||
const auto attribute_null_value = std::get<ValueType>(attribute.null_values);
|
||||
AttributeType null_value = static_cast<AttributeType>(attribute_null_value);
|
||||
DictionaryDefaultValueExtractor<AttributeType> default_value_extractor(std::move(null_value), default_values_column);
|
||||
|
||||
auto column = ColumnProvider::getColumn(dictionary_attribute, size);
|
||||
|
||||
@ -153,7 +154,7 @@ ColumnPtr FlatDictionary::getColumn(
|
||||
|
||||
getItemsImpl<ValueType, ValueType>(
|
||||
attribute,
|
||||
ids,
|
||||
ids,
|
||||
[&](const size_t row, const auto value) { out[row] = value; },
|
||||
default_value_extractor);
|
||||
}
|
||||
@ -404,12 +405,12 @@ FlatDictionary::Attribute FlatDictionary::createAttribute(const DictionaryAttrib
|
||||
}
|
||||
|
||||
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter>
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter, typename DefaultValueExtractor>
|
||||
void FlatDictionary::getItemsImpl(
|
||||
const Attribute & attribute,
|
||||
const PaddedPODArray<Key> & ids,
|
||||
ValueSetter && set_value,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const
|
||||
DefaultValueExtractor & default_value_extractor) const
|
||||
{
|
||||
const auto & attr = std::get<ContainerType<AttributeType>>(attribute.arrays);
|
||||
const auto rows = ext::size(ids);
|
||||
|
@ -148,12 +148,12 @@ private:
|
||||
|
||||
Attribute createAttribute(const DictionaryAttribute& attribute, const Field & null_value);
|
||||
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter>
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter, typename DefaultValueExtractor>
|
||||
void getItemsImpl(
|
||||
const Attribute & attribute,
|
||||
const PaddedPODArray<Key> & ids,
|
||||
ValueSetter && set_value,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const;
|
||||
DefaultValueExtractor & default_value_extractor) const;
|
||||
|
||||
template <typename T>
|
||||
void resize(Attribute & attribute, const Key id);
|
||||
|
@ -152,9 +152,10 @@ ColumnPtr HashedDictionary::getColumn(
|
||||
using AttributeType = typename Type::AttributeType;
|
||||
using ValueType = DictionaryValueType<AttributeType>;
|
||||
using ColumnProvider = DictionaryAttributeColumnProvider<AttributeType>;
|
||||
|
||||
const auto null_value = std::get<ValueType>(attribute.null_values);
|
||||
DictionaryDefaultValueExtractor<ValueType> default_value_extractor(null_value, default_values_column);
|
||||
|
||||
const auto attribute_null_value = std::get<ValueType>(attribute.null_values);
|
||||
AttributeType null_value = static_cast<AttributeType>(attribute_null_value);
|
||||
DictionaryDefaultValueExtractor<AttributeType> default_value_extractor(std::move(null_value), default_values_column);
|
||||
|
||||
auto column = ColumnProvider::getColumn(dictionary_attribute, size);
|
||||
|
||||
@ -178,7 +179,7 @@ ColumnPtr HashedDictionary::getColumn(
|
||||
[&](const size_t row, const auto value) { return out[row] = value; },
|
||||
default_value_extractor);
|
||||
}
|
||||
|
||||
|
||||
result = std::move(column);
|
||||
};
|
||||
|
||||
@ -518,12 +519,12 @@ HashedDictionary::Attribute HashedDictionary::createAttribute(const DictionaryAt
|
||||
}
|
||||
|
||||
|
||||
template <typename AttributeType, typename OutputType, typename MapType, typename ValueSetter>
|
||||
template <typename AttributeType, typename OutputType, typename MapType, typename ValueSetter, typename DefaultValueExtractor>
|
||||
void HashedDictionary::getItemsAttrImpl(
|
||||
const MapType & attr,
|
||||
const PaddedPODArray<Key> & ids,
|
||||
ValueSetter && set_value,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const
|
||||
DefaultValueExtractor & default_value_extractor) const
|
||||
{
|
||||
const auto rows = ext::size(ids);
|
||||
|
||||
@ -536,12 +537,12 @@ void HashedDictionary::getItemsAttrImpl(
|
||||
query_count.fetch_add(rows, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter>
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter, typename DefaultValueExtractor>
|
||||
void HashedDictionary::getItemsImpl(
|
||||
const Attribute & attribute,
|
||||
const PaddedPODArray<Key> & ids,
|
||||
ValueSetter && set_value,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const
|
||||
DefaultValueExtractor & default_value_extractor) const
|
||||
{
|
||||
if (!sparse)
|
||||
return getItemsAttrImpl<AttributeType, OutputType>(*std::get<CollectionPtrType<AttributeType>>(attribute.maps), ids, set_value, default_value_extractor);
|
||||
|
@ -182,19 +182,19 @@ private:
|
||||
|
||||
Attribute createAttribute(const DictionaryAttribute& attribute, const Field & null_value);
|
||||
|
||||
template <typename AttributeType, typename OutputType, typename MapType, typename ValueSetter>
|
||||
template <typename AttributeType, typename OutputType, typename MapType, typename ValueSetter, typename DefaultValueExtractor>
|
||||
void getItemsAttrImpl(
|
||||
const MapType & attr,
|
||||
const PaddedPODArray<Key> & ids,
|
||||
ValueSetter && set_value,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & extractor) const;
|
||||
DefaultValueExtractor & default_value_extractor) const;
|
||||
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter>
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter, typename DefaultValueExtractor>
|
||||
void getItemsImpl(
|
||||
const Attribute & attribute,
|
||||
const PaddedPODArray<Key> & ids,
|
||||
ValueSetter && set_value,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & extractor) const;
|
||||
DefaultValueExtractor & default_value_extractor) const;
|
||||
|
||||
template <typename T>
|
||||
bool setAttributeValueImpl(Attribute & attribute, const Key id, const T value);
|
||||
|
@ -22,21 +22,20 @@ namespace DB
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int NOT_IMPLEMENTED;
|
||||
extern const int TYPE_MISMATCH;
|
||||
}
|
||||
|
||||
struct IDictionaryBase;
|
||||
using DictionaryPtr = std::unique_ptr<IDictionaryBase>;
|
||||
|
||||
/** DictionaryKeyType provides IDictionary client information about
|
||||
* which key type is supported by dictionary.
|
||||
*
|
||||
* Simple is for dictionaries that support UInt64 key column.
|
||||
*
|
||||
* Complex is for dictionaries that support any combination of key columns.
|
||||
*
|
||||
* Range is for dictionary that support combination of UInt64 key column,
|
||||
* and Integer representable range key column.
|
||||
/** DictionaryKeyType provides IDictionary client information about
|
||||
* which key type is supported by dictionary.
|
||||
*
|
||||
* Simple is for dictionaries that support UInt64 key column.
|
||||
*
|
||||
* Complex is for dictionaries that support any combination of key columns.
|
||||
*
|
||||
* Range is for dictionary that support combination of UInt64 key column,
|
||||
* and numeric representable range key column.
|
||||
*/
|
||||
enum class DictionaryKeyType
|
||||
{
|
||||
@ -47,7 +46,7 @@ enum class DictionaryKeyType
|
||||
|
||||
/**
|
||||
* Base class for Dictionaries implementation.
|
||||
*/
|
||||
*/
|
||||
struct IDictionaryBase : public IExternalLoadable
|
||||
{
|
||||
using Key = UInt64;
|
||||
@ -109,11 +108,11 @@ struct IDictionaryBase : public IExternalLoadable
|
||||
*/
|
||||
virtual DictionaryKeyType getKeyType() const = 0;
|
||||
|
||||
/** Subclass must validate key columns and keys types
|
||||
/** Subclass must validate key columns and keys types
|
||||
* and return column representation of dictionary attribute.
|
||||
*
|
||||
*
|
||||
* Parameter default_values_column must be used to provide default values
|
||||
* for keys that are not in dictionary. If null pointer is passed,
|
||||
* for keys that are not in dictionary. If null pointer is passed,
|
||||
* then default attribute value must be used.
|
||||
*/
|
||||
virtual ColumnPtr getColumn(
|
||||
@ -123,8 +122,8 @@ struct IDictionaryBase : public IExternalLoadable
|
||||
const DataTypes & key_types,
|
||||
const ColumnPtr default_values_column) const = 0;
|
||||
|
||||
/** Subclass must validate key columns and key types and return ColumnUInt8 that
|
||||
* is bitmask representation of is key in dictionary or not.
|
||||
/** Subclass must validate key columns and key types and return ColumnUInt8 that
|
||||
* is bitmask representation of is key in dictionary or not.
|
||||
* If key is in dictionary then value of associated row will be 1, otherwise 0.
|
||||
*/
|
||||
virtual ColumnUInt8::Ptr hasKeys(
|
||||
|
@ -289,10 +289,10 @@ ColumnPtr IPAddressDictionary::getColumn(
|
||||
using Type = std::decay_t<decltype(dictionary_attribute_type)>;
|
||||
using AttributeType = typename Type::AttributeType;
|
||||
using ValueType = DictionaryValueType<AttributeType>;
|
||||
using ColumnProvider = DictionaryAttributeColumnProvider<AttributeType>;
|
||||
using ColumnProvider = DictionaryAttributeColumnProvider<AttributeType>;
|
||||
|
||||
const auto null_value = ValueType{std::get<AttributeType>(attribute.null_values)};
|
||||
DictionaryDefaultValueExtractor<ValueType> default_value_extractor(null_value, default_values_column);
|
||||
const auto null_value = std::get<AttributeType>(attribute.null_values);
|
||||
DictionaryDefaultValueExtractor<AttributeType> default_value_extractor(null_value, default_values_column);
|
||||
|
||||
auto column = ColumnProvider::getColumn(dictionary_attribute, size);
|
||||
|
||||
@ -637,12 +637,12 @@ const uint8_t * IPAddressDictionary::getIPv6FromOffset(const IPAddressDictionary
|
||||
return reinterpret_cast<const uint8_t *>(&ipv6_col[i * IPV6_BINARY_LENGTH]);
|
||||
}
|
||||
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter>
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter, typename DefaultValueExtractor>
|
||||
void IPAddressDictionary::getItemsByTwoKeyColumnsImpl(
|
||||
const Attribute & attribute,
|
||||
const Columns & key_columns,
|
||||
ValueSetter && set_value,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const
|
||||
DefaultValueExtractor & default_value_extractor) const
|
||||
{
|
||||
const auto first_column = key_columns.front();
|
||||
const auto rows = first_column->size();
|
||||
@ -718,12 +718,12 @@ void IPAddressDictionary::getItemsByTwoKeyColumnsImpl(
|
||||
}
|
||||
}
|
||||
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter>
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter, typename DefaultValueExtractor>
|
||||
void IPAddressDictionary::getItemsImpl(
|
||||
const Attribute & attribute,
|
||||
const Columns & key_columns,
|
||||
ValueSetter && set_value,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const
|
||||
DefaultValueExtractor & default_value_extractor) const
|
||||
{
|
||||
const auto first_column = key_columns.front();
|
||||
const auto rows = first_column->size();
|
||||
|
@ -141,19 +141,19 @@ private:
|
||||
|
||||
Attribute createAttributeWithType(const AttributeUnderlyingType type, const Field & null_value);
|
||||
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter>
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter, typename DefaultValueExtractor>
|
||||
void getItemsByTwoKeyColumnsImpl(
|
||||
const Attribute & attribute,
|
||||
const Columns & key_columns,
|
||||
ValueSetter && set_value,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const;
|
||||
DefaultValueExtractor & default_value_extractor) const;
|
||||
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter>
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter, typename DefaultValueExtractor>
|
||||
void getItemsImpl(
|
||||
const Attribute & attribute,
|
||||
const Columns & key_columns,
|
||||
ValueSetter && set_value,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const;
|
||||
DefaultValueExtractor & default_value_extractor) const;
|
||||
|
||||
template <typename T>
|
||||
void setAttributeValueImpl(Attribute & attribute, const T value);
|
||||
|
@ -112,11 +112,10 @@ ColumnPtr IPolygonDictionary::getColumn(
|
||||
{
|
||||
using Type = std::decay_t<decltype(dictionary_attribute_type)>;
|
||||
using AttributeType = typename Type::AttributeType;
|
||||
using ValueType = DictionaryValueType<AttributeType>;
|
||||
using ColumnProvider = DictionaryAttributeColumnProvider<AttributeType>;
|
||||
|
||||
const auto null_value = static_cast<ValueType>(std::get<AttributeType>(null_values[index]));
|
||||
DictionaryDefaultValueExtractor<ValueType> default_value_extractor(null_value, default_values_column);
|
||||
|
||||
const auto null_value = std::get<AttributeType>(null_values[index]);
|
||||
DictionaryDefaultValueExtractor<AttributeType> default_value_extractor(null_value, default_values_column);
|
||||
|
||||
auto column = ColumnProvider::getColumn(dictionary_attribute, keys_size);
|
||||
|
||||
|
@ -124,10 +124,11 @@ ColumnPtr RangeHashedDictionary::getColumn(
|
||||
using Type = std::decay_t<decltype(dictionary_attribute_type)>;
|
||||
using AttributeType = typename Type::AttributeType;
|
||||
using ValueType = DictionaryValueType<AttributeType>;
|
||||
using ColumnProvider = DictionaryAttributeColumnProvider<AttributeType>;
|
||||
using ColumnProvider = DictionaryAttributeColumnProvider<AttributeType>;
|
||||
|
||||
const auto null_value = std::get<ValueType>(attribute.null_values);
|
||||
DictionaryDefaultValueExtractor<ValueType> default_value_extractor(null_value, default_values_column);
|
||||
const auto attribute_null_value = std::get<ValueType>(attribute.null_values);
|
||||
AttributeType null_value = static_cast<AttributeType>(attribute_null_value);
|
||||
DictionaryDefaultValueExtractor<AttributeType> default_value_extractor(std::move(null_value), default_values_column);
|
||||
|
||||
auto column = ColumnProvider::getColumn(dictionary_attribute, keys_size);
|
||||
|
||||
@ -138,7 +139,8 @@ ColumnPtr RangeHashedDictionary::getColumn(
|
||||
getItemsImpl<ValueType, ValueType>(
|
||||
attribute,
|
||||
modified_key_columns,
|
||||
[&](const size_t row, const StringRef value, bool is_null) {
|
||||
[&](const size_t row, const StringRef value, bool is_null)
|
||||
{
|
||||
if (attribute.is_nullable)
|
||||
(*vec_null_map_to)[row] = is_null;
|
||||
|
||||
@ -153,7 +155,8 @@ ColumnPtr RangeHashedDictionary::getColumn(
|
||||
getItemsImpl<ValueType, ValueType>(
|
||||
attribute,
|
||||
modified_key_columns,
|
||||
[&](const size_t row, const auto value, bool is_null) {
|
||||
[&](const size_t row, const auto value, bool is_null)
|
||||
{
|
||||
if (attribute.is_nullable)
|
||||
(*vec_null_map_to)[row] = is_null;
|
||||
|
||||
@ -313,12 +316,12 @@ RangeHashedDictionary::createAttribute(const DictionaryAttribute& attribute, con
|
||||
return attr;
|
||||
}
|
||||
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter>
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter, typename DefaultValueExtractor>
|
||||
void RangeHashedDictionary::getItemsImpl(
|
||||
const Attribute & attribute,
|
||||
const Columns & key_columns,
|
||||
ValueSetter && set_value,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const
|
||||
DefaultValueExtractor & default_value_extractor) const
|
||||
{
|
||||
PaddedPODArray<Key> key_backup_storage;
|
||||
PaddedPODArray<RangeStorageType> range_backup_storage;
|
||||
|
@ -152,12 +152,12 @@ private:
|
||||
|
||||
Attribute createAttribute(const DictionaryAttribute& attribute, const Field & null_value);
|
||||
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter>
|
||||
template <typename AttributeType, typename OutputType, typename ValueSetter, typename DefaultValueExtractor>
|
||||
void getItemsImpl(
|
||||
const Attribute & attribute,
|
||||
const Columns & key_columns,
|
||||
ValueSetter && set_value,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const;
|
||||
DefaultValueExtractor & default_value_extractor) const;
|
||||
|
||||
template <typename T>
|
||||
void setAttributeValueImpl(Attribute & attribute, const Key id, const Range & range, const Field & value);
|
||||
|
@ -1348,11 +1348,10 @@ ColumnPtr SSDCacheDictionary::getColumn(
|
||||
{
|
||||
using Type = std::decay_t<decltype(dictionary_attribute_type)>;
|
||||
using AttributeType = typename Type::AttributeType;
|
||||
using ValueType = DictionaryValueType<AttributeType>;
|
||||
using ColumnProvider = DictionaryAttributeColumnProvider<AttributeType>;
|
||||
|
||||
const auto null_value = static_cast<ValueType>(std::get<AttributeType>(null_values[index]));
|
||||
DictionaryDefaultValueExtractor<ValueType> default_value_extractor(null_value, default_values_column);
|
||||
const auto null_value = std::get<AttributeType>(null_values[index]);
|
||||
DictionaryDefaultValueExtractor<AttributeType> default_value_extractor(null_value, default_values_column);
|
||||
|
||||
auto column = ColumnProvider::getColumn(dictionary_attribute, keys_size);
|
||||
|
||||
|
@ -1401,12 +1401,10 @@ ColumnPtr SSDComplexKeyCacheDictionary::getColumn(
|
||||
{
|
||||
using Type = std::decay_t<decltype(dictionary_attribute_type)>;
|
||||
using AttributeType = typename Type::AttributeType;
|
||||
|
||||
using ValueType = DictionaryValueType<AttributeType>;
|
||||
using ColumnProvider = DictionaryAttributeColumnProvider<AttributeType>;
|
||||
|
||||
const auto null_value = static_cast<ValueType>(std::get<AttributeType>(null_values[index]));
|
||||
DictionaryDefaultValueExtractor<ValueType> default_value_extractor(null_value, default_values_column);
|
||||
const auto null_value = std::get<AttributeType>(null_values[index]);
|
||||
DictionaryDefaultValueExtractor<AttributeType> default_value_extractor(null_value, default_values_column);
|
||||
|
||||
auto column = ColumnProvider::getColumn(dictionary_attribute, keys_size);
|
||||
|
||||
@ -1434,13 +1432,13 @@ ColumnPtr SSDComplexKeyCacheDictionary::getColumn(
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename AttributeType, typename OutputType>
|
||||
template <typename AttributeType, typename OutputType, typename DefaultValueExtractor>
|
||||
void SSDComplexKeyCacheDictionary::getItemsNumberImpl(
|
||||
const size_t attribute_index,
|
||||
const Columns & key_columns,
|
||||
const DataTypes & key_types,
|
||||
ResultArrayType<OutputType> & out,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const
|
||||
DefaultValueExtractor & default_value_extractor) const
|
||||
{
|
||||
assert(dict_struct.key);
|
||||
assert(key_columns.size() == key_types.size());
|
||||
@ -1488,7 +1486,7 @@ void SSDComplexKeyCacheDictionary::getItemsStringImpl(
|
||||
const Columns & key_columns,
|
||||
const DataTypes & key_types,
|
||||
ColumnString * out,
|
||||
DictionaryDefaultValueExtractor<StringRef> & default_value_extractor) const
|
||||
DictionaryDefaultValueExtractor<String> & default_value_extractor) const
|
||||
{
|
||||
dict_struct.validateKeyTypes(key_types);
|
||||
|
||||
|
@ -593,20 +593,20 @@ private:
|
||||
AttributeValueVariant createAttributeNullValueWithType(const AttributeUnderlyingType type, const Field & null_value);
|
||||
void createAttributes();
|
||||
|
||||
template <typename AttributeType, typename OutputType>
|
||||
template <typename AttributeType, typename OutputType, typename DefaultValueExtractor>
|
||||
void getItemsNumberImpl(
|
||||
const size_t attribute_index,
|
||||
const Columns & key_columns,
|
||||
const DataTypes & key_types,
|
||||
ResultArrayType<OutputType> & out,
|
||||
DictionaryDefaultValueExtractor<AttributeType> & default_value_extractor) const;
|
||||
DefaultValueExtractor & default_value_extractor) const;
|
||||
|
||||
void getItemsStringImpl(
|
||||
const size_t attribute_index,
|
||||
const Columns & key_columns,
|
||||
const DataTypes & key_types,
|
||||
ColumnString * out,
|
||||
DictionaryDefaultValueExtractor<StringRef> & default_value_extractor) const;
|
||||
DictionaryDefaultValueExtractor<String> & default_value_extractor) const;
|
||||
|
||||
const std::string name;
|
||||
const DictionaryStructure dict_struct;
|
||||
|
Loading…
Reference in New Issue
Block a user