@@ -87,26 +87,52 @@ StorageObjectStorageCluster::StorageObjectStorageCluster(
8787 ContextPtr context_,
8888 const String & comment_,
8989 std::optional<FormatSettings> format_settings_,
90- LoadingStrictnessLevel mode_)
90+ LoadingStrictnessLevel mode_,
91+ bool lazy_init)
9192 : IStorageCluster(
9293 cluster_name_, table_id_, getLogger(fmt::format(" {}({})" , configuration_->getEngineName (), table_id_.table_name)))
9394 , configuration{configuration_}
9495 , object_storage(object_storage_)
9596 , cluster_name_in_settings(false )
9697{
9798 configuration->initPartitionStrategy (partition_by, columns_in_table_or_function_definition, context_);
98- // / We allow exceptions to be thrown on update(),
99- // / because Cluster engine can only be used as table function,
100- // / so no lazy initialization is allowed.
101- configuration->update (
102- object_storage,
103- context_,
104- /* if_not_updated_before */ false ,
105- /* check_consistent_with_previous_metadata */ true );
99+
100+ const bool need_resolve_columns_or_format = columns_in_table_or_function_definition.empty () || (configuration->getFormat () == " auto" );
101+ const bool do_lazy_init = lazy_init && !need_resolve_columns_or_format;
102+
103+ auto log_ = getLogger (" StorageObjectStorageCluster" );
104+
105+ try
106+ {
107+ if (!do_lazy_init)
108+ {
109+ // / We allow exceptions to be thrown on update(),
110+ // / because Cluster engine can only be used as table function,
111+ // / so no lazy initialization is allowed.
112+ configuration->update (
113+ object_storage,
114+ context_,
115+ /* if_not_updated_before */ false ,
116+ /* check_consistent_with_previous_metadata */ true );
117+ }
118+ }
119+ catch (...)
120+ {
121+ // If we don't have format or schema yet, we can't ignore failed configuration update,
122+ // because relevant configuration is crucial for format and schema inference
123+ if (mode_ <= LoadingStrictnessLevel::CREATE || need_resolve_columns_or_format)
124+ {
125+ throw ;
126+ }
127+ tryLogCurrentException (log_);
128+ }
106129
107130 ColumnsDescription columns{columns_in_table_or_function_definition};
108131 std::string sample_path;
109- resolveSchemaAndFormat (columns, object_storage, configuration, {}, sample_path, context_);
132+ if (need_resolve_columns_or_format)
133+ resolveSchemaAndFormat (columns, object_storage, configuration, {}, sample_path, context_);
134+ else
135+ validateSupportedColumns (columns, *configuration);
110136 configuration->check (context_);
111137
112138 if (sample_path.empty () && context_->getSettingsRef ()[Setting::use_hive_partitioning] && !configuration->isDataLakeConfiguration () && !configuration->getPartitionStrategy ())
@@ -162,7 +188,9 @@ StorageObjectStorageCluster::StorageObjectStorageCluster(
162188 format_settings_,
163189 mode_,
164190 /* distributed_processing */ false ,
165- partition_by);
191+ partition_by,
192+ /* is_table_function */ false ,
193+ /* lazy_init */ lazy_init);
166194
167195 auto virtuals_ = getVirtualsPtr ();
168196 if (virtuals_)
0 commit comments