aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Databases/MySQL/DatabaseMaterializedTablesIterator.h
blob: 8a7dbacf4a2d604cdb7677ac39ec071b8df7ed72 (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
#pragma once

#include <Databases/IDatabase.h>
#include <Storages/StorageMaterializedMySQL.h>

namespace DB
{

/** MaterializedMySQL database table iterator
 *
 * The iterator returns different storage engine types depending on the visitor.
 * When MySQLSync thread accesses, it always returns MergeTree
 * Other cases always convert MergeTree to StorageMaterializedMySQL
 */
class DatabaseMaterializedTablesIterator final : public IDatabaseTablesIterator
{
public:
    void next() override { nested_iterator->next(); }

    bool isValid() const override { return nested_iterator->isValid(); }

    const String & name() const override { return nested_iterator->name(); }

    const StoragePtr & table() const override
    {
        StoragePtr storage = std::make_shared<StorageMaterializedMySQL>(nested_iterator->table(), database);
        return tables.emplace_back(storage);
    }

    UUID uuid() const override { return nested_iterator->uuid(); }

    DatabaseMaterializedTablesIterator(DatabaseTablesIteratorPtr nested_iterator_, const IDatabase * database_)
        : IDatabaseTablesIterator(database_->getDatabaseName()), nested_iterator(std::move(nested_iterator_)), database(database_)
    {
    }

private:
    mutable std::vector<StoragePtr> tables;
    DatabaseTablesIteratorPtr nested_iterator;
    const IDatabase * database;
};

}