@@ -269,18 +269,53 @@ void StorageObjectStorageCluster::updateQueryToSendIfNeeded(
269
269
{
270
270
configuration->addStructureAndFormatToArgsIfNeeded (args, structure, configuration->format , context, /* with_structure=*/ true );
271
271
272
+ // / Convert to old-stype *Cluster table function.
273
+ // / This allows to use old clickhouse versions in cluster.
274
+ static std::unordered_map<std::string, std::string> function_to_cluster_function = {
275
+ {" s3" , " s3Cluster" },
276
+ {" azureBlobStorage" , " azureBlobStorageCluster" },
277
+ {" hdfs" , " hdfsCluster" },
278
+ {" iceberg" , " icebergS3Cluster" },
279
+ {" icebergS3" , " icebergS3Cluster" },
280
+ {" icebergAzure" , " icebergAzureCluster" },
281
+ {" icebergHDFS" , " icebergHDFSCluster" },
282
+ {" deltaLake" , " deltaLakeCluster" },
283
+ {" hudi" , " hudiCluster" },
284
+ };
285
+
286
+ ASTFunction * table_function = extractTableFunctionFromSelectQuery (query);
287
+
288
+ auto p = function_to_cluster_function.find (table_function->name );
289
+ if (p == function_to_cluster_function.end ())
290
+ {
291
+ throw Exception (
292
+ ErrorCodes::LOGICAL_ERROR,
293
+ " Can't find cluster name for table function {}" ,
294
+ table_function->name );
295
+ }
296
+
297
+ table_function->name = p->second ;
298
+
299
+ auto cluster_name = getClusterName (context);
300
+ auto cluster_name_arg = std::make_shared<ASTLiteral>(cluster_name);
301
+ args.insert (args.begin (), cluster_name_arg);
302
+
272
303
auto * select_query = query->as <ASTSelectQuery>();
273
- if (select_query)
304
+ if (!select_query)
305
+ throw Exception (
306
+ ErrorCodes::LOGICAL_ERROR,
307
+ " Expected SELECT query from table function {}" ,
308
+ configuration->getEngineName ());
309
+
310
+ auto settings = select_query->settings ();
311
+ if (settings)
274
312
{
275
- auto settings = select_query-> settings ();
276
- if (settings )
313
+ auto & settings_ast = settings-> as <ASTSetQuery &> ();
314
+ if (settings_ast. changes . removeSetting ( " object_storage_cluster " ) && settings_ast. changes . empty () )
277
315
{
278
- auto & settings_ast = settings->as <ASTSetQuery &>();
279
- if (settings_ast.changes .removeSetting (" object_storage_cluster" ) && settings_ast.changes .empty ())
280
- {
281
- select_query->setExpression (ASTSelectQuery::Expression::SETTINGS, {});
282
- }
316
+ select_query->setExpression (ASTSelectQuery::Expression::SETTINGS, {});
283
317
}
318
+ // / No throw if not found - `object_storage_cluster` can be global setting.
284
319
}
285
320
}
286
321
else
0 commit comments