ClickHouse/dbms/src/Columns/ColumnsCommon.h

76 lines
3.0 KiB
C++
Raw Normal View History

#pragma once
#include <Columns/IColumn.h>
2017-03-09 00:56:38 +00:00
/// Common helper methods for implementation of different columns.
namespace DB
{
2018-04-18 21:00:47 +00:00
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
2017-03-09 00:56:38 +00:00
/// Counts how many bytes of `filt` are greater than zero.
size_t countBytesInFilter(const IColumn::Filter & filt);
2018-02-09 15:09:33 +00:00
/// Returns vector with num_columns elements. vector[i] is the count of i values in selector.
/// Selector must contain values from 0 to num_columns - 1. NOTE: this is not checked.
std::vector<size_t> countColumnsSizeInSelector(IColumn::ColumnIndex num_columns, const IColumn::Selector & selector);
2017-06-23 06:45:48 +00:00
/// Returns true, if the memory contains only zeros.
bool memoryIsZero(const void * data, size_t size);
2017-03-09 00:56:38 +00:00
/// The general implementation of `filter` function for ColumnArray and ColumnString.
template <typename T>
void filterArraysImpl(
const PaddedPODArray<T> & src_elems, const IColumn::Offsets & src_offsets,
PaddedPODArray<T> & res_elems, IColumn::Offsets & res_offsets,
const IColumn::Filter & filt, ssize_t result_size_hint);
/// Same as above, but not fills res_offsets.
template <typename T>
void filterArraysImplOnlyData(
const PaddedPODArray<T> & src_elems, const IColumn::Offsets & src_offsets,
PaddedPODArray<T> & res_elems,
const IColumn::Filter & filt, ssize_t result_size_hint);
2018-04-18 21:00:47 +00:00
namespace detail
{
template <typename T>
const PaddedPODArray<T> * getIndexesData(const IColumn & indexes);
2018-04-18 21:00:47 +00:00
}
2019-02-10 15:17:45 +00:00
/// Check limit <= indexes->size() and call column.indexImpl(const PaddedPodArray<Type> & indexes, UInt64 limit).
2018-04-18 21:00:47 +00:00
template <typename Column>
ColumnPtr selectIndexImpl(const Column & column, const IColumn & indexes, size_t limit)
2018-04-18 21:00:47 +00:00
{
if (limit == 0)
limit = indexes.size();
2018-04-18 21:00:47 +00:00
if (indexes.size() < limit)
2018-04-18 21:00:47 +00:00
throw Exception("Size of indexes is less than required.", ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
if (auto * data_uint8 = detail::getIndexesData<UInt8>(indexes))
2018-04-23 16:51:27 +00:00
return column.template indexImpl<UInt8>(*data_uint8, limit);
2018-04-18 21:00:47 +00:00
else if (auto * data_uint16 = detail::getIndexesData<UInt16>(indexes))
2018-04-23 16:51:27 +00:00
return column.template indexImpl<UInt16>(*data_uint16, limit);
2018-04-18 21:00:47 +00:00
else if (auto * data_uint32 = detail::getIndexesData<UInt32>(indexes))
2018-04-23 16:51:27 +00:00
return column.template indexImpl<UInt32>(*data_uint32, limit);
2018-04-18 21:00:47 +00:00
else if (auto * data_uint64 = detail::getIndexesData<UInt64>(indexes))
2018-04-23 16:51:27 +00:00
return column.template indexImpl<UInt64>(*data_uint64, limit);
2018-04-18 21:00:47 +00:00
else
throw Exception("Indexes column for IColumn::select must be ColumnUInt, got" + indexes.getName(),
2018-04-18 21:00:47 +00:00
ErrorCodes::LOGICAL_ERROR);
}
#define INSTANTIATE_INDEX_IMPL(Column) \
template ColumnPtr Column::indexImpl<UInt8>(const PaddedPODArray<UInt8> & indexes, size_t limit) const; \
template ColumnPtr Column::indexImpl<UInt16>(const PaddedPODArray<UInt16> & indexes, size_t limit) const; \
template ColumnPtr Column::indexImpl<UInt32>(const PaddedPODArray<UInt32> & indexes, size_t limit) const; \
template ColumnPtr Column::indexImpl<UInt64>(const PaddedPODArray<UInt64> & indexes, size_t limit) const;
}