ClickHouse/src/Storages/StorageMaterializedMySQL.cpp

81 lines
2.5 KiB
C++
Raw Normal View History

#if !defined(ARCADIA_BUILD)
# include "config_core.h"
#endif
#if USE_MYSQL
#include <Storages/StorageMaterializedMySQL.h>
2020-08-17 10:11:50 +00:00
#include <Core/Settings.h>
#include <Interpreters/Context.h>
#include <Interpreters/ExpressionAnalyzer.h>
#include <Interpreters/TreeRewriter.h>
2020-08-17 10:11:50 +00:00
2020-06-23 17:45:55 +00:00
#include <Parsers/ASTFunction.h>
#include <Parsers/ASTSelectQuery.h>
#include <Parsers/ASTTablesInSelectQuery.h>
2020-06-23 17:45:55 +00:00
#include <Parsers/ASTLiteral.h>
#include <Parsers/ASTIdentifier.h>
2021-10-16 14:03:50 +00:00
#include <QueryPipeline/Pipe.h>
2020-06-23 17:45:55 +00:00
#include <Processors/Transforms/FilterTransform.h>
#include <Databases/MySQL/DatabaseMaterializedMySQL.h>
2021-07-01 08:20:13 +00:00
#include <Storages/ReadFinalForExternalReplicaStorage.h>
#include <Storages/SelectQueryInfo.h>
namespace DB
{
StorageMaterializedMySQL::StorageMaterializedMySQL(const StoragePtr & nested_storage_, const IDatabase * database_)
: StorageProxy(nested_storage_->getStorageID()), nested_storage(nested_storage_), database(database_)
{
StorageInMemoryMetadata in_memory_metadata;
in_memory_metadata = nested_storage->getInMemoryMetadata();
setInMemoryMetadata(in_memory_metadata);
}
bool StorageMaterializedMySQL::needRewriteQueryWithFinal(const Names & column_names) const
{
return needRewriteQueryWithFinalForStorage(column_names, nested_storage);
}
Pipe StorageMaterializedMySQL::read(
const Names & column_names,
2021-07-01 08:20:13 +00:00
const StorageMetadataPtr & metadata_snapshot,
SelectQueryInfo & query_info,
ContextPtr context,
QueryProcessingStage::Enum processed_stage,
size_t max_block_size,
unsigned int num_streams)
{
/// If the background synchronization thread has exception.
2020-09-15 13:30:30 +00:00
rethrowSyncExceptionIfNeed(database);
2021-07-01 08:20:13 +00:00
return readFinalFromNestedStorage(nested_storage, column_names, metadata_snapshot,
query_info, context, processed_stage, max_block_size, num_streams);
2020-06-24 05:28:27 +00:00
}
NamesAndTypesList StorageMaterializedMySQL::getVirtuals() const
2020-06-24 05:28:27 +00:00
{
/// If the background synchronization thread has exception.
2020-09-15 13:30:30 +00:00
rethrowSyncExceptionIfNeed(database);
return nested_storage->getVirtuals();
}
IStorage::ColumnSizeByName StorageMaterializedMySQL::getColumnSizes() const
{
auto sizes = nested_storage->getColumnSizes();
auto nested_header = nested_storage->getInMemoryMetadataPtr()->getSampleBlock();
String sign_column_name = nested_header.getByPosition(nested_header.columns() - 2).name;
String version_column_name = nested_header.getByPosition(nested_header.columns() - 1).name;
sizes.erase(sign_column_name);
sizes.erase(version_column_name);
return sizes;
}
}
#endif