forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableFunctionFileCluster.cpp
More file actions
69 lines (59 loc) · 2.14 KB
/
TableFunctionFileCluster.cpp
File metadata and controls
69 lines (59 loc) · 2.14 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
#include <Core/Settings.h>
#include <Storages/StorageFile.h>
#include <TableFunctions/TableFunctionFileCluster.h>
#include <TableFunctions/TableFunctionFactory.h>
#include <TableFunctions/registerTableFunctions.h>
#include <memory>
namespace DB
{
namespace Setting
{
extern const SettingsString rename_files_after_processing;
}
StoragePtr TableFunctionFileCluster::getStorage(
const String & /*source*/, const String & /*format_*/, const ColumnsDescription & columns, ContextPtr context,
const std::string & table_name, const String & /*compression_method_*/, bool /*is_insert_query*/) const
{
StoragePtr storage;
if (context->getClientInfo().query_kind == ClientInfo::QueryKind::SECONDARY_QUERY)
{
/// On worker node this filename won't contain any globs
StorageFile::CommonArguments args{
WithContext(context),
StorageID(getDatabaseName(), table_name),
format,
std::nullopt /*format settings*/,
compression_method,
columns,
ConstraintsDescription{},
String{},
context->getSettingsRef()[Setting::rename_files_after_processing],
path_to_archive};
storage = std::make_shared<StorageFile>(filename, context->getUserFilesPath(), true, args);
}
else
{
storage = std::make_shared<StorageFileCluster>(
context,
cluster_name,
filename,
format,
compression_method,
StorageID(getDatabaseName(), table_name),
columns,
ConstraintsDescription{});
}
return storage;
}
void registerTableFunctionFileCluster(TableFunctionFactory & factory)
{
factory.registerFunction<TableFunctionFileCluster>(
{
.documentation = {
.description = R"(This table function is used for distributed reading of files in cluster nodes filesystems.)",
.examples{{"fileCluster", "SELECT * from fileCluster('my_cluster', 'file{1,2}.csv');", ""}},
.category = FunctionDocumentation::Category::TableFunction
},
.allow_readonly = false});
}
}