@@ -30,6 +30,7 @@ namespace ErrorCodes
30
30
{
31
31
extern const int LOGICAL_ERROR;
32
32
extern const int UNKNOWN_FUNCTION;
33
+ extern const int NOT_IMPLEMENTED;
33
34
}
34
35
35
36
@@ -78,10 +79,6 @@ StorageObjectStorageCluster::StorageObjectStorageCluster(
78
79
, configuration{configuration_}
79
80
, object_storage(object_storage_)
80
81
, cluster_name_in_settings(false )
81
- , comment(comment_)
82
- , format_settings(format_settings_)
83
- , mode(mode_)
84
- , partition_by(partition_by_)
85
82
{
86
83
ColumnsDescription columns{columns_};
87
84
std::string sample_path;
@@ -98,7 +95,18 @@ StorageObjectStorageCluster::StorageObjectStorageCluster(
98
95
setVirtuals (VirtualColumnUtils::getVirtualsForFileLikeStorage (metadata.columns , context_, sample_path));
99
96
setInMemoryMetadata (metadata);
100
97
101
- getPureStorage (context_);
98
+ pure_storage = std::make_shared<StorageObjectStorage>(
99
+ configuration,
100
+ object_storage,
101
+ context_,
102
+ getStorageID (),
103
+ getInMemoryMetadata ().getColumns (),
104
+ getInMemoryMetadata ().getConstraints (),
105
+ comment_,
106
+ format_settings_,
107
+ mode_,
108
+ /* distributed_processing */ false ,
109
+ partition_by_);
102
110
}
103
111
104
112
std::string StorageObjectStorageCluster::getName () const
@@ -260,34 +268,6 @@ RemoteQueryExecutor::Extension StorageObjectStorageCluster::getTaskIteratorExten
260
268
return RemoteQueryExecutor::Extension{ .task_iterator = std::move (callback) };
261
269
}
262
270
263
- std::shared_ptr<StorageObjectStorage> StorageObjectStorageCluster::getPureStorage (ContextPtr context)
264
- {
265
- std::lock_guard lock (mutex);
266
- if (!pure_storage)
267
- {
268
- pure_storage = std::make_shared<StorageObjectStorage>(
269
- configuration,
270
- object_storage,
271
- context,
272
- getStorageID (),
273
- getInMemoryMetadata ().getColumns (),
274
- getInMemoryMetadata ().getConstraints (),
275
- comment,
276
- format_settings,
277
- mode,
278
- /* distributed_processing */ false ,
279
- partition_by);
280
-
281
- auto virtuals_ = getVirtualsPtr ();
282
- if (virtuals_)
283
- pure_storage->setVirtuals (*virtuals_);
284
-
285
- pure_storage->setInMemoryMetadata (getInMemoryMetadata ());
286
- }
287
-
288
- return pure_storage;
289
- }
290
-
291
271
void StorageObjectStorageCluster::readFallBackToPure (
292
272
QueryPlan & query_plan,
293
273
const Names & column_names,
@@ -298,7 +278,7 @@ void StorageObjectStorageCluster::readFallBackToPure(
298
278
size_t max_block_size,
299
279
size_t num_streams)
300
280
{
301
- getPureStorage (context) ->read (query_plan, column_names, storage_snapshot, query_info, context, processed_stage, max_block_size, num_streams);
281
+ pure_storage ->read (query_plan, column_names, storage_snapshot, query_info, context, processed_stage, max_block_size, num_streams);
302
282
}
303
283
304
284
SinkToStoragePtr StorageObjectStorageCluster::writeFallBackToPure (
@@ -307,11 +287,15 @@ SinkToStoragePtr StorageObjectStorageCluster::writeFallBackToPure(
307
287
ContextPtr context,
308
288
bool async_insert)
309
289
{
310
- return getPureStorage (context) ->write (query, metadata_snapshot, context, async_insert);
290
+ return pure_storage ->write (query, metadata_snapshot, context, async_insert);
311
291
}
312
292
313
293
String StorageObjectStorageCluster::getClusterName (ContextPtr context) const
314
294
{
295
+ // / We try to get cluster name from query settings.
296
+ // / If it emtpy, we take default cluster name from table settings.
297
+ // / When it is not empty, we use this cluster to distibuted requests.
298
+ // / When both are empty, we must fall back to pure implementatiuon.
315
299
auto cluster_name_ = context->getSettingsRef ()[Setting::object_storage_cluster].value ;
316
300
if (cluster_name_.empty ())
317
301
cluster_name_ = getOriginalClusterName ();
@@ -335,7 +319,11 @@ void StorageObjectStorageCluster::truncate(
335
319
ContextPtr local_context,
336
320
TableExclusiveLockHolder & lock_holder)
337
321
{
338
- return getPureStorage (local_context)->truncate (query, metadata_snapshot, local_context, lock_holder);
322
+ // / Full query if fall back to pure storage.
323
+ if (getClusterName (local_context).empty ())
324
+ return pure_storage->truncate (query, metadata_snapshot, local_context, lock_holder);
325
+
326
+ throw Exception (ErrorCodes::NOT_IMPLEMENTED, " Truncate is not supported by storage {}" , getName ());
339
327
}
340
328
341
329
void StorageObjectStorageCluster::addInferredEngineArgsToCreateQuery (ASTs & args, const ContextPtr & context) const
0 commit comments