MCPcopy Create free account
hub / github.com/ByConity/ByConity / executeCacheableCreateQuery

Method executeCacheableCreateQuery

src/CloudServices/CnchWorkerResource.cpp:79–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79void CnchWorkerResource::executeCacheableCreateQuery(
80 ContextMutablePtr context,
81 const StorageID & cnch_storage_id,
82 const String & definition,
83 const String & local_table_name,
84 WorkerEngineType engine_type,
85 const String & underlying_dictionary_tables,
86 const ColumnsDescription & object_columns)
87{
88 static auto * log = &Poco::Logger::get("WorkerResource");
89
90 std::shared_ptr<StorageCloudMergeTree> cached;
91 if (auto cache = context->tryGetCloudTableDefinitionCache(); cache)
92 {
93 auto load = [&]() -> std::shared_ptr<StorageCloudMergeTree>
94 {
95 auto ast_query = parseCreateQuery(context, definition);
96 auto & create_query = ast_query->as<ASTCreateQuery &>();
97
98 replaceCnchWithCloud(
99 create_query.storage,
100 cnch_storage_id.getDatabaseName(),
101 cnch_storage_id.getTableName(),
102 engine_type);
103
104 auto table = createStorageFromQuery(create_query, context);
105 if (auto cloud_table = std::dynamic_pointer_cast<StorageCloudMergeTree>(table))
106 return cloud_table;
107 return {};
108 };
109
110 cached = cache->getOrSet(CloudTableDefinitionCache::hash(definition), std::move(load)).first;
111 }
112
113 StoragePtr res;
114 if (cached)
115 {
116 LOG_DEBUG(log, "Creating cloud table {} from cached template of definition {}", local_table_name, definition);
117 StorageID actual_table_id = cached->getStorageID();
118 actual_table_id.table_name = local_table_name;
119
120 std::unique_ptr<MergeTreeSettings> new_settings = std::make_unique<MergeTreeSettings>(*cached->getSettings());
121 if (!underlying_dictionary_tables.empty())
122 new_settings->underlying_dictionary_tables = underlying_dictionary_tables;
123
124 switch (engine_type)
125 {
126 case WorkerEngineType::CLOUD:
127 res = StorageCloudMergeTree::create(
128 actual_table_id,
129 cnch_storage_id.database_name,
130 cnch_storage_id.table_name,
131 *cached->getInMemoryMetadataPtr(),
132 context,
133 /*date_column_name*/ "",
134 cached->getMergingParams(),
135 std::move(new_settings));
136 break;

Callers 1

Calls 15

replaceCnchWithCloudFunction · 0.85
createStorageFromQueryFunction · 0.85
modifyOrAddSettingFunction · 0.85
parseCreateQueryFunction · 0.70
getFunction · 0.50
hashFunction · 0.50
createFunction · 0.50
ExceptionClass · 0.50
FieldClass · 0.50
serializeASTFunction · 0.50

Tested by

no test coverage detected