2022-09-28 08:45:15 +00:00
|
|
|
#include "config.h"
|
2021-03-16 18:41:29 +00:00
|
|
|
|
|
|
|
#if USE_AWS_S3
|
|
|
|
|
2021-04-12 21:42:52 +00:00
|
|
|
#include <TableFunctions/TableFunctionS3Cluster.h>
|
2023-05-12 13:58:45 +00:00
|
|
|
#include <TableFunctions/TableFunctionFactory.h>
|
2022-08-16 09:41:32 +00:00
|
|
|
#include <Interpreters/parseColumnsListForTableFunction.h>
|
2023-05-12 13:58:45 +00:00
|
|
|
#include <Storages/StorageS3.h>
|
2021-04-12 17:33:55 +00:00
|
|
|
|
|
|
|
#include "registerTableFunctions.h"
|
2021-04-12 17:07:01 +00:00
|
|
|
|
|
|
|
#include <memory>
|
2021-03-16 18:41:29 +00:00
|
|
|
|
2021-04-22 01:25:40 +00:00
|
|
|
|
2021-03-16 18:41:29 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-04-12 21:42:52 +00:00
|
|
|
StoragePtr TableFunctionS3Cluster::executeImpl(
|
2021-04-12 19:35:26 +00:00
|
|
|
const ASTPtr & /*function*/, ContextPtr context,
|
2021-03-19 21:49:18 +00:00
|
|
|
const std::string & table_name, ColumnsDescription /*cached_columns*/) const
|
2021-03-16 18:41:29 +00:00
|
|
|
{
|
2021-04-13 20:17:25 +00:00
|
|
|
StoragePtr storage;
|
2022-03-28 22:46:35 +00:00
|
|
|
ColumnsDescription columns;
|
2023-01-18 20:33:50 +00:00
|
|
|
bool structure_argument_was_provided = configuration.structure != "auto";
|
2022-09-13 13:07:43 +00:00
|
|
|
|
2023-01-18 20:33:50 +00:00
|
|
|
if (structure_argument_was_provided)
|
2022-09-13 13:07:43 +00:00
|
|
|
{
|
2022-03-28 22:46:35 +00:00
|
|
|
columns = parseColumnsListFromString(configuration.structure, context);
|
2022-09-13 13:07:43 +00:00
|
|
|
}
|
2022-03-28 22:46:35 +00:00
|
|
|
else if (!structure_hint.empty())
|
2022-09-13 13:07:43 +00:00
|
|
|
{
|
2022-03-28 22:46:35 +00:00
|
|
|
columns = structure_hint;
|
2022-09-13 13:07:43 +00:00
|
|
|
}
|
2022-03-28 22:46:35 +00:00
|
|
|
|
2021-04-13 20:17:25 +00:00
|
|
|
if (context->getClientInfo().query_kind == ClientInfo::QueryKind::SECONDARY_QUERY)
|
|
|
|
{
|
|
|
|
/// On worker node this filename won't contains globs
|
2022-04-19 20:47:29 +00:00
|
|
|
storage = std::make_shared<StorageS3>(
|
2023-03-28 13:39:59 +00:00
|
|
|
configuration,
|
2023-03-24 21:35:12 +00:00
|
|
|
context,
|
2021-04-23 12:18:23 +00:00
|
|
|
StorageID(getDatabaseName(), table_name),
|
2022-03-28 22:46:35 +00:00
|
|
|
columns,
|
2021-04-23 12:18:23 +00:00
|
|
|
ConstraintsDescription{},
|
2022-09-13 13:07:43 +00:00
|
|
|
/* comment */String{},
|
|
|
|
/* format_settings */std::nullopt, /// No format_settings for S3Cluster
|
2021-04-23 12:18:23 +00:00
|
|
|
/*distributed_processing=*/true);
|
2021-04-13 20:17:25 +00:00
|
|
|
}
|
2021-04-13 20:19:04 +00:00
|
|
|
else
|
|
|
|
{
|
2022-04-19 20:47:29 +00:00
|
|
|
storage = std::make_shared<StorageS3Cluster>(
|
2023-04-21 17:24:37 +00:00
|
|
|
cluster_name,
|
2022-09-13 13:07:43 +00:00
|
|
|
configuration,
|
2022-03-28 22:46:35 +00:00
|
|
|
StorageID(getDatabaseName(), table_name),
|
|
|
|
columns,
|
|
|
|
ConstraintsDescription{},
|
2023-01-18 20:33:50 +00:00
|
|
|
context,
|
|
|
|
structure_argument_was_provided);
|
2021-04-13 20:17:25 +00:00
|
|
|
}
|
2021-03-16 18:41:29 +00:00
|
|
|
|
|
|
|
storage->startup();
|
|
|
|
|
|
|
|
return storage;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-12 21:42:52 +00:00
|
|
|
void registerTableFunctionS3Cluster(TableFunctionFactory & factory)
|
2021-03-16 18:41:29 +00:00
|
|
|
{
|
2021-04-12 21:42:52 +00:00
|
|
|
factory.registerFunction<TableFunctionS3Cluster>();
|
2021-03-16 18:41:29 +00:00
|
|
|
}
|
|
|
|
|
2021-04-06 19:18:45 +00:00
|
|
|
|
2021-03-16 18:41:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|