aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/TableFunctions/TableFunctionAzureBlobStorageCluster.cpp
blob: 3926669c9d811d060f1ef48cf60fd8f384f5242b (plain) (blame)
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
#include "clickhouse_config.h"

#if USE_AZURE_BLOB_STORAGE

#include <TableFunctions/TableFunctionAzureBlobStorageCluster.h>
#include <TableFunctions/TableFunctionFactory.h>
#include <Interpreters/parseColumnsListForTableFunction.h>
#include <Storages/StorageAzureBlob.h>

#include "registerTableFunctions.h"

#include <memory>


namespace DB
{

StoragePtr TableFunctionAzureBlobStorageCluster::executeImpl(
    const ASTPtr & /*function*/, ContextPtr context,
    const std::string & table_name, ColumnsDescription /*cached_columns*/, bool is_insert_query) const
{
    StoragePtr storage;
    ColumnsDescription columns;
    bool structure_argument_was_provided = configuration.structure != "auto";

    if (structure_argument_was_provided)
    {
        columns = parseColumnsListFromString(configuration.structure, context);
    }
    else if (!structure_hint.empty())
    {
        columns = structure_hint;
    }

    auto client = StorageAzureBlob::createClient(configuration, !is_insert_query);
    auto settings = StorageAzureBlob::createSettings(context);

    if (context->getClientInfo().query_kind == ClientInfo::QueryKind::SECONDARY_QUERY)
    {
        /// On worker node this filename won't contains globs
        storage = std::make_shared<StorageAzureBlob>(
            configuration,
            std::make_unique<AzureObjectStorage>(table_name, std::move(client), std::move(settings)),
            context,
            StorageID(getDatabaseName(), table_name),
            columns,
            ConstraintsDescription{},
            /* comment */String{},
            /* format_settings */std::nullopt, /// No format_settings
            /* distributed_processing */ true,
            /*partition_by_=*/nullptr);
    }
    else
    {
        storage = std::make_shared<StorageAzureBlobCluster>(
            cluster_name,
            configuration,
            std::make_unique<AzureObjectStorage>(table_name, std::move(client), std::move(settings)),
            StorageID(getDatabaseName(), table_name),
            columns,
            ConstraintsDescription{},
            context,
            structure_argument_was_provided);
    }

    storage->startup();

    return storage;
}


void registerTableFunctionAzureBlobStorageCluster(TableFunctionFactory & factory)
{
    factory.registerFunction<TableFunctionAzureBlobStorageCluster>(
        {.documentation
         = {.description=R"(The table function can be used to read the data stored on Azure Blob Storage in parallel for many nodes in a specified cluster.)",
            .examples{{"azureBlobStorageCluster", "SELECT * FROM  azureBlobStorageCluster(cluster, connection_string|storage_account_url, container_name, blobpath, [account_name, account_key, format, compression, structure])", ""}}},
         .allow_readonly = false}
        );
}


}

#endif