first truly working version

This commit is contained in:
myrrc 2020-07-17 15:44:26 +03:00
parent 0ce74ccc28
commit 80053d745d
4 changed files with 36 additions and 18 deletions

View File

@ -21,6 +21,8 @@ namespace ErrorCodes
* with UIntXX holding actual data indices.
* To obtain the value's index, call #getOrFindIndex.
* To operate on the data (so called indices column), call #getIndexes.
*
* @note The indices column always contains the default value (empty StringRef) with the first index.
*/
class ColumnLowCardinality final : public COWHelper<IColumn, ColumnLowCardinality>
{

View File

@ -112,22 +112,18 @@ public:
UInt128 getHash() const override { return hash.getHash(*getRawColumnPtr()); }
inline UInt64 getOrFindIndex(const StringRef& value) const override
inline std::optional<UInt64> getOrFindIndex(const StringRef& value) const override
{
if (std::optional<UInt64> res = reverse_index.getIndex(value); res)
return res.value();
return res;
auto& nested = *getNestedColumn();
for (size_t i = 0; i < nested.size(); ++i) {
std::cout << nested.getDataAt(i) << std::endl;
for (size_t i = 0; i < nested.size(); ++i)
if (nested.getDataAt(i) == value)
return i;
};
throw Exception(
"Trying to find the value that is not present in the index",
ErrorCodes::LOGICAL_ERROR);
return {};
}
private:

View File

@ -1,4 +1,5 @@
#pragma once
#include <optional>
#include <Columns/IColumn.h>
#include <Common/UInt128.h>
@ -85,7 +86,7 @@ public:
* region, so it can be easily represented as a @e StringRef. So we pass that ref to this function and get its
* index in the dictionary, which can be used to operate with the indices column.
*/
virtual inline UInt64 getOrFindIndex(const StringRef& value) const = 0;
virtual std::optional<UInt64> getOrFindIndex(const StringRef& value) const = 0;
void insert(const Field &) override
{

View File

@ -1,3 +1,4 @@
#include <optional>
#include <type_traits>
#include <Functions/IFunctionImpl.h>
#include <Functions/FunctionFactory.h>
@ -58,7 +59,7 @@ struct IndexCount
* ConstColumn s), and @e vectorVector for processing vectors of vectors.
*/
template <class Initial, class Result, class ConcreteAction>
template <class Initial, class Result, class ConcreteAction, bool ResizeRes = true>
struct ArrayIndexNumImpl
{
private:
@ -101,7 +102,9 @@ private:
PaddedPODArray<typename ConcreteAction::ResultType> & result)
{
size_t size = offsets.size();
result.resize(size);
if constexpr (ResizeRes)
result.resize(size);
ColumnArray::Offset current_offset = 0;
for (size_t i = 0; i < size; ++i)
@ -133,7 +136,9 @@ private:
const PaddedPODArray<UInt8> & null_map_item)
{
size_t size = offsets.size();
result.resize(size);
if constexpr (ResizeRes)
result.resize(size);
ColumnArray::Offset current_offset = 0;
for (size_t i = 0; i < size; ++i)
@ -165,7 +170,9 @@ private:
const PaddedPODArray<UInt8> & null_map_data)
{
size_t size = offsets.size();
result.resize(size);
if constexpr (ResizeRes)
result.resize(size);
ColumnArray::Offset current_offset = 0;
for (size_t i = 0; i < size; ++i)
@ -202,7 +209,9 @@ private:
const PaddedPODArray<UInt8> & null_map_item)
{
size_t size = offsets.size();
result.resize(size);
if constexpr (ResizeRes)
result.resize(size);
ColumnArray::Offset current_offset = 0;
for (size_t i = 0; i < size; ++i)
@ -766,19 +775,25 @@ private:
? 1 /// We have a column with just one value. Arbitrary n is allowed (as the column is const, so take 0).
: col_arg->size();
col_res->getData().resize_fill(col_array->getOffsets().size()); /// fill with default values
for (size_t i = 0; i < size; ++i)
{
StringRef elem = col_arg->getDataAt(i);
UInt64 value_index = col_lc->getDictionary().getOrFindIndex(elem);
std::optional<UInt64> value_index = col_lc->getDictionary().getOrFindIndex(elem);
if (!value_index)
continue; /// position already zeroed out
ArrayIndexNumImpl<
/* Initial data type -- DB::ReverseIndex index */ UInt64,
/* Resulting data type -- same */ UInt64,
ConcreteAction>::
ConcreteAction,
/* Resize col_res -- already resized */ false>::
vector(
/* data -- indices column */ col_lc->getIndexes(),
col_array->getOffsets(),
/* target value */ value_index,
/* target value */ *value_index,
col_res->getData(),
null_map_data,
null_map_item);
@ -804,7 +819,11 @@ private:
if (item_arg->onlyNull())
{
ArrayIndexStringNullImpl<ConcreteAction>::vector_const(
col_nested->getChars(), col_array->getOffsets(), col_nested->getOffsets(), col_res->getData(), null_map_data);
col_nested->getChars(),
col_array->getOffsets(),
col_nested->getOffsets(),
col_res->getData(),
null_map_data);
}
else if (const auto item_arg_const = checkAndGetColumnConstStringOrFixedString(item_arg))
{