2021-09-07 23:55:17 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <DataTypes/IDataType.h>
|
2021-10-15 20:18:20 +00:00
|
|
|
#include <Processors/Sources/ShellCommandSource.h>
|
2021-09-07 23:55:17 +00:00
|
|
|
#include <Interpreters/IExternalLoadable.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-09-09 19:35:07 +00:00
|
|
|
enum class UserDefinedExecutableFunctionType
|
|
|
|
{
|
|
|
|
executable,
|
|
|
|
executable_pool
|
|
|
|
};
|
|
|
|
|
2021-09-10 13:28:46 +00:00
|
|
|
struct UserDefinedExecutableFunctionConfiguration
|
|
|
|
{
|
2021-09-17 13:04:44 +00:00
|
|
|
UserDefinedExecutableFunctionType type = UserDefinedExecutableFunctionType::executable;
|
2021-09-10 13:28:46 +00:00
|
|
|
std::string name;
|
|
|
|
std::string script_path;
|
|
|
|
std::string format;
|
|
|
|
std::vector<DataTypePtr> argument_types;
|
|
|
|
DataTypePtr result_type;
|
|
|
|
/// Pool settings
|
|
|
|
size_t pool_size = 0;
|
|
|
|
size_t command_termination_timeout = 0;
|
|
|
|
size_t max_command_execution_time = 0;
|
|
|
|
/// Send number_of_rows\n before sending chunk to process
|
|
|
|
bool send_chunk_header = false;
|
|
|
|
};
|
|
|
|
|
2021-09-07 23:55:17 +00:00
|
|
|
class UserDefinedExecutableFunction final : public IExternalLoadable
|
|
|
|
{
|
|
|
|
public:
|
2021-09-09 19:35:07 +00:00
|
|
|
|
2021-09-07 23:55:17 +00:00
|
|
|
UserDefinedExecutableFunction(
|
2021-09-10 13:28:46 +00:00
|
|
|
const UserDefinedExecutableFunctionConfiguration & configuration_,
|
2021-09-17 13:04:44 +00:00
|
|
|
const ExternalLoadableLifetime & lifetime_,
|
|
|
|
std::shared_ptr<ProcessPool> process_pool_ = nullptr);
|
2021-09-07 23:55:17 +00:00
|
|
|
|
|
|
|
const ExternalLoadableLifetime & getLifetime() const override
|
|
|
|
{
|
|
|
|
return lifetime;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string & getLoadableName() const override
|
|
|
|
{
|
2021-09-10 13:28:46 +00:00
|
|
|
return configuration.name;
|
2021-09-07 23:55:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool supportUpdates() const override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isModified() const override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<const IExternalLoadable> clone() const override
|
|
|
|
{
|
2021-09-17 13:04:44 +00:00
|
|
|
return std::make_shared<UserDefinedExecutableFunction>(configuration, lifetime, process_pool);
|
2021-09-07 23:55:17 +00:00
|
|
|
}
|
|
|
|
|
2021-09-10 13:28:46 +00:00
|
|
|
const UserDefinedExecutableFunctionConfiguration & getConfiguration() const
|
2021-09-07 23:55:17 +00:00
|
|
|
{
|
2021-09-10 13:28:46 +00:00
|
|
|
return configuration;
|
2021-09-07 23:55:17 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 13:04:44 +00:00
|
|
|
std::shared_ptr<ProcessPool> getProcessPool() const
|
|
|
|
{
|
|
|
|
return process_pool;
|
|
|
|
}
|
|
|
|
|
2021-09-07 23:55:17 +00:00
|
|
|
std::shared_ptr<UserDefinedExecutableFunction> shared_from_this()
|
|
|
|
{
|
|
|
|
return std::static_pointer_cast<UserDefinedExecutableFunction>(IExternalLoadable::shared_from_this());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<const UserDefinedExecutableFunction> shared_from_this() const
|
|
|
|
{
|
|
|
|
return std::static_pointer_cast<const UserDefinedExecutableFunction>(IExternalLoadable::shared_from_this());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-09-17 13:04:44 +00:00
|
|
|
UserDefinedExecutableFunction(const UserDefinedExecutableFunctionConfiguration & configuration_,
|
|
|
|
std::shared_ptr<ProcessPool> process_pool_,
|
|
|
|
const ExternalLoadableLifetime & lifetime_);
|
|
|
|
|
2021-09-10 13:28:46 +00:00
|
|
|
UserDefinedExecutableFunctionConfiguration configuration;
|
2021-09-07 23:55:17 +00:00
|
|
|
ExternalLoadableLifetime lifetime;
|
2021-09-17 13:04:44 +00:00
|
|
|
std::shared_ptr<ProcessPool> process_pool;
|
2021-09-07 23:55:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|