ClickHouse/src/Functions/if.cpp

998 lines
43 KiB
C++
Raw Normal View History

#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/DataTypesDecimal.h>
#include <DataTypes/DataTypeArray.h>
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypeFixedString.h>
#include <DataTypes/DataTypeTuple.h>
#include <DataTypes/DataTypeNullable.h>
2019-02-10 17:40:52 +00:00
#include <DataTypes/NumberTraits.h>
#include <DataTypes/getLeastSupertype.h>
#include <Columns/ColumnVector.h>
#include <Columns/ColumnDecimal.h>
#include <Columns/ColumnString.h>
#include <Columns/ColumnConst.h>
#include <Columns/ColumnArray.h>
#include <Columns/ColumnFixedString.h>
#include <Columns/ColumnTuple.h>
#include <Columns/ColumnNullable.h>
2017-07-13 20:58:19 +00:00
#include <Common/typeid_cast.h>
#include <Common/assert_cast.h>
#include <Functions/IFunctionImpl.h>
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
#include <Functions/FunctionHelpers.h>
#include <Functions/GatherUtils/GatherUtils.h>
#include <Functions/GatherUtils/Algorithms.h>
#include <Functions/FunctionIfBase.h>
#include <Functions/FunctionFactory.h>
2019-02-03 08:41:25 +00:00
#include <Interpreters/castColumn.h>
namespace DB
{
namespace ErrorCodes
{
2020-02-25 18:02:41 +00:00
extern const int ILLEGAL_COLUMN;
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
extern const int NOT_IMPLEMENTED;
}
using namespace GatherUtils;
2017-05-27 15:45:25 +00:00
/** Selection function by condition: if(cond, then, else).
* cond - UInt8
2017-05-27 15:45:25 +00:00
* then, else - numeric types for which there is a general type, or dates, datetimes, or strings, or arrays of these types.
*/
template <typename A, typename B, typename ResultType>
struct NumIfImpl
{
using ArrayCond = PaddedPODArray<UInt8>;
using ArrayA = PaddedPODArray<A>;
using ArrayB = PaddedPODArray<B>;
using ColVecResult = ColumnVector<ResultType>;
static void vectorVector(const ArrayCond & cond, const ArrayA & a, const ArrayB & b, Block & block, size_t result, UInt32)
{
size_t size = cond.size();
auto col_res = ColVecResult::create(size);
typename ColVecResult::Container & res = col_res->getData();
for (size_t i = 0; i < size; ++i)
res[i] = cond[i] ? static_cast<ResultType>(a[i]) : static_cast<ResultType>(b[i]);
block.getByPosition(result).column = std::move(col_res);
}
static void vectorConstant(const ArrayCond & cond, const ArrayA & a, B b, Block & block, size_t result, UInt32)
{
size_t size = cond.size();
auto col_res = ColVecResult::create(size);
typename ColVecResult::Container & res = col_res->getData();
for (size_t i = 0; i < size; ++i)
res[i] = cond[i] ? static_cast<ResultType>(a[i]) : static_cast<ResultType>(b);
block.getByPosition(result).column = std::move(col_res);
}
static void constantVector(const ArrayCond & cond, A a, const ArrayB & b, Block & block, size_t result, UInt32)
{
size_t size = cond.size();
auto col_res = ColVecResult::create(size);
typename ColVecResult::Container & res = col_res->getData();
for (size_t i = 0; i < size; ++i)
res[i] = cond[i] ? static_cast<ResultType>(a) : static_cast<ResultType>(b[i]);
block.getByPosition(result).column = std::move(col_res);
}
static void constantConstant(const ArrayCond & cond, A a, B b, Block & block, size_t result, UInt32)
{
size_t size = cond.size();
auto col_res = ColVecResult::create(size);
typename ColVecResult::Container & res = col_res->getData();
for (size_t i = 0; i < size; ++i)
res[i] = cond[i] ? static_cast<ResultType>(a) : static_cast<ResultType>(b);
block.getByPosition(result).column = std::move(col_res);
}
};
template <typename A, typename B, typename R>
struct NumIfImpl<Decimal<A>, Decimal<B>, Decimal<R>>
{
using ResultType = Decimal<R>;
using ArrayCond = PaddedPODArray<UInt8>;
using ArrayA = DecimalPaddedPODArray<Decimal<A>>;
using ArrayB = DecimalPaddedPODArray<Decimal<B>>;
using ColVecResult = ColumnDecimal<ResultType>;
static void vectorVector(const ArrayCond & cond, const ArrayA & a, const ArrayB & b, Block & block, size_t result, UInt32 scale)
{
size_t size = cond.size();
auto col_res = ColVecResult::create(size, scale);
typename ColVecResult::Container & res = col_res->getData();
for (size_t i = 0; i < size; ++i)
res[i] = cond[i] ? static_cast<ResultType>(a[i]) : static_cast<ResultType>(b[i]);
block.getByPosition(result).column = std::move(col_res);
}
static void vectorConstant(const ArrayCond & cond, const ArrayA & a, B b, Block & block, size_t result, UInt32 scale)
{
size_t size = cond.size();
auto col_res = ColVecResult::create(size, scale);
typename ColVecResult::Container & res = col_res->getData();
for (size_t i = 0; i < size; ++i)
res[i] = cond[i] ? static_cast<ResultType>(a[i]) : static_cast<ResultType>(b);
block.getByPosition(result).column = std::move(col_res);
}
static void constantVector(const ArrayCond & cond, A a, const ArrayB & b, Block & block, size_t result, UInt32 scale)
{
size_t size = cond.size();
auto col_res = ColVecResult::create(size, scale);
typename ColVecResult::Container & res = col_res->getData();
for (size_t i = 0; i < size; ++i)
res[i] = cond[i] ? static_cast<ResultType>(a) : static_cast<ResultType>(b[i]);
block.getByPosition(result).column = std::move(col_res);
}
static void constantConstant(const ArrayCond & cond, A a, B b, Block & block, size_t result, UInt32 scale)
{
size_t size = cond.size();
auto col_res = ColVecResult::create(size, scale);
typename ColVecResult::Container & res = col_res->getData();
for (size_t i = 0; i < size; ++i)
res[i] = cond[i] ? static_cast<ResultType>(a) : static_cast<ResultType>(b);
block.getByPosition(result).column = std::move(col_res);
}
};
template <typename A, typename B>
struct NumIfImpl<A, B, NumberTraits::Error>
{
private:
[[noreturn]] static void throwError()
{
throw Exception("Internal logic error: invalid types of arguments 2 and 3 of if", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
}
public:
template <typename... Args> static void vectorVector(Args &&...) { throwError(); }
template <typename... Args> static void vectorConstant(Args &&...) { throwError(); }
template <typename... Args> static void constantVector(Args &&...) { throwError(); }
template <typename... Args> static void constantConstant(Args &&...) { throwError(); }
};
class FunctionIf : public FunctionIfBase</*null_is_false=*/false>
{
public:
static constexpr auto name = "if";
2020-04-14 21:05:45 +00:00
static FunctionPtr create(const Context &) { return std::make_shared<FunctionIf>(); }
private:
2018-10-12 11:23:05 +00:00
template <typename T0, typename T1>
static constexpr bool allow_arrays = !std::is_same_v<T0, UInt128> && !std::is_same_v<T1, UInt128>;
2018-10-12 11:23:05 +00:00
template <typename T0, typename T1>
static UInt32 decimalScale(Block & block [[maybe_unused]], const ColumnNumbers & arguments [[maybe_unused]])
{
if constexpr (IsDecimalNumber<T0> && IsDecimalNumber<T1>)
{
UInt32 left_scale = getDecimalScale(*block.getByPosition(arguments[1]).type);
UInt32 right_scale = getDecimalScale(*block.getByPosition(arguments[2]).type);
if (left_scale != right_scale)
throw Exception("Conditional functions with different Decimal scales", ErrorCodes::NOT_IMPLEMENTED);
return left_scale;
}
else
return std::numeric_limits<UInt32>::max();
}
template <typename T0, typename T1, typename ColVecT0, typename ColVecT1>
bool executeRightType(
const ColumnUInt8 * cond_col,
Block & block,
const ColumnNumbers & arguments,
size_t result,
const ColVecT0 * col_left)
{
using ResultType = typename NumberTraits::ResultOfIf<T0, T1>::Type;
const IColumn * col_right_untyped = block.getByPosition(arguments[2]).column.get();
UInt32 scale = decimalScale<T0, T1>(block, arguments);
2020-04-22 08:31:10 +00:00
if (const auto * col_right_vec = checkAndGetColumn<ColVecT1>(col_right_untyped))
{
NumIfImpl<T0, T1, ResultType>::vectorVector(
cond_col->getData(), col_left->getData(), col_right_vec->getData(), block, result, scale);
return true;
}
2020-04-22 08:31:10 +00:00
else if (const auto * col_right_const = checkAndGetColumnConst<ColVecT1>(col_right_untyped))
{
NumIfImpl<T0, T1, ResultType>::vectorConstant(
cond_col->getData(), col_left->getData(), col_right_const->template getValue<T1>(), block, result, scale);
return true;
}
return false;
}
template <typename T0, typename T1, typename ColVecT0, typename ColVecT1>
bool executeConstRightType(
const ColumnUInt8 * cond_col,
Block & block,
const ColumnNumbers & arguments,
size_t result,
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
const ColumnConst * col_left)
{
using ResultType = typename NumberTraits::ResultOfIf<T0, T1>::Type;
const IColumn * col_right_untyped = block.getByPosition(arguments[2]).column.get();
UInt32 scale = decimalScale<T0, T1>(block, arguments);
2020-04-22 08:45:14 +00:00
if (const auto * col_right_vec = checkAndGetColumn<ColVecT1>(col_right_untyped))
{
NumIfImpl<T0, T1, ResultType>::constantVector(
cond_col->getData(), col_left->template getValue<T0>(), col_right_vec->getData(), block, result, scale);
return true;
}
2020-04-22 08:45:14 +00:00
else if (const auto * col_right_const = checkAndGetColumnConst<ColVecT1>(col_right_untyped))
{
NumIfImpl<T0, T1, ResultType>::constantConstant(
cond_col->getData(), col_left->template getValue<T0>(), col_right_const->template getValue<T1>(), block, result, scale);
return true;
}
return false;
}
template <typename T0, typename T1, typename ColVecT0, typename ColVecT1>
2017-12-02 02:47:12 +00:00
bool executeRightTypeArray(
2017-12-02 03:34:45 +00:00
[[maybe_unused]] const ColumnUInt8 * cond_col,
[[maybe_unused]] Block & block,
[[maybe_unused]] const ColumnNumbers & arguments,
[[maybe_unused]] size_t result,
2018-04-24 07:16:39 +00:00
[[maybe_unused]] const ColumnArray * col_left_array,
[[maybe_unused]] size_t input_rows_count)
{
2017-12-25 04:01:46 +00:00
if constexpr (std::is_same_v<NumberTraits::Error, typename NumberTraits::ResultOfIf<T0, T1>::Type>)
2017-12-02 02:47:12 +00:00
return false;
2018-10-12 11:23:05 +00:00
else if constexpr (allow_arrays<T0, T1>)
2017-12-02 02:47:12 +00:00
{
using ResultType = typename NumberTraits::ResultOfIf<T0, T1>::Type;
const IColumn * col_right_untyped = block.getByPosition(arguments[2]).column.get();
2020-04-22 08:31:10 +00:00
if (const auto * col_right_array = checkAndGetColumn<ColumnArray>(col_right_untyped))
{
const ColVecT1 * col_right_vec = checkAndGetColumn<ColVecT1>(&col_right_array->getData());
2017-12-02 02:47:12 +00:00
if (!col_right_vec)
return false;
auto res = block.getByPosition(result).type->createColumn();
2017-12-02 02:47:12 +00:00
conditional(
NumericArraySource<T0>(*col_left_array),
NumericArraySource<T1>(*col_right_array),
NumericArraySink<ResultType>(assert_cast<ColumnArray &>(*res), input_rows_count),
2017-12-02 02:47:12 +00:00
cond_col->getData());
block.getByPosition(result).column = std::move(res);
return true;
2017-12-02 02:47:12 +00:00
}
2020-04-22 08:31:10 +00:00
else if (const auto * col_right_const_array = checkAndGetColumnConst<ColumnArray>(col_right_untyped))
2017-12-02 02:47:12 +00:00
{
const ColumnArray * col_right_const_array_data = checkAndGetColumn<ColumnArray>(&col_right_const_array->getDataColumn());
if (!checkColumn<ColVecT1>(&col_right_const_array_data->getData()))
2017-12-02 02:47:12 +00:00
return false;
auto res = block.getByPosition(result).type->createColumn();
2017-12-02 02:47:12 +00:00
conditional(
NumericArraySource<T0>(*col_left_array),
ConstSource<NumericArraySource<T1>>(*col_right_const_array),
NumericArraySink<ResultType>(assert_cast<ColumnArray &>(*res), input_rows_count),
2017-12-02 02:47:12 +00:00
cond_col->getData());
block.getByPosition(result).column = std::move(res);
return true;
2017-12-02 02:47:12 +00:00
}
}
return false;
}
template <typename T0, typename T1, typename ColVecT0, typename ColVecT1>
2017-12-02 02:47:12 +00:00
bool executeConstRightTypeArray(
2017-12-02 03:36:52 +00:00
[[maybe_unused]] const ColumnUInt8 * cond_col,
[[maybe_unused]] Block & block,
[[maybe_unused]] const ColumnNumbers & arguments,
[[maybe_unused]] size_t result,
2018-04-24 07:16:39 +00:00
[[maybe_unused]] const ColumnConst * col_left_const_array,
[[maybe_unused]] size_t input_rows_count)
{
2017-12-25 04:01:46 +00:00
if constexpr (std::is_same_v<NumberTraits::Error, typename NumberTraits::ResultOfIf<T0, T1>::Type>)
return false;
2018-10-12 11:23:05 +00:00
else if constexpr (allow_arrays<T0, T1>)
{
2017-12-02 02:47:12 +00:00
using ResultType = typename NumberTraits::ResultOfIf<T0, T1>::Type;
const IColumn * col_right_untyped = block.getByPosition(arguments[2]).column.get();
2020-04-22 08:31:10 +00:00
if (const auto * col_right_array = checkAndGetColumn<ColumnArray>(col_right_untyped))
2017-12-02 02:47:12 +00:00
{
const ColVecT1 * col_right_vec = checkAndGetColumn<ColVecT1>(&col_right_array->getData());
2017-12-02 02:47:12 +00:00
if (!col_right_vec)
return false;
auto res = block.getByPosition(result).type->createColumn();
2017-12-02 02:47:12 +00:00
conditional(
ConstSource<NumericArraySource<T0>>(*col_left_const_array),
NumericArraySource<T1>(*col_right_array),
NumericArraySink<ResultType>(assert_cast<ColumnArray &>(*res), input_rows_count),
2017-12-02 02:47:12 +00:00
cond_col->getData());
block.getByPosition(result).column = std::move(res);
return true;
2017-12-02 02:47:12 +00:00
}
2020-04-22 08:31:10 +00:00
else if (const auto * col_right_const_array = checkAndGetColumnConst<ColumnArray>(col_right_untyped))
2017-12-02 02:47:12 +00:00
{
const ColumnArray * col_right_const_array_data = checkAndGetColumn<ColumnArray>(&col_right_const_array->getDataColumn());
if (!checkColumn<ColVecT1>(&col_right_const_array_data->getData()))
2017-12-02 02:47:12 +00:00
return false;
auto res = block.getByPosition(result).type->createColumn();
2017-12-02 02:47:12 +00:00
conditional(
ConstSource<NumericArraySource<T0>>(*col_left_const_array),
ConstSource<NumericArraySource<T1>>(*col_right_const_array),
NumericArraySink<ResultType>(assert_cast<ColumnArray &>(*res), input_rows_count),
2017-12-02 02:47:12 +00:00
cond_col->getData());
block.getByPosition(result).column = std::move(res);
return true;
2017-12-02 02:47:12 +00:00
}
}
return false;
}
template <typename T0, typename T1>
bool executeTyped(const ColumnUInt8 * cond_col, Block & block, const ColumnNumbers & arguments, size_t result, size_t input_rows_count)
{
using ColVecT0 = std::conditional_t<IsDecimalNumber<T0>, ColumnDecimal<T0>, ColumnVector<T0>>;
using ColVecT1 = std::conditional_t<IsDecimalNumber<T1>, ColumnDecimal<T1>, ColumnVector<T1>>;
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
const IColumn * col_left_untyped = block.getByPosition(arguments[1]).column.get();
bool left_ok = false;
bool right_ok = false;
2020-04-22 08:31:10 +00:00
if (const auto * col_left = checkAndGetColumn<ColVecT0>(col_left_untyped))
{
left_ok = true;
right_ok = executeRightType<T0, T1, ColVecT0, ColVecT1>(cond_col, block, arguments, result, col_left);
}
2020-04-22 08:31:10 +00:00
else if (const auto * col_const_left = checkAndGetColumnConst<ColVecT0>(col_left_untyped))
{
left_ok = true;
right_ok = executeConstRightType<T0, T1, ColVecT0, ColVecT1>(cond_col, block, arguments, result, col_const_left);
}
2020-04-22 08:31:10 +00:00
else if (const auto * col_arr_left = checkAndGetColumn<ColumnArray>(col_left_untyped))
{
if (auto col_arr_left_elems = checkAndGetColumn<ColVecT0>(&col_arr_left->getData()))
{
left_ok = true;
right_ok = executeRightTypeArray<T0, T1, ColVecT0, ColVecT1>(
cond_col, block, arguments, result, col_arr_left, input_rows_count);
}
}
2020-04-22 08:31:10 +00:00
else if (const auto * col_const_arr_left = checkAndGetColumnConst<ColumnArray>(col_left_untyped))
{
if (checkColumn<ColVecT0>(&assert_cast<const ColumnArray &>(col_const_arr_left->getDataColumn()).getData()))
{
left_ok = true;
right_ok = executeConstRightTypeArray<T0, T1, ColVecT0, ColVecT1>(
cond_col, block, arguments, result, col_const_arr_left, input_rows_count);
}
}
if (!left_ok)
return false;
ColumnWithTypeAndName & right_column_typed = block.getByPosition(arguments[2]);
if (!right_ok)
throw Exception("Illegal column " + right_column_typed.column->getName() + " of third argument of function " + getName(),
ErrorCodes::ILLEGAL_COLUMN);
return true;
}
2020-03-18 00:57:00 +00:00
static bool executeString(const ColumnUInt8 * cond_col, Block & block, const ColumnNumbers & arguments, size_t result)
{
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
const IColumn * col_then_untyped = block.getByPosition(arguments[1]).column.get();
const IColumn * col_else_untyped = block.getByPosition(arguments[2]).column.get();
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
const ColumnString * col_then = checkAndGetColumn<ColumnString>(col_then_untyped);
const ColumnString * col_else = checkAndGetColumn<ColumnString>(col_else_untyped);
const ColumnFixedString * col_then_fixed = checkAndGetColumn<ColumnFixedString>(col_then_untyped);
const ColumnFixedString * col_else_fixed = checkAndGetColumn<ColumnFixedString>(col_else_untyped);
const ColumnConst * col_then_const = checkAndGetColumnConst<ColumnString>(col_then_untyped);
const ColumnConst * col_else_const = checkAndGetColumnConst<ColumnString>(col_else_untyped);
const ColumnConst * col_then_const_fixed = checkAndGetColumnConst<ColumnFixedString>(col_then_untyped);
const ColumnConst * col_else_const_fixed = checkAndGetColumnConst<ColumnFixedString>(col_else_untyped);
const PaddedPODArray<UInt8> & cond_data = cond_col->getData();
size_t rows = cond_data.size();
if ((col_then_fixed || col_then_const_fixed)
&& (col_else_fixed || col_else_const_fixed))
{
/// The result is FixedString.
auto col_res_untyped = block.getByPosition(result).type->createColumn();
ColumnFixedString * col_res = assert_cast<ColumnFixedString *>(col_res_untyped.get());
auto sink = FixedStringSink(*col_res, rows);
if (col_then_fixed && col_else_fixed)
conditional(FixedStringSource(*col_then_fixed), FixedStringSource(*col_else_fixed), sink, cond_data);
else if (col_then_fixed && col_else_const_fixed)
conditional(FixedStringSource(*col_then_fixed), ConstSource<FixedStringSource>(*col_else_const_fixed), sink, cond_data);
else if (col_then_const_fixed && col_else_fixed)
conditional(ConstSource<FixedStringSource>(*col_then_const_fixed), FixedStringSource(*col_else_fixed), sink, cond_data);
else if (col_then_const_fixed && col_else_const_fixed)
conditional(ConstSource<FixedStringSource>(*col_then_const_fixed), ConstSource<FixedStringSource>(*col_else_const_fixed), sink, cond_data);
block.getByPosition(result).column = std::move(col_res_untyped);
return true;
}
if ((col_then || col_then_const || col_then_fixed || col_then_const_fixed)
&& (col_else || col_else_const || col_else_fixed || col_else_const_fixed))
{
/// The result is String.
auto col_res = ColumnString::create();
auto sink = StringSink(*col_res, rows);
if (col_then && col_else)
conditional(StringSource(*col_then), StringSource(*col_else), sink, cond_data);
else if (col_then && col_else_const)
conditional(StringSource(*col_then), ConstSource<StringSource>(*col_else_const), sink, cond_data);
else if (col_then_const && col_else)
conditional(ConstSource<StringSource>(*col_then_const), StringSource(*col_else), sink, cond_data);
else if (col_then_const && col_else_const)
conditional(ConstSource<StringSource>(*col_then_const), ConstSource<StringSource>(*col_else_const), sink, cond_data);
else if (col_then && col_else_fixed)
conditional(StringSource(*col_then), FixedStringSource(*col_else_fixed), sink, cond_data);
else if (col_then_fixed && col_else)
conditional(FixedStringSource(*col_then_fixed), StringSource(*col_else), sink, cond_data);
else if (col_then_const && col_else_fixed)
conditional(ConstSource<StringSource>(*col_then_const), FixedStringSource(*col_else_fixed), sink, cond_data);
else if (col_then_fixed && col_else_const)
conditional(FixedStringSource(*col_then_fixed), ConstSource<StringSource>(*col_else_const), sink, cond_data);
else if (col_then && col_else_const_fixed)
conditional(StringSource(*col_then), ConstSource<FixedStringSource>(*col_else_const_fixed), sink, cond_data);
else if (col_then_const_fixed && col_else)
conditional(ConstSource<FixedStringSource>(*col_then_const_fixed), StringSource(*col_else), sink, cond_data);
else if (col_then_const && col_else_const_fixed)
conditional(ConstSource<StringSource>(*col_then_const), ConstSource<FixedStringSource>(*col_else_const_fixed), sink, cond_data);
else if (col_then_const_fixed && col_else_const)
conditional(ConstSource<FixedStringSource>(*col_then_const_fixed), ConstSource<StringSource>(*col_else_const), sink, cond_data);
block.getByPosition(result).column = std::move(col_res);
return true;
}
return false;
}
2020-03-18 00:57:00 +00:00
static bool executeGenericArray(const ColumnUInt8 * cond_col, Block & block, const ColumnNumbers & arguments, size_t result)
{
/// For generic implementation, arrays must be of same type.
if (!block.getByPosition(arguments[1]).type->equals(*block.getByPosition(arguments[2]).type))
return false;
const IColumn * col_then_untyped = block.getByPosition(arguments[1]).column.get();
const IColumn * col_else_untyped = block.getByPosition(arguments[2]).column.get();
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
const ColumnArray * col_arr_then = checkAndGetColumn<ColumnArray>(col_then_untyped);
const ColumnArray * col_arr_else = checkAndGetColumn<ColumnArray>(col_else_untyped);
const ColumnConst * col_arr_then_const = checkAndGetColumnConst<ColumnArray>(col_then_untyped);
const ColumnConst * col_arr_else_const = checkAndGetColumnConst<ColumnArray>(col_else_untyped);
const PaddedPODArray<UInt8> & cond_data = cond_col->getData();
size_t rows = cond_data.size();
if ((col_arr_then || col_arr_then_const)
&& (col_arr_else || col_arr_else_const))
{
auto res = block.getByPosition(result).type->createColumn();
2020-04-22 08:31:10 +00:00
auto * col_res = assert_cast<ColumnArray *>(res.get());
if (col_arr_then && col_arr_else)
conditional(GenericArraySource(*col_arr_then), GenericArraySource(*col_arr_else), GenericArraySink(*col_res, rows), cond_data);
else if (col_arr_then && col_arr_else_const)
conditional(GenericArraySource(*col_arr_then), ConstSource<GenericArraySource>(*col_arr_else_const), GenericArraySink(*col_res, rows), cond_data);
else if (col_arr_then_const && col_arr_else)
conditional(ConstSource<GenericArraySource>(*col_arr_then_const), GenericArraySource(*col_arr_else), GenericArraySink(*col_res, rows), cond_data);
else if (col_arr_then_const && col_arr_else_const)
conditional(ConstSource<GenericArraySource>(*col_arr_then_const), ConstSource<GenericArraySource>(*col_arr_else_const), GenericArraySink(*col_res, rows), cond_data);
else
return false;
block.getByPosition(result).column = std::move(res);
return true;
}
return false;
}
2018-04-24 07:16:39 +00:00
bool executeTuple(Block & block, const ColumnNumbers & arguments, size_t result, size_t input_rows_count)
{
/// Calculate function for each corresponding elements of tuples.
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
const ColumnWithTypeAndName & arg1 = block.getByPosition(arguments[1]);
const ColumnWithTypeAndName & arg2 = block.getByPosition(arguments[2]);
Columns col1_contents;
Columns col2_contents;
if (const ColumnTuple * tuple1 = typeid_cast<const ColumnTuple *>(arg1.column.get()))
col1_contents = tuple1->getColumnsCopy();
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
else if (const ColumnConst * const_tuple = checkAndGetColumnConst<ColumnTuple>(arg1.column.get()))
col1_contents = convertConstTupleToConstantElements(*const_tuple);
else
return false;
if (const ColumnTuple * tuple2 = typeid_cast<const ColumnTuple *>(arg2.column.get()))
col2_contents = tuple2->getColumnsCopy();
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
else if (const ColumnConst * const_tuple = checkAndGetColumnConst<ColumnTuple>(arg2.column.get()))
col2_contents = convertConstTupleToConstantElements(*const_tuple);
else
return false;
const DataTypeTuple & type1 = static_cast<const DataTypeTuple &>(*arg1.type);
const DataTypeTuple & type2 = static_cast<const DataTypeTuple &>(*arg2.type);
Block temporary_block;
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
temporary_block.insert(block.getByPosition(arguments[0]));
size_t tuple_size = type1.getElements().size();
Columns tuple_columns(tuple_size);
for (size_t i = 0; i < tuple_size; ++i)
{
temporary_block.insert({nullptr,
getReturnTypeImpl({std::make_shared<DataTypeUInt8>(), type1.getElements()[i], type2.getElements()[i]}),
{}});
temporary_block.insert({col1_contents[i], type1.getElements()[i], {}});
temporary_block.insert({col2_contents[i], type2.getElements()[i], {}});
/// temporary_block will be: cond, res_0, ..., res_i, then_i, else_i
2018-04-24 07:16:39 +00:00
executeImpl(temporary_block, {0, i + 2, i + 3}, i + 1, input_rows_count);
temporary_block.erase(i + 3);
temporary_block.erase(i + 2);
tuple_columns[i] = temporary_block.getByPosition(i + 1).column;
}
/// temporary_block is: cond, res_0, res_1, res_2...
block.getByPosition(result).column = ColumnTuple::create(tuple_columns);
return true;
}
2020-04-15 10:12:03 +00:00
static void executeGeneric(const ColumnUInt8 * cond_col, Block & block, const ColumnNumbers & arguments, size_t result, size_t input_rows_count)
2019-02-03 08:41:25 +00:00
{
/// Convert both columns to the common type (if needed).
const ColumnWithTypeAndName & arg1 = block.getByPosition(arguments[1]);
const ColumnWithTypeAndName & arg2 = block.getByPosition(arguments[2]);
DataTypePtr common_type = getLeastSupertype({arg1.type, arg2.type});
2020-04-14 21:05:45 +00:00
ColumnPtr col_then = castColumn(arg1, common_type);
ColumnPtr col_else = castColumn(arg2, common_type);
2019-02-03 08:41:25 +00:00
MutableColumnPtr result_column = common_type->createColumn();
result_column->reserve(input_rows_count);
bool then_is_const = isColumnConst(*col_then);
bool else_is_const = isColumnConst(*col_else);
2019-02-03 08:41:25 +00:00
const auto & cond_array = cond_col->getData();
if (then_is_const && else_is_const)
{
const IColumn & then_nested_column = assert_cast<const ColumnConst &>(*col_then).getDataColumn();
const IColumn & else_nested_column = assert_cast<const ColumnConst &>(*col_else).getDataColumn();
2019-02-03 08:41:25 +00:00
for (size_t i = 0; i < input_rows_count; ++i)
{
if (cond_array[i])
result_column->insertFrom(then_nested_column, 0);
else
result_column->insertFrom(else_nested_column, 0);
}
}
else if (then_is_const)
{
const IColumn & then_nested_column = assert_cast<const ColumnConst &>(*col_then).getDataColumn();
2019-02-03 08:41:25 +00:00
for (size_t i = 0; i < input_rows_count; ++i)
{
if (cond_array[i])
result_column->insertFrom(then_nested_column, 0);
else
result_column->insertFrom(*col_else, i);
}
}
else if (else_is_const)
{
const IColumn & else_nested_column = assert_cast<const ColumnConst &>(*col_else).getDataColumn();
2019-02-03 08:41:25 +00:00
for (size_t i = 0; i < input_rows_count; ++i)
{
if (cond_array[i])
result_column->insertFrom(*col_then, i);
else
result_column->insertFrom(else_nested_column, 0);
}
}
else
{
for (size_t i = 0; i < input_rows_count; ++i)
result_column->insertFrom(cond_array[i] ? *col_then : *col_else, i);
}
block.getByPosition(result).column = std::move(result_column);
}
2019-05-10 10:42:00 +00:00
bool executeForNullableCondition(Block & block, const ColumnNumbers & arguments, size_t result, size_t /*input_rows_count*/)
{
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
const ColumnWithTypeAndName & arg_cond = block.getByPosition(arguments[0]);
bool cond_is_null = arg_cond.column->onlyNull();
if (cond_is_null)
{
2019-05-10 10:42:00 +00:00
block.getByPosition(result).column = std::move(block.getByPosition(arguments[2]).column);
return true;
}
2020-04-22 08:31:10 +00:00
if (const auto * nullable = checkAndGetColumn<ColumnNullable>(*arg_cond.column))
{
Block temporary_block
{
2019-06-26 17:20:33 +00:00
{ nullable->getNestedColumnPtr(), removeNullable(arg_cond.type), arg_cond.name },
block.getByPosition(arguments[1]),
block.getByPosition(arguments[2]),
block.getByPosition(result)
};
2018-04-24 07:16:39 +00:00
executeImpl(temporary_block, {0, 1, 2}, 3, temporary_block.rows());
2019-05-10 10:42:00 +00:00
block.getByPosition(result).column = std::move(temporary_block.getByPosition(3).column);
return true;
}
return false;
}
static ColumnPtr materializeColumnIfConst(const ColumnPtr & column)
{
return column->convertToFullColumnIfConst();
}
static ColumnPtr makeNullableColumnIfNot(const ColumnPtr & column)
{
2019-07-01 11:44:19 +00:00
if (isColumnNullable(*column))
return column;
return ColumnNullable::create(
materializeColumnIfConst(column), ColumnUInt8::create(column->size(), 0));
}
static ColumnPtr getNestedColumn(const ColumnPtr & column)
{
2020-04-22 08:31:10 +00:00
if (const auto * nullable = checkAndGetColumn<ColumnNullable>(*column))
2019-06-26 17:20:33 +00:00
return nullable->getNestedColumnPtr();
return column;
}
2018-04-24 07:16:39 +00:00
bool executeForNullableThenElse(Block & block, const ColumnNumbers & arguments, size_t result, size_t input_rows_count)
{
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
const ColumnWithTypeAndName & arg_cond = block.getByPosition(arguments[0]);
const ColumnWithTypeAndName & arg_then = block.getByPosition(arguments[1]);
const ColumnWithTypeAndName & arg_else = block.getByPosition(arguments[2]);
2020-04-22 08:31:10 +00:00
const auto * then_is_nullable = checkAndGetColumn<ColumnNullable>(*arg_then.column);
const auto * else_is_nullable = checkAndGetColumn<ColumnNullable>(*arg_else.column);
if (!then_is_nullable && !else_is_nullable)
return false;
/** Calculate null mask of result and nested column separately.
*/
ColumnPtr result_null_mask;
{
Block temporary_block(
{
arg_cond,
{
then_is_nullable
2019-06-26 17:20:33 +00:00
? then_is_nullable->getNullMapColumnPtr()
2018-04-24 07:16:39 +00:00
: DataTypeUInt8().createColumnConstWithDefaultValue(input_rows_count),
std::make_shared<DataTypeUInt8>(),
""
},
{
else_is_nullable
2019-06-26 17:20:33 +00:00
? else_is_nullable->getNullMapColumnPtr()
2018-04-24 07:16:39 +00:00
: DataTypeUInt8().createColumnConstWithDefaultValue(input_rows_count),
std::make_shared<DataTypeUInt8>(),
""
},
{
nullptr,
std::make_shared<DataTypeUInt8>(),
""
}
});
2018-04-24 07:16:39 +00:00
executeImpl(temporary_block, {0, 1, 2}, 3, temporary_block.rows());
result_null_mask = temporary_block.getByPosition(3).column;
}
ColumnPtr result_nested_column;
{
Block temporary_block(
{
arg_cond,
{
getNestedColumn(arg_then.column),
removeNullable(arg_then.type),
""
},
{
getNestedColumn(arg_else.column),
removeNullable(arg_else.type),
""
},
{
nullptr,
removeNullable(block.getByPosition(result).type),
""
}
});
2018-04-24 07:16:39 +00:00
executeImpl(temporary_block, {0, 1, 2}, 3, temporary_block.rows());
result_nested_column = temporary_block.getByPosition(3).column;
}
block.getByPosition(result).column = ColumnNullable::create(
materializeColumnIfConst(result_nested_column), materializeColumnIfConst(result_null_mask));
return true;
}
2020-04-22 08:31:10 +00:00
bool executeForNullThenElse(Block & block, const ColumnNumbers & arguments, size_t result, size_t input_rows_count) const
{
const ColumnWithTypeAndName & arg_cond = block.getByPosition(arguments[0]);
const ColumnWithTypeAndName & arg_then = block.getByPosition(arguments[1]);
const ColumnWithTypeAndName & arg_else = block.getByPosition(arguments[2]);
bool then_is_null = arg_then.column->onlyNull();
bool else_is_null = arg_else.column->onlyNull();
if (!then_is_null && !else_is_null)
return false;
if (then_is_null && else_is_null)
{
2018-04-24 07:16:39 +00:00
block.getByPosition(result).column = block.getByPosition(result).type->createColumnConstWithDefaultValue(input_rows_count);
return true;
}
const ColumnUInt8 * cond_col = typeid_cast<const ColumnUInt8 *>(arg_cond.column.get());
const ColumnConst * cond_const_col = checkAndGetColumnConst<ColumnVector<UInt8>>(arg_cond.column.get());
/// If then is NULL, we create Nullable column with null mask OR-ed with condition.
if (then_is_null)
{
if (cond_col)
{
2019-07-01 11:44:19 +00:00
if (isColumnNullable(*arg_else.column))
{
2018-03-20 17:01:13 +00:00
auto arg_else_column = arg_else.column;
auto result_column = (*std::move(arg_else_column)).mutate();
assert_cast<ColumnNullable &>(*result_column).applyNullMap(assert_cast<const ColumnUInt8 &>(*arg_cond.column));
block.getByPosition(result).column = std::move(result_column);
}
else
{
block.getByPosition(result).column = ColumnNullable::create(
materializeColumnIfConst(arg_else.column), arg_cond.column);
}
}
else if (cond_const_col)
{
if (cond_const_col->getValue<UInt8>())
2018-04-24 07:16:39 +00:00
block.getByPosition(result).column = block.getByPosition(result).type->createColumn()->cloneResized(input_rows_count);
else
block.getByPosition(result).column = makeNullableColumnIfNot(arg_else.column);
}
else
throw Exception("Illegal column " + arg_cond.column->getName() + " of first argument of function " + getName()
+ ". Must be ColumnUInt8 or ColumnConstUInt8.",
ErrorCodes::ILLEGAL_COLUMN);
return true;
}
/// If else is NULL, we create Nullable column with null mask OR-ed with negated condition.
if (else_is_null)
{
if (cond_col)
{
2018-04-24 07:16:39 +00:00
size_t size = input_rows_count;
2020-04-22 08:31:10 +00:00
const auto & null_map_data = cond_col->getData();
auto negated_null_map = ColumnUInt8::create();
auto & negated_null_map_data = negated_null_map->getData();
negated_null_map_data.resize(size);
for (size_t i = 0; i < size; ++i)
negated_null_map_data[i] = !null_map_data[i];
2019-07-01 11:44:19 +00:00
if (isColumnNullable(*arg_then.column))
{
2018-03-20 10:58:16 +00:00
auto arg_then_column = arg_then.column;
auto result_column = (*std::move(arg_then_column)).mutate();
assert_cast<ColumnNullable &>(*result_column).applyNegatedNullMap(assert_cast<const ColumnUInt8 &>(*arg_cond.column));
block.getByPosition(result).column = std::move(result_column);
}
else
{
block.getByPosition(result).column = ColumnNullable::create(
materializeColumnIfConst(arg_then.column), std::move(negated_null_map));
}
}
else if (cond_const_col)
{
if (cond_const_col->getValue<UInt8>())
block.getByPosition(result).column = makeNullableColumnIfNot(arg_then.column);
else
2018-04-24 07:16:39 +00:00
block.getByPosition(result).column = block.getByPosition(result).type->createColumn()->cloneResized(input_rows_count);
}
else
throw Exception("Illegal column " + arg_cond.column->getName() + " of first argument of function " + getName()
+ ". Must be ColumnUInt8 or ColumnConstUInt8.",
ErrorCodes::ILLEGAL_COLUMN);
return true;
}
return false;
}
public:
String getName() const override
{
return name;
}
size_t getNumberOfArguments() const override { return 3; }
2017-07-24 01:00:31 +00:00
bool useDefaultImplementationForNulls() const override { return false; }
2019-10-02 17:51:00 +00:00
ColumnNumbers getArgumentsThatDontImplyNullableReturnType(size_t /*number_of_arguments*/) const override { return {0}; }
2017-05-27 15:45:25 +00:00
/// Get result types by argument types. If the function does not apply to these arguments, throw an exception.
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
{
if (arguments[0]->onlyNull())
2019-05-10 10:42:00 +00:00
return arguments[2];
if (arguments[0]->isNullable())
2019-05-10 10:42:00 +00:00
return getReturnTypeImpl({
removeNullable(arguments[0]), arguments[1], arguments[2]});
if (!WhichDataType(arguments[0]).isUInt8())
throw Exception("Illegal type " + arguments[0]->getName() + " of first argument (condition) of function if. Must be UInt8.",
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
return getLeastSupertype({arguments[1], arguments[2]});
}
2018-04-24 07:16:39 +00:00
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t input_rows_count) override
{
2018-04-24 07:16:39 +00:00
if (executeForNullableCondition(block, arguments, result, input_rows_count)
|| executeForNullThenElse(block, arguments, result, input_rows_count)
|| executeForNullableThenElse(block, arguments, result, input_rows_count))
return;
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
const ColumnWithTypeAndName & arg_cond = block.getByPosition(arguments[0]);
const ColumnWithTypeAndName & arg_then = block.getByPosition(arguments[1]);
const ColumnWithTypeAndName & arg_else = block.getByPosition(arguments[2]);
2019-02-03 08:41:25 +00:00
/// A case for identical then and else (pointers are the same).
if (arg_then.column.get() == arg_else.column.get())
{
/// Just point result to them.
block.getByPosition(result).column = arg_then.column;
return;
}
const ColumnUInt8 * cond_col = typeid_cast<const ColumnUInt8 *>(arg_cond.column.get());
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
const ColumnConst * cond_const_col = checkAndGetColumnConst<ColumnVector<UInt8>>(arg_cond.column.get());
ColumnPtr materialized_cond_col;
if (cond_const_col)
{
if (arg_then.type->equals(*arg_else.type))
{
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
block.getByPosition(result).column = cond_const_col->getValue<UInt8>()
? arg_then.column
: arg_else.column;
return;
}
else
{
materialized_cond_col = cond_const_col->convertToFullColumn();
cond_col = typeid_cast<const ColumnUInt8 *>(&*materialized_cond_col);
}
}
if (!cond_col)
throw Exception("Illegal column " + arg_cond.column->getName() + " of first argument of function " + getName()
+ ". Must be ColumnUInt8 or ColumnConstUInt8.",
ErrorCodes::ILLEGAL_COLUMN);
auto call = [&](const auto & types) -> bool
{
using Types = std::decay_t<decltype(types)>;
using T0 = typename Types::LeftType;
using T1 = typename Types::RightType;
2019-01-19 23:27:52 +00:00
if constexpr (IsDecimalNumber<T0> == IsDecimalNumber<T1>)
return executeTyped<T0, T1>(cond_col, block, arguments, result, input_rows_count);
else
throw Exception("Conditional function with Decimal and non Decimal", ErrorCodes::NOT_IMPLEMENTED);
};
TypeIndex left_id = arg_then.type->getTypeId();
TypeIndex right_id = arg_else.type->getTypeId();
2020-04-22 08:31:10 +00:00
if (const auto * left_array = checkAndGetDataType<DataTypeArray>(arg_then.type.get()))
left_id = left_array->getNestedType()->getTypeId();
2020-04-22 08:31:10 +00:00
if (const auto * right_array = checkAndGetDataType<DataTypeArray>(arg_else.type.get()))
right_id = right_array->getNestedType()->getTypeId();
2019-02-03 08:41:25 +00:00
if (!(callOnBasicTypes<true, true, true, false>(left_id, right_id, call)
2018-10-12 11:23:05 +00:00
|| executeTyped<UInt128, UInt128>(cond_col, block, arguments, result, input_rows_count)
|| executeString(cond_col, block, arguments, result)
|| executeGenericArray(cond_col, block, arguments, result)
|| executeTuple(block, arguments, result, input_rows_count)))
2019-02-03 08:41:25 +00:00
{
executeGeneric(cond_col, block, arguments, result, input_rows_count);
}
}
};
void registerFunctionIf(FunctionFactory & factory)
{
factory.registerFunction<FunctionIf>(FunctionFactory::CaseInsensitive);
}
}