aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Dictionaries/Embedded/GeodataProviders/HierarchiesProvider.h
blob: c2e36f59e1ed3271122b08abd7d4d6887cd284f5 (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
#pragma once

#include "IHierarchiesProvider.h"

#include <unordered_map>
#include <Common/FileUpdatesTracker.h>


// Represents local file with regions hierarchy dump
class RegionsHierarchyDataSource : public IRegionsHierarchyDataSource
{
private:
    std::string path;
    FileUpdatesTracker updates_tracker;

public:
    explicit RegionsHierarchyDataSource(const std::string & path_) : path(path_), updates_tracker(path_) {}

    bool isModified() const override;

    IRegionsHierarchyReaderPtr createReader() override;
};


// Provides access to directory with multiple data source files: one file per regions hierarchy
class RegionsHierarchiesDataProvider : public IRegionsHierarchiesDataProvider
{
private:
    // path to file with default regions hierarchy
    std::string path;

    using HierarchyFiles = std::unordered_map<std::string, std::string>;
    HierarchyFiles hierarchy_files;

public:
    /** path must point to the file with the hierarchy of regions "by default". It will be accessible by an empty key.
      * In addition, a number of files are searched for, the name of which (before the extension, if any) is added arbitrary _suffix.
      * Such files are loaded, and the hierarchy of regions is put on the `suffix` key.
      *
      * For example, if /opt/geo/regions_hierarchy.txt is specified,
      *  then the /opt/geo/regions_hierarchy_ua.txt file will also be loaded, if any, it will be accessible by the `ua` key.
      */
    explicit RegionsHierarchiesDataProvider(const std::string & path_);

    std::vector<std::string> listCustomHierarchies() const override;

    IRegionsHierarchyDataSourcePtr getDefaultHierarchySource() const override;
    IRegionsHierarchyDataSourcePtr getHierarchySource(const std::string & name) const override;

private:
    void discoverFilesWithCustomHierarchies();
};