Skip to content

Commit

Permalink
Remove useless template instantiations (#4978)
Browse files Browse the repository at this point in the history
ref #4909
  • Loading branch information
solotzg authored May 24, 2022
1 parent 44f0999 commit 4448bac
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 87 deletions.
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

0 comments on commit 4448bac

Please sign in to comment.