ClickHouse/src/Functions/ITupleFunction.h

47 lines
1.3 KiB
C++
Raw Normal View History

2021-08-20 21:14:26 +00:00
#pragma once
#include <Columns/ColumnConst.h>
#include <Columns/ColumnTuple.h>
#include <Functions/IFunction.h>
#include <Functions/FunctionHelpers.h>
#include <Interpreters/Context_fwd.h>
namespace DB
{
2021-08-20 21:14:26 +00:00
namespace ErrorCodes
{
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
}
2021-09-09 12:41:22 +00:00
class ITupleFunction : public IFunction
{
2021-08-25 14:02:04 +00:00
protected:
ContextPtr context;
public:
2021-09-09 12:41:22 +00:00
explicit ITupleFunction(ContextPtr context_) : context(context_) {}
2021-08-25 14:02:04 +00:00
Columns getTupleElements(const IColumn & column) const
{
if (const auto * const_column = typeid_cast<const ColumnConst *>(&column))
return convertConstTupleToConstantElements(*const_column);
if (const auto * column_tuple = typeid_cast<const ColumnTuple *>(&column))
{
Columns columns(column_tuple->tupleSize());
for (size_t i = 0; i < columns.size(); ++i)
columns[i] = column_tuple->getColumnPtr(i);
return columns;
}
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Argument of function {} should be tuples, got {}",
getName(), column.getName());
}
2021-08-25 14:02:04 +00:00
bool useDefaultImplementationForConstants() const override { return true; }
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; }
};
}