ClickHouse/dbms/include/DB/Functions/Conditional/CondSource.h

59 lines
1.4 KiB
C++
Raw Normal View History

2016-04-18 14:31:32 +00:00
#pragma once
#include <DB/Common/PODArray.h>
#include <DB/Core/Block.h>
#include <DB/Core/ColumnNumbers.h>
namespace DB
{
namespace Conditional
{
/// This class provides access to the values of a condition in a multiIf function.
class CondSource final
{
public:
CondSource(const Block & block, const ColumnNumbers & args, size_t i);
CondSource(const CondSource &) = delete;
CondSource & operator=(const CondSource &) = delete;
CondSource(CondSource &&) = default;
CondSource & operator=(CondSource &&) = default;
/// Get the value of this condition for a given row.
inline bool get(size_t row) const
2016-04-18 14:31:32 +00:00
{
bool is_null = !null_map.empty() ? (null_map[row] != 0) : false;
return is_null ? false : static_cast<bool>(data_array[row]);
2016-04-18 14:31:32 +00:00
}
2016-05-05 12:00:14 +00:00
inline size_t getSize() const
{
return data_array.size();
}
2016-04-18 14:31:32 +00:00
private:
static const ColumnPtr initMaterializedCol(const Block & block, const ColumnNumbers & args, size_t i);
static const PaddedPODArray<UInt8> & initDataArray(const Block & block, const ColumnNumbers & args,
size_t i, const ColumnPtr & materialized_col_);
static const PaddedPODArray<UInt8> & initNullMap(const Block & block, const ColumnNumbers & args, size_t i);
2016-04-18 14:31:32 +00:00
private:
const ColumnPtr materialized_col;
const PaddedPODArray<UInt8> & data_array;
const PaddedPODArray<UInt8> & null_map;
2016-04-18 14:31:32 +00:00
static const ColumnPtr null_materialized_col;
static const PaddedPODArray<UInt8> empty_null_map;
2016-04-18 14:31:32 +00:00
};
using CondSources = std::vector<CondSource>;
}
}