2013-05-08 09:54:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-12-07 08:31:47 +00:00
|
|
|
#include <Common/Arena.h>
|
2019-10-07 18:56:03 +00:00
|
|
|
#include <Common/PODArray.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Columns/IColumn.h>
|
|
|
|
#include <Columns/ColumnsCommon.h>
|
2013-05-08 09:54:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2014-08-20 04:57:03 +00:00
|
|
|
|
2016-01-13 00:32:59 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const int SIZES_OF_COLUMNS_DOESNT_MATCH;
|
|
|
|
extern const int NOT_IMPLEMENTED;
|
2016-01-13 00:32:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-09 00:56:38 +00:00
|
|
|
/** Base class for columns-constants that contain a value that is not in the `Field`.
|
|
|
|
* Not a full-fledged column and is used in a special way.
|
2013-05-08 09:54:07 +00:00
|
|
|
*/
|
2017-12-15 02:36:40 +00:00
|
|
|
class IColumnDummy : public IColumn
|
2013-05-08 09:54:07 +00:00
|
|
|
{
|
2017-12-15 02:36:40 +00:00
|
|
|
public:
|
|
|
|
IColumnDummy() : s(0) {}
|
2017-04-01 07:20:54 +00:00
|
|
|
IColumnDummy(size_t s_) : s(s_) {}
|
|
|
|
|
2017-12-14 03:56:56 +00:00
|
|
|
public:
|
|
|
|
virtual MutableColumnPtr cloneDummy(size_t s_) const = 0;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-12-14 03:56:56 +00:00
|
|
|
MutableColumnPtr cloneResized(size_t s_) const override { return cloneDummy(s_); }
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t size() const override { return s; }
|
|
|
|
void insertDefault() override { ++s; }
|
|
|
|
void popBack(size_t n) override { s -= n; }
|
|
|
|
size_t byteSize() const override { return 0; }
|
2017-07-13 16:49:09 +00:00
|
|
|
size_t allocatedBytes() const override { return 0; }
|
2017-12-01 21:13:25 +00:00
|
|
|
int compareAt(size_t, size_t, const IColumn &, int) const override { return 0; }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-12-01 21:13:25 +00:00
|
|
|
Field operator[](size_t) const override { throw Exception("Cannot get value from " + getName(), ErrorCodes::NOT_IMPLEMENTED); }
|
2018-06-03 20:39:06 +00:00
|
|
|
void get(size_t, Field &) const override { throw Exception("Cannot get value from " + getName(), ErrorCodes::NOT_IMPLEMENTED); }
|
2017-12-01 21:13:25 +00:00
|
|
|
void insert(const Field &) override { throw Exception("Cannot insert element into " + getName(), ErrorCodes::NOT_IMPLEMENTED); }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-12-07 08:31:47 +00:00
|
|
|
StringRef getDataAt(size_t) const override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-12-07 08:31:47 +00:00
|
|
|
return {};
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
2017-12-07 08:31:47 +00:00
|
|
|
void insertData(const char *, size_t) override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-12-07 08:31:47 +00:00
|
|
|
++s;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef serializeValueIntoArena(size_t /*n*/, Arena & arena, char const *& begin) const override
|
|
|
|
{
|
|
|
|
return { arena.allocContinue(0, begin), 0 };
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * deserializeAndInsertFromArena(const char * pos) override
|
|
|
|
{
|
|
|
|
++s;
|
|
|
|
return pos;
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 21:13:25 +00:00
|
|
|
void updateHashWithValue(size_t /*n*/, SipHash & /*hash*/) const override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-12-07 08:31:47 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 16:03:55 +00:00
|
|
|
void updateWeakHash32(WeakHash32 & /*hash*/) const override
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-12-07 08:31:47 +00:00
|
|
|
void insertFrom(const IColumn &, size_t) override
|
|
|
|
{
|
|
|
|
++s;
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 21:13:25 +00:00
|
|
|
void insertRangeFrom(const IColumn & /*src*/, size_t /*start*/, size_t length) override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
s += length;
|
|
|
|
}
|
|
|
|
|
2018-03-20 14:17:09 +00:00
|
|
|
ColumnPtr filter(const Filter & filt, ssize_t /*result_size_hint*/) const override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
return cloneDummy(countBytesInFilter(filt));
|
|
|
|
}
|
|
|
|
|
2019-02-18 19:44:26 +00:00
|
|
|
ColumnPtr permute(const Permutation & perm, size_t limit) const override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
if (s != perm.size())
|
|
|
|
throw Exception("Size of permutation doesn't match size of column.", ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
|
|
|
|
|
|
|
|
return cloneDummy(limit ? std::min(s, limit) : s);
|
|
|
|
}
|
|
|
|
|
2019-02-18 17:28:53 +00:00
|
|
|
ColumnPtr index(const IColumn & indexes, size_t limit) const override
|
2018-04-23 16:40:25 +00:00
|
|
|
{
|
2018-06-07 18:14:37 +00:00
|
|
|
if (indexes.size() < limit)
|
2018-04-23 16:40:25 +00:00
|
|
|
throw Exception("Size of indexes is less than required.", ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
|
|
|
|
|
|
|
|
return cloneDummy(limit ? limit : s);
|
|
|
|
}
|
|
|
|
|
2017-12-01 21:13:25 +00:00
|
|
|
void getPermutation(bool /*reverse*/, size_t /*limit*/, int /*nan_direction_hint*/, Permutation & res) const override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
res.resize(s);
|
|
|
|
for (size_t i = 0; i < s; ++i)
|
|
|
|
res[i] = i;
|
|
|
|
}
|
|
|
|
|
2018-03-20 14:17:09 +00:00
|
|
|
ColumnPtr replicate(const Offsets & offsets) const override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
if (s != offsets.size())
|
|
|
|
throw Exception("Size of offsets doesn't match size of column.", ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
|
|
|
|
|
2018-12-24 14:26:38 +00:00
|
|
|
return cloneDummy(offsets.back());
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 03:56:56 +00:00
|
|
|
MutableColumns scatter(ColumnIndex num_columns, const Selector & selector) const override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
if (s != selector.size())
|
|
|
|
throw Exception("Size of selector doesn't match size of column.", ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
|
|
|
|
|
|
|
|
std::vector<size_t> counts(num_columns);
|
|
|
|
for (auto idx : selector)
|
|
|
|
++counts[idx];
|
|
|
|
|
2017-12-14 03:56:56 +00:00
|
|
|
MutableColumns res(num_columns);
|
2017-04-01 07:20:54 +00:00
|
|
|
for (size_t i = 0; i < num_columns; ++i)
|
|
|
|
res[i] = cloneResized(counts[i]);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-07-06 13:54:55 +00:00
|
|
|
void gather(ColumnGathererStream &) override
|
|
|
|
{
|
|
|
|
throw Exception("Method gather is not supported for " + getName(), ErrorCodes::NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
2017-12-01 21:13:25 +00:00
|
|
|
void getExtremes(Field &, Field &) const override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-12-07 08:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void addSize(size_t delta)
|
|
|
|
{
|
|
|
|
s += delta;
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2016-07-05 16:23:37 +00:00
|
|
|
|
2017-12-09 10:14:45 +00:00
|
|
|
bool isDummy() const override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-15 02:36:40 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t s;
|
2013-05-08 09:54:07 +00:00
|
|
|
};
|
2014-08-20 04:57:03 +00:00
|
|
|
|
2013-05-08 09:54:07 +00:00
|
|
|
}
|