2017-07-21 06:35:58 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Common/typeid_cast.h>
|
2019-08-21 02:28:04 +00:00
|
|
|
#include <Common/assert_cast.h>
|
2017-07-21 06:35:58 +00:00
|
|
|
#include <DataTypes/IDataType.h>
|
|
|
|
#include <Columns/IColumn.h>
|
|
|
|
#include <Columns/ColumnConst.h>
|
2017-07-24 01:00:31 +00:00
|
|
|
#include <Core/Block.h>
|
|
|
|
#include <Core/ColumnNumbers.h>
|
2018-09-03 10:46:58 +00:00
|
|
|
#include <Core/callOnTypeIndex.h>
|
2017-07-21 06:35:58 +00:00
|
|
|
|
2018-09-02 01:12:32 +00:00
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-04-09 19:19:30 +00:00
|
|
|
class IFunction;
|
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
/// Methods, that helps dispatching over real column types.
|
|
|
|
|
|
|
|
template <typename Type>
|
|
|
|
const Type * checkAndGetDataType(const IDataType * data_type)
|
|
|
|
{
|
|
|
|
return typeid_cast<const Type *>(data_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Type>
|
|
|
|
const ColumnConst * checkAndGetColumnConst(const IColumn * column)
|
|
|
|
{
|
2019-06-27 19:28:52 +00:00
|
|
|
if (!column || !isColumnConst(*column))
|
2017-07-21 06:35:58 +00:00
|
|
|
return {};
|
|
|
|
|
2019-08-21 02:28:04 +00:00
|
|
|
const ColumnConst * res = assert_cast<const ColumnConst *>(column);
|
2017-07-21 06:35:58 +00:00
|
|
|
|
|
|
|
if (!checkColumn<Type>(&res->getDataColumn()))
|
|
|
|
return {};
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Type>
|
|
|
|
const Type * checkAndGetColumnConstData(const IColumn * column)
|
|
|
|
{
|
|
|
|
const ColumnConst * res = checkAndGetColumnConst<Type>(column);
|
|
|
|
|
|
|
|
if (!res)
|
2017-12-08 06:46:35 +00:00
|
|
|
return {};
|
2017-07-21 06:35:58 +00:00
|
|
|
|
2017-12-08 06:46:35 +00:00
|
|
|
return static_cast<const Type *>(&res->getDataColumn());
|
2017-07-21 06:35:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Type>
|
2017-12-01 20:21:35 +00:00
|
|
|
bool checkColumnConst(const IColumn * column)
|
2017-07-21 06:35:58 +00:00
|
|
|
{
|
|
|
|
return checkAndGetColumnConst<Type>(column);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns non-nullptr if column is ColumnConst with ColumnString or ColumnFixedString inside.
|
|
|
|
const ColumnConst * checkAndGetColumnConstStringOrFixedString(const IColumn * column);
|
|
|
|
|
|
|
|
|
|
|
|
/// Transform anything to Field.
|
|
|
|
template <typename T>
|
2018-08-24 16:35:00 +00:00
|
|
|
inline std::enable_if_t<!IsDecimalNumber<T>, Field> toField(const T & x)
|
2017-07-21 06:35:58 +00:00
|
|
|
{
|
2018-11-20 20:09:20 +00:00
|
|
|
return Field(NearestFieldType<T>(x));
|
2017-07-21 06:35:58 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 16:35:00 +00:00
|
|
|
template <typename T>
|
|
|
|
inline std::enable_if_t<IsDecimalNumber<T>, Field> toField(const T & x, UInt32 scale)
|
|
|
|
{
|
2018-11-20 20:09:20 +00:00
|
|
|
return Field(NearestFieldType<T>(x, scale));
|
2018-08-24 16:35:00 +00:00
|
|
|
}
|
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
|
2017-12-09 12:23:09 +00:00
|
|
|
Columns convertConstTupleToConstantElements(const ColumnConst & column);
|
2017-07-21 06:35:58 +00:00
|
|
|
|
2017-07-23 08:40:43 +00:00
|
|
|
|
2017-07-24 01:00:31 +00:00
|
|
|
/// Returns the copy of a given block in which each column specified in
|
|
|
|
/// the "arguments" parameter is replaced with its respective nested
|
|
|
|
/// column if it is nullable.
|
2018-01-19 02:15:10 +00:00
|
|
|
Block createBlockWithNestedColumns(const Block & block, const ColumnNumbers & args);
|
2017-07-24 01:00:31 +00:00
|
|
|
|
|
|
|
/// Similar function as above. Additionally transform the result type if needed.
|
2018-01-19 02:15:10 +00:00
|
|
|
Block createBlockWithNestedColumns(const Block & block, const ColumnNumbers & args, size_t result);
|
2017-07-24 01:00:31 +00:00
|
|
|
|
2019-04-09 19:19:30 +00:00
|
|
|
/// Checks argument type at specified index with predicate.
|
|
|
|
/// throws if there is no argument at specified index or if predicate returns false.
|
|
|
|
void validateArgumentType(const IFunction & func, const DataTypes & arguments,
|
|
|
|
size_t argument_index, bool (* validator_func)(const IDataType &),
|
|
|
|
const char * expected_type_description);
|
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
}
|