Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove useless template instantiations #4978

Merged
merged 3 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions dbms/src/Functions/FunctionsTiDBConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,19 @@ void registerFunctionsTiDBConversion(FunctionFactory & factory)
factory.registerFunction<FunctionBuilderTiDBCast>();
}

FunctionBasePtr FunctionBuilderTiDBCast::buildImpl(
const ColumnsWithTypeAndName & arguments,
const DataTypePtr & return_type,
const TiDB::TiDBCollatorPtr &) const
{
DataTypes data_types(arguments.size());

for (size_t i = 0; i < arguments.size(); ++i)
data_types[i] = arguments[i].type;

auto monotonicity = getMonotonicityInformation(arguments.front().type, return_type.get());
return std::make_shared<FunctionTiDBCast<>>(context, name, std::move(monotonicity), data_types, return_type, in_union, tidb_tp);
}


} // namespace DB
20 changes: 6 additions & 14 deletions dbms/src/Functions/FunctionsTiDBConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,7 @@ inline bool numberToDateTime(Int64 number, MyDateTime & result, DAGContext * ctx
return getDatetime(number, result, ctx);
}

template <typename...>
class ExecutableFunctionTiDBCast : public IExecutableFunction
{
public:
Expand Down Expand Up @@ -1782,13 +1783,15 @@ class ExecutableFunctionTiDBCast : public IExecutableFunction
const Context & context;
};

using MonotonicityForRange = std::function<IFunctionBase::Monotonicity(const IDataType &, const Field &, const Field &)>;

/// FunctionTiDBCast implements SQL cast function in TiDB
/// The basic idea is to dispatch according to combinations of <From, To> parameter types
template <typename...>
class FunctionTiDBCast final : public IFunctionBase
{
public:
using WrapperType = std::function<void(Block &, const ColumnNumbers &, size_t, bool, const tipb::FieldType &, const Context &)>;
using MonotonicityForRange = std::function<Monotonicity(const IDataType &, const Field &, const Field &)>;

FunctionTiDBCast(const Context & context, const char * name, MonotonicityForRange && monotonicity_for_range, const DataTypes & argument_types, const DataTypePtr & return_type, bool in_union_, const tipb::FieldType & tidb_tp_)
: context(context)
Expand All @@ -1805,7 +1808,7 @@ class FunctionTiDBCast final : public IFunctionBase

ExecutableFunctionPtr prepare(const Block & /*sample_block*/) const override
{
return std::make_shared<ExecutableFunctionTiDBCast>(
return std::make_shared<ExecutableFunctionTiDBCast<>>(
prepare(getArgumentTypes()[0], getReturnType()),
name,
in_union,
Expand Down Expand Up @@ -2341,8 +2344,6 @@ class FunctionTiDBCast final : public IFunctionBase
class FunctionBuilderTiDBCast : public IFunctionBuilder
{
public:
using MonotonicityForRange = FunctionTiDBCast::MonotonicityForRange;

static constexpr auto name = "tidb_cast";
static FunctionBuilderPtr create(const Context & context)
{
Expand All @@ -2369,16 +2370,7 @@ class FunctionBuilderTiDBCast : public IFunctionBuilder
FunctionBasePtr buildImpl(
const ColumnsWithTypeAndName & arguments,
const DataTypePtr & return_type,
const TiDB::TiDBCollatorPtr &) const override
{
DataTypes data_types(arguments.size());

for (size_t i = 0; i < arguments.size(); ++i)
data_types[i] = arguments[i].type;

auto monotonicity = getMonotonicityInformation(arguments.front().type, return_type.get());
return std::make_shared<FunctionTiDBCast>(context, name, std::move(monotonicity), data_types, return_type, in_union, tidb_tp);
}
const TiDB::TiDBCollatorPtr &) const override;

// use the last const string column's value as the return type name, in string representation like "Float64"
DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override
Expand Down
Loading