2017-12-17 09:01:12 +00:00
|
|
|
#include <IO/WriteHelpers.h>
|
2012-08-26 11:14:52 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Columns/ColumnConst.h>
|
2017-12-17 09:01:12 +00:00
|
|
|
#include <Columns/ColumnsCommon.h>
|
2019-10-07 18:56:03 +00:00
|
|
|
#include <Common/PODArray.h>
|
2017-07-21 20:20:22 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2020-03-18 16:03:55 +00:00
|
|
|
#include <Common/WeakHash.h>
|
2020-03-18 16:36:21 +00:00
|
|
|
#include <Common/HashTable/Hash.h>
|
2011-11-06 06:22:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2013-03-06 13:56:11 +00:00
|
|
|
|
2017-12-17 09:01:12 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int SIZES_OF_COLUMNS_DOESNT_MATCH;
|
2020-03-19 17:35:08 +00:00
|
|
|
extern const int LOGICAL_ERROR;
|
2017-12-17 09:01:12 +00:00
|
|
|
}
|
|
|
|
|
2019-08-03 11:02:40 +00:00
|
|
|
ColumnConst::ColumnConst(const ColumnPtr & data_, size_t s_)
|
|
|
|
: data(data_), s(s_)
|
2017-07-24 01:00:31 +00:00
|
|
|
{
|
2017-12-08 03:52:33 +00:00
|
|
|
/// Squash Const of Const.
|
2017-12-15 19:17:15 +00:00
|
|
|
while (const ColumnConst * const_data = typeid_cast<const ColumnConst *>(data.get()))
|
2017-12-08 03:52:33 +00:00
|
|
|
data = const_data->getDataColumnPtr();
|
|
|
|
|
2017-07-24 01:00:31 +00:00
|
|
|
if (data->size() != 1)
|
|
|
|
throw Exception("Incorrect size of nested column in constructor of ColumnConst: " + toString(data->size()) + ", must be 1.",
|
|
|
|
ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
|
|
|
|
}
|
|
|
|
|
2018-03-20 14:17:09 +00:00
|
|
|
ColumnPtr ColumnConst::convertToFullColumn() const
|
2017-07-24 01:00:31 +00:00
|
|
|
{
|
2017-12-15 21:32:25 +00:00
|
|
|
return data->replicate(Offsets(1, s));
|
2017-07-24 01:00:31 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 12:41:29 +00:00
|
|
|
ColumnPtr ColumnConst::removeLowCardinality() const
|
|
|
|
{
|
2018-09-27 15:55:22 +00:00
|
|
|
return ColumnConst::create(data->convertToFullColumnIfLowCardinality(), s);
|
2018-08-14 12:41:29 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 14:17:09 +00:00
|
|
|
ColumnPtr ColumnConst::filter(const Filter & filt, ssize_t /*result_size_hint*/) const
|
2017-12-17 09:01:12 +00:00
|
|
|
{
|
|
|
|
if (s != filt.size())
|
|
|
|
throw Exception("Size of filter (" + toString(filt.size()) + ") doesn't match size of column (" + toString(s) + ")",
|
|
|
|
ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
|
|
|
|
|
|
|
|
return ColumnConst::create(data, countBytesInFilter(filt));
|
|
|
|
}
|
|
|
|
|
2018-03-20 14:17:09 +00:00
|
|
|
ColumnPtr ColumnConst::replicate(const Offsets & offsets) const
|
2017-12-17 09:01:12 +00:00
|
|
|
{
|
|
|
|
if (s != offsets.size())
|
|
|
|
throw Exception("Size of offsets (" + toString(offsets.size()) + ") doesn't match size of column (" + toString(s) + ")",
|
|
|
|
ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
|
|
|
|
|
|
|
|
size_t replicated_size = 0 == s ? 0 : offsets.back();
|
|
|
|
return ColumnConst::create(data, replicated_size);
|
|
|
|
}
|
|
|
|
|
2019-02-18 19:44:26 +00:00
|
|
|
ColumnPtr ColumnConst::permute(const Permutation & perm, size_t limit) const
|
2017-12-17 09:01:12 +00:00
|
|
|
{
|
|
|
|
if (limit == 0)
|
|
|
|
limit = s;
|
|
|
|
else
|
|
|
|
limit = std::min(s, limit);
|
|
|
|
|
|
|
|
if (perm.size() < limit)
|
|
|
|
throw Exception("Size of permutation (" + toString(perm.size()) + ") is less than required (" + toString(limit) + ")",
|
|
|
|
ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
|
|
|
|
|
|
|
|
return ColumnConst::create(data, limit);
|
|
|
|
}
|
|
|
|
|
2019-02-18 17:28:53 +00:00
|
|
|
ColumnPtr ColumnConst::index(const IColumn & indexes, size_t limit) const
|
2018-04-18 21:00:47 +00:00
|
|
|
{
|
|
|
|
if (limit == 0)
|
2018-06-07 18:14:37 +00:00
|
|
|
limit = indexes.size();
|
2018-04-18 21:00:47 +00:00
|
|
|
|
2018-06-07 18:14:37 +00:00
|
|
|
if (indexes.size() < limit)
|
|
|
|
throw Exception("Size of indexes (" + toString(indexes.size()) + ") is less than required (" + toString(limit) + ")",
|
2018-04-18 21:00:47 +00:00
|
|
|
ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
|
|
|
|
|
|
|
|
return ColumnConst::create(data, limit);
|
|
|
|
}
|
|
|
|
|
2017-12-17 09:01:12 +00:00
|
|
|
MutableColumns ColumnConst::scatter(ColumnIndex num_columns, const Selector & selector) const
|
|
|
|
{
|
|
|
|
if (s != selector.size())
|
|
|
|
throw Exception("Size of selector (" + toString(selector.size()) + ") doesn't match size of column (" + toString(s) + ")",
|
|
|
|
ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
|
|
|
|
|
2018-02-06 19:34:53 +00:00
|
|
|
std::vector<size_t> counts = countColumnsSizeInSelector(num_columns, selector);
|
2017-12-17 09:01:12 +00:00
|
|
|
|
|
|
|
MutableColumns res(num_columns);
|
|
|
|
for (size_t i = 0; i < num_columns; ++i)
|
|
|
|
res[i] = cloneResized(counts[i]);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColumnConst::getPermutation(bool /*reverse*/, size_t /*limit*/, int /*nan_direction_hint*/, Permutation & res) const
|
|
|
|
{
|
|
|
|
res.resize(s);
|
|
|
|
for (size_t i = 0; i < s; ++i)
|
|
|
|
res[i] = i;
|
|
|
|
}
|
|
|
|
|
2020-03-18 16:03:55 +00:00
|
|
|
void ColumnConst::updateWeakHash32(WeakHash32 & hash) const
|
|
|
|
{
|
|
|
|
if (hash.getData().size() != s)
|
|
|
|
throw Exception("Size of WeakHash32 does not match size of column: column size is " + std::to_string(s) +
|
|
|
|
", hash size is " + std::to_string(hash.getData().size()), ErrorCodes::LOGICAL_ERROR);
|
|
|
|
|
|
|
|
WeakHash32 element_hash(1);
|
|
|
|
data->updateWeakHash32(element_hash);
|
|
|
|
size_t data_hash = element_hash.getData()[0];
|
|
|
|
|
|
|
|
for (auto & value : hash.getData())
|
|
|
|
value = intHashCRC32(data_hash, value);
|
|
|
|
}
|
|
|
|
|
2011-11-06 06:22:52 +00:00
|
|
|
}
|