2021-04-12 21:42:52 +00:00
|
|
|
#include "Storages/StorageS3Cluster.h"
|
2021-03-19 21:49:18 +00:00
|
|
|
|
2022-09-28 08:45:15 +00:00
|
|
|
#include "config.h"
|
2021-03-24 21:02:21 +00:00
|
|
|
|
|
|
|
#if USE_AWS_S3
|
|
|
|
|
2021-03-22 17:12:31 +00:00
|
|
|
#include <DataTypes/DataTypeString.h>
|
2023-02-03 10:54:49 +00:00
|
|
|
#include <IO/ConnectionTimeouts.h>
|
2022-12-02 14:43:29 +00:00
|
|
|
#include <Interpreters/AddDefaultDatabaseVisitor.h>
|
2023-05-12 13:58:45 +00:00
|
|
|
#include <Interpreters/InterpreterSelectQuery.h>
|
2021-04-06 19:18:45 +00:00
|
|
|
#include <Processors/Sources/RemoteSource.h>
|
2023-05-12 13:58:45 +00:00
|
|
|
#include <Processors/Transforms/AddingDefaultsTransform.h>
|
2021-10-15 20:18:20 +00:00
|
|
|
#include <QueryPipeline/RemoteQueryExecutor.h>
|
2021-03-26 15:33:14 +00:00
|
|
|
#include <Storages/IStorage.h>
|
2023-05-12 13:58:45 +00:00
|
|
|
#include <Storages/StorageURL.h>
|
2021-03-26 15:33:14 +00:00
|
|
|
#include <Storages/SelectQueryInfo.h>
|
2022-09-30 16:59:17 +00:00
|
|
|
#include <Storages/StorageDictionary.h>
|
2023-05-12 13:58:45 +00:00
|
|
|
#include <Storages/extractTableFunctionArgumentsFromSelectQuery.h>
|
2023-08-17 16:54:43 +00:00
|
|
|
#include <Storages/VirtualColumnUtils.h>
|
2023-05-12 13:58:45 +00:00
|
|
|
#include <Common/Exception.h>
|
|
|
|
#include <Parsers/queryToString.h>
|
|
|
|
#include <TableFunctions/TableFunctionS3Cluster.h>
|
2021-03-22 17:12:31 +00:00
|
|
|
|
2021-03-19 21:49:18 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2021-03-22 17:12:31 +00:00
|
|
|
|
2021-03-19 21:49:18 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2022-09-30 16:59:17 +00:00
|
|
|
|
2023-05-15 16:39:26 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int LOGICAL_ERROR;
|
|
|
|
}
|
|
|
|
|
2021-04-12 21:42:52 +00:00
|
|
|
StorageS3Cluster::StorageS3Cluster(
|
2023-04-21 17:24:37 +00:00
|
|
|
const String & cluster_name_,
|
|
|
|
const StorageS3::Configuration & configuration_,
|
2021-03-22 17:12:31 +00:00
|
|
|
const StorageID & table_id_,
|
|
|
|
const ColumnsDescription & columns_,
|
|
|
|
const ConstraintsDescription & constraints_,
|
2023-01-18 20:33:50 +00:00
|
|
|
ContextPtr context_,
|
|
|
|
bool structure_argument_was_provided_)
|
2023-04-24 13:20:04 +00:00
|
|
|
: IStorageCluster(cluster_name_, table_id_, &Poco::Logger::get("StorageS3Cluster (" + table_id_.table_name + ")"), structure_argument_was_provided_)
|
2023-02-06 14:36:47 +00:00
|
|
|
, s3_configuration{configuration_}
|
2021-03-19 21:49:18 +00:00
|
|
|
{
|
2023-02-06 14:36:47 +00:00
|
|
|
context_->getGlobalContext()->getRemoteHostFilter().checkURL(configuration_.url.uri);
|
2023-06-15 13:49:49 +00:00
|
|
|
context_->getGlobalContext()->getHTTPHeaderFilter().checkHeaders(configuration_.headers_from_ast);
|
|
|
|
|
2021-03-19 21:49:18 +00:00
|
|
|
StorageInMemoryMetadata storage_metadata;
|
2023-03-28 13:39:59 +00:00
|
|
|
updateConfigurationIfChanged(context_);
|
2022-03-28 22:46:35 +00:00
|
|
|
|
|
|
|
if (columns_.empty())
|
|
|
|
{
|
|
|
|
/// `format_settings` is set to std::nullopt, because StorageS3Cluster is used only as table function
|
2023-03-24 21:35:12 +00:00
|
|
|
auto columns = StorageS3::getTableStructureFromDataImpl(s3_configuration, /*format_settings=*/std::nullopt, context_);
|
2022-03-28 22:46:35 +00:00
|
|
|
storage_metadata.setColumns(columns);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
storage_metadata.setColumns(columns_);
|
|
|
|
|
2021-03-22 17:12:31 +00:00
|
|
|
storage_metadata.setConstraints(constraints_);
|
2021-03-19 21:49:18 +00:00
|
|
|
setInMemoryMetadata(storage_metadata);
|
2022-05-19 11:18:58 +00:00
|
|
|
|
2023-08-17 16:54:43 +00:00
|
|
|
virtual_columns = VirtualColumnUtils::getPathAndFileVirtualsForStorage(storage_metadata.getSampleBlock().getNamesAndTypesList());
|
2021-03-19 21:49:18 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 13:58:45 +00:00
|
|
|
void StorageS3Cluster::addColumnsStructureToQuery(ASTPtr & query, const String & structure, const ContextPtr & context)
|
2023-04-24 13:20:04 +00:00
|
|
|
{
|
2023-05-12 13:58:45 +00:00
|
|
|
ASTExpressionList * expression_list = extractTableFunctionArgumentsFromSelectQuery(query);
|
|
|
|
if (!expression_list)
|
|
|
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Expected SELECT query from table function s3Cluster, got '{}'", queryToString(query));
|
|
|
|
|
|
|
|
TableFunctionS3Cluster::addColumnsStructureToArguments(expression_list->children, structure, context);
|
2023-04-24 13:20:04 +00:00
|
|
|
}
|
|
|
|
|
2023-03-28 13:39:59 +00:00
|
|
|
void StorageS3Cluster::updateConfigurationIfChanged(ContextPtr local_context)
|
|
|
|
{
|
|
|
|
s3_configuration.update(local_context);
|
|
|
|
}
|
|
|
|
|
2023-05-12 13:58:45 +00:00
|
|
|
RemoteQueryExecutor::Extension StorageS3Cluster::getTaskIteratorExtension(ASTPtr query, const ContextPtr & context) const
|
2023-01-09 12:30:32 +00:00
|
|
|
{
|
|
|
|
auto iterator = std::make_shared<StorageS3Source::DisclosedGlobIterator>(
|
2023-08-17 16:54:43 +00:00
|
|
|
*s3_configuration.client, s3_configuration.url, query, virtual_columns, context, nullptr, s3_configuration.request_settings, context->getFileProgressCallback());
|
2023-01-09 12:30:32 +00:00
|
|
|
auto callback = std::make_shared<std::function<String()>>([iterator]() mutable -> String { return iterator->next().key; });
|
|
|
|
return RemoteQueryExecutor::Extension{ .task_iterator = std::move(callback) };
|
|
|
|
}
|
|
|
|
|
2021-04-12 21:42:52 +00:00
|
|
|
NamesAndTypesList StorageS3Cluster::getVirtuals() const
|
2021-04-12 17:33:55 +00:00
|
|
|
{
|
2022-05-19 11:18:58 +00:00
|
|
|
return virtual_columns;
|
2021-04-12 17:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-19 21:49:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-24 21:02:21 +00:00
|
|
|
#endif
|