support jit for identity

This commit is contained in:
taiyang-li 2024-10-15 09:03:59 +08:00
parent 47971c9d7a
commit 664f565cee

View File

@ -2,6 +2,10 @@
#include <Functions/IFunction.h> #include <Functions/IFunction.h>
#include <Interpreters/Context_fwd.h> #include <Interpreters/Context_fwd.h>
#if USE_EMBEDDED_COMPILER
# include <DataTypes/Native.h>
# include <llvm/IR/IRBuilder.h>
#endif
namespace DB namespace DB
{ {
@ -11,6 +15,11 @@ namespace ErrorCodes
extern const int BAD_ARGUMENTS; extern const int BAD_ARGUMENTS;
} }
struct IdentityName
{
static constexpr auto name = "identity";
};
template<typename Name> template<typename Name>
class FunctionIdentityBase : public IFunction class FunctionIdentityBase : public IFunction
{ {
@ -32,12 +41,21 @@ public:
{ {
return arguments.front().column; return arguments.front().column;
} }
#if USE_EMBEDDED_COMPILER
bool isCompilableImpl(const DataTypes & /*types*/, const DataTypePtr & result_type) const override
{
return Name::name == IdentityName::name && canBeNativeType(result_type);
}
llvm::Value *
compileImpl(llvm::IRBuilderBase & /*builder*/, const ValuesWithType & arguments, const DataTypePtr & /*result_type*/) const override
{
return arguments[0].value;
}
#endif
}; };
struct IdentityName
{
static constexpr auto name = "identity";
};
struct ScalarSubqueryResultName struct ScalarSubqueryResultName
{ {