forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathregisterStorageObjectStorage.cpp
More file actions
387 lines (353 loc) · 13.8 KB
/
registerStorageObjectStorage.cpp
File metadata and controls
387 lines (353 loc) · 13.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#include <Core/FormatFactorySettings.h>
#include <Core/Settings.h>
#include <Databases/DataLake/ICatalog.h>
#include <Databases/LoadingStrictnessLevel.h>
#include <Formats/FormatFactory.h>
#include <Formats/FormatFilterInfo.h>
#include <Formats/FormatParserSharedResources.h>
#include <Interpreters/Context.h>
#include <Parsers/ASTCreateQuery.h>
#include <Storages/ObjectStorage/Azure/Configuration.h>
#include <Storages/ObjectStorage/DataLakes/DataLakeConfiguration.h>
#include <Storages/ObjectStorage/HDFS/Configuration.h>
#include <Storages/ObjectStorage/S3/Configuration.h>
#include <Storages/ObjectStorage/StorageObjectStorage.h>
#include <Storages/ObjectStorage/StorageObjectStorageSettings.h>
#include <Storages/ObjectStorage/StorageObjectStorageDefinitions.h>
#include <Storages/ObjectStorage/StorageObjectStorageCluster.h>
#include <Storages/StorageFactory.h>
#include <Poco/Logger.h>
namespace DB
{
namespace ErrorCodes
{
extern const int BAD_ARGUMENTS;
}
namespace Setting
{
extern const SettingsBool write_full_path_in_iceberg_metadata;
}
namespace
{
// LocalObjectStorage is only supported for Iceberg Datalake operations where Avro format is required. For regular file access, use FileStorage instead.
#if USE_AWS_S3 || USE_AZURE_BLOB_STORAGE || USE_HDFS || USE_AVRO
StoragePtr
createStorageObjectStorage(const StorageFactory::Arguments & args, StorageObjectStorageConfigurationPtr configuration)
{
auto & engine_args = args.engine_args;
if (engine_args.empty())
throw Exception(ErrorCodes::BAD_ARGUMENTS, "External data source must have arguments");
const auto context = args.getLocalContext();
std::string cluster_name;
if (args.storage_def->settings)
{
if (const auto * value = args.storage_def->settings->changes.tryGet("object_storage_cluster"))
cluster_name = value->safeGet<std::string>();
}
configuration->initialize(args.engine_args, context, false);
// Use format settings from global server context + settings from
// the SETTINGS clause of the create query. Settings from current
// session and user are ignored.
std::optional<FormatSettings> format_settings;
if (args.storage_def->settings)
{
Settings settings = context->getSettingsCopy();
// Apply changes from SETTINGS clause, with validation.
settings.applyChanges(args.storage_def->settings->changes);
format_settings = getFormatSettings(context, settings);
}
else
{
format_settings = getFormatSettings(context);
}
ASTPtr partition_by;
if (args.storage_def->partition_by)
partition_by = args.storage_def->partition_by->clone();
ContextMutablePtr context_copy = Context::createCopy(args.getContext());
Settings settings_copy = args.getLocalContext()->getSettingsCopy();
context_copy->setSettings(settings_copy);
return std::make_shared<StorageObjectStorageCluster>(
cluster_name,
configuration,
// We only want to perform write actions (e.g. create a container in Azure) when the table is being created,
// and we want to avoid it when we load the table after a server restart.
configuration->createObjectStorage(context, /* is_readonly */ args.mode != LoadingStrictnessLevel::CREATE),
args.table_id,
args.columns,
args.constraints,
partition_by,
context_copy, /// Use global context.
args.comment,
format_settings,
args.mode,
configuration->getCatalog(context, args.query.attach),
args.query.if_not_exists,
/* is_datalake_query */ false,
/* distributed_processing */ false,
/* is_table_function */ false,
/* lazy_init */ false);
}
#endif
}
#if USE_AZURE_BLOB_STORAGE
void registerStorageAzure(StorageFactory & factory)
{
factory.registerStorage(AzureDefinition::storage_engine_name, [](const StorageFactory::Arguments & args)
{
auto configuration = std::make_shared<StorageAzureConfiguration>();
return createStorageObjectStorage(args, configuration);
},
{
.supports_settings = true,
.supports_sort_order = true, // for partition by
.supports_schema_inference = true,
.source_access_type = AccessTypeObjects::Source::AZURE,
.has_builtin_setting_fn = StorageObjectStorageSettings::hasBuiltin,
});
}
#endif
#if USE_AWS_S3
void registerStorageS3Impl(const String & name, StorageFactory & factory)
{
factory.registerStorage(name, [=](const StorageFactory::Arguments & args)
{
auto configuration = std::make_shared<StorageS3Configuration>();
return createStorageObjectStorage(args, configuration);
},
{
.supports_settings = true,
.supports_sort_order = true, // for partition by
.supports_schema_inference = true,
.source_access_type = AccessTypeObjects::Source::S3,
.has_builtin_setting_fn = StorageObjectStorageSettings::hasBuiltin,
});
}
void registerStorageS3(StorageFactory & factory)
{
registerStorageS3Impl(S3Definition::storage_engine_name, factory);
}
void registerStorageCOS(StorageFactory & factory)
{
registerStorageS3Impl(COSNDefinition::storage_engine_name, factory);
}
void registerStorageOSS(StorageFactory & factory)
{
registerStorageS3Impl(OSSDefinition::storage_engine_name, factory);
}
void registerStorageGCS(StorageFactory & factory)
{
registerStorageS3Impl(GCSDefinition::storage_engine_name, factory);
}
#endif
#if USE_HDFS
void registerStorageHDFS(StorageFactory & factory)
{
factory.registerStorage(HDFSDefinition::storage_engine_name, [=](const StorageFactory::Arguments & args)
{
auto configuration = std::make_shared<StorageHDFSConfiguration>();
return createStorageObjectStorage(args, configuration);
},
{
.supports_settings = true,
.supports_sort_order = true, // for partition by
.supports_schema_inference = true,
.source_access_type = AccessTypeObjects::Source::HDFS,
.has_builtin_setting_fn = StorageObjectStorageSettings::hasBuiltin,
});
}
#endif
void registerStorageObjectStorage(StorageFactory & factory)
{
#if USE_AWS_S3
registerStorageS3(factory);
registerStorageCOS(factory);
registerStorageOSS(factory);
registerStorageGCS(factory);
#endif
#if USE_AZURE_BLOB_STORAGE
registerStorageAzure(factory);
#endif
#if USE_HDFS
registerStorageHDFS(factory);
#endif
UNUSED(factory);
}
#if USE_AVRO /// StorageIceberg depending on Avro to parse metadata with Avro format.
static DataLakeStorageSettingsPtr getDataLakeStorageSettings(const ASTStorage & storage_def)
{
auto storage_settings = std::make_shared<DataLakeStorageSettings>();
if (storage_def.settings)
storage_settings->loadFromQuery(*storage_def.settings);
return storage_settings;
}
void registerStorageIceberg(StorageFactory & factory)
{
factory.registerStorage(
IcebergDefinition::storage_engine_name,
[&](const StorageFactory::Arguments & args)
{
const auto storage_settings = getDataLakeStorageSettings(*args.storage_def);
auto configuration = std::make_shared<StorageIcebergConfiguration>(storage_settings);
return createStorageObjectStorage(args, configuration);
},
{
.supports_settings = true,
.supports_sort_order = true,
.supports_schema_inference = true,
.source_access_type = AccessTypeObjects::Source::S3,
.has_builtin_setting_fn = DataLakeStorageSettings::hasBuiltin,
});
# if USE_AWS_S3
factory.registerStorage(
IcebergS3Definition::storage_engine_name,
[&](const StorageFactory::Arguments & args)
{
const auto storage_settings = getDataLakeStorageSettings(*args.storage_def);
auto configuration = std::make_shared<StorageS3IcebergConfiguration>(storage_settings);
return createStorageObjectStorage(args, configuration);
},
{
.supports_settings = true,
.supports_sort_order = true,
.supports_schema_inference = true,
.source_access_type = AccessTypeObjects::Source::S3,
.has_builtin_setting_fn = DataLakeStorageSettings::hasBuiltin,
});
# endif
# if USE_AZURE_BLOB_STORAGE
factory.registerStorage(
IcebergAzureDefinition::storage_engine_name,
[&](const StorageFactory::Arguments & args)
{
const auto storage_settings = getDataLakeStorageSettings(*args.storage_def);
auto configuration = std::make_shared<StorageAzureIcebergConfiguration>(storage_settings);
return createStorageObjectStorage(args, configuration);
},
{
.supports_settings = true,
.supports_sort_order = true,
.supports_schema_inference = true,
.source_access_type = AccessTypeObjects::Source::AZURE,
.has_builtin_setting_fn = DataLakeStorageSettings::hasBuiltin,
});
# endif
# if USE_HDFS
factory.registerStorage(
IcebergHDFSDefinition::storage_engine_name,
[&](const StorageFactory::Arguments & args)
{
const auto storage_settings = getDataLakeStorageSettings(*args.storage_def);
auto configuration = std::make_shared<StorageHDFSIcebergConfiguration>(storage_settings);
return createStorageObjectStorage(args, configuration);
},
{
.supports_settings = true,
.supports_sort_order = true,
.supports_schema_inference = true,
.source_access_type = AccessTypeObjects::Source::HDFS,
.has_builtin_setting_fn = DataLakeStorageSettings::hasBuiltin,
});
# endif
factory.registerStorage(
IcebergLocalDefinition::storage_engine_name,
[&](const StorageFactory::Arguments & args)
{
const auto storage_settings = getDataLakeStorageSettings(*args.storage_def);
auto configuration = std::make_shared<StorageLocalIcebergConfiguration>(storage_settings);
return createStorageObjectStorage(args, configuration);
},
{
.supports_settings = true,
.supports_sort_order = true,
.supports_schema_inference = true,
.source_access_type = AccessTypeObjects::Source::FILE,
.has_builtin_setting_fn = DataLakeStorageSettings::hasBuiltin,
});
}
#endif
#if USE_PARQUET && USE_DELTA_KERNEL_RS
void registerStorageDeltaLake(StorageFactory & factory)
{
# if USE_AWS_S3
factory.registerStorage(
DeltaLakeDefinition::storage_engine_name,
[&](const StorageFactory::Arguments & args)
{
const auto storage_settings = getDataLakeStorageSettings(*args.storage_def);
auto configuration = std::make_shared<StorageS3DeltaLakeConfiguration>(storage_settings);
return createStorageObjectStorage(args, configuration);
},
{
.supports_settings = true,
.supports_schema_inference = true,
.source_access_type = AccessTypeObjects::Source::S3,
.has_builtin_setting_fn = DataLakeStorageSettings::hasBuiltin,
});
factory.registerStorage(
DeltaLakeS3Definition::storage_engine_name,
[&](const StorageFactory::Arguments & args)
{
const auto storage_settings = getDataLakeStorageSettings(*args.storage_def);
auto configuration = std::make_shared<StorageS3DeltaLakeConfiguration>(storage_settings);
return createStorageObjectStorage(args, configuration);
},
{
.supports_settings = true,
.supports_schema_inference = true,
.source_access_type = AccessTypeObjects::Source::S3,
.has_builtin_setting_fn = DataLakeStorageSettings::hasBuiltin,
});
# endif
# if USE_AZURE_BLOB_STORAGE
factory.registerStorage(
DeltaLakeAzureDefinition::storage_engine_name,
[&](const StorageFactory::Arguments & args)
{
const auto storage_settings = getDataLakeStorageSettings(*args.storage_def);
auto configuration = std::make_shared<StorageAzureDeltaLakeConfiguration>(storage_settings);
return createStorageObjectStorage(args, configuration);
},
{
.supports_settings = true,
.supports_schema_inference = true,
.source_access_type = AccessTypeObjects::Source::AZURE,
.has_builtin_setting_fn = DataLakeStorageSettings::hasBuiltin,
});
# endif
factory.registerStorage(
DeltaLakeLocalDefinition::storage_engine_name,
[&](const StorageFactory::Arguments & args)
{
const auto storage_settings = getDataLakeStorageSettings(*args.storage_def);
auto configuration = std::make_shared<StorageLocalDeltaLakeConfiguration>(storage_settings);
return createStorageObjectStorage(args, configuration);
},
{
.supports_settings = true,
.supports_schema_inference = true,
.source_access_type = AccessTypeObjects::Source::FILE,
.has_builtin_setting_fn = StorageObjectStorageSettings::hasBuiltin,
});
}
#endif
void registerStorageHudi(StorageFactory & factory)
{
#if USE_AWS_S3
factory.registerStorage(
HudiDefinition::storage_engine_name,
[&](const StorageFactory::Arguments & args)
{
const auto storage_settings = getDataLakeStorageSettings(*args.storage_def);
auto configuration = std::make_shared<StorageS3HudiConfiguration>(storage_settings);
return createStorageObjectStorage(args, configuration);
},
{
.supports_settings = false,
.supports_schema_inference = true,
.source_access_type = AccessTypeObjects::Source::S3,
.has_builtin_setting_fn = DataLakeStorageSettings::hasBuiltin,
});
#endif
UNUSED(factory);
}
}