ClickHouse/dbms/src/Databases/DatabasesCommon.h

70 lines
1.6 KiB
C++
Raw Normal View History

#pragma once
#include <Core/Types.h>
#include <Parsers/IAST.h>
#include <Storages/IStorage.h>
#include <Databases/IDatabase.h>
2017-05-23 18:33:48 +00:00
2017-04-17 11:56:55 +00:00
/// General functionality for several different database engines.
namespace DB
{
2017-05-23 18:33:48 +00:00
class Context;
2017-04-17 11:56:55 +00:00
/** Get the row with the table definition based on the CREATE query.
* It is an ATTACH query that you can execute to create a table from the correspondent database.
* See the implementation.
*/
String getTableDefinitionFromCreateQuery(const ASTPtr & query);
2017-04-17 11:56:55 +00:00
/** Create a table by its definition, without using InterpreterCreateQuery.
* (InterpreterCreateQuery has more complex functionality, and it can not be used if the database has not been created yet)
* Returns the table name and the table itself.
*/
std::pair<String, StoragePtr> createTableFromDefinition(
const String & definition,
const String & database_name,
const String & database_data_path,
Context & context,
bool has_force_restore_data_flag,
const String & description_for_error_message);
/// Copies list of tables and iterates through such snapshot.
class DatabaseSnaphotIterator : public IDatabaseIterator
{
private:
Tables tables;
Tables::iterator it;
public:
DatabaseSnaphotIterator(Tables & tables_)
: tables(tables_), it(tables.begin()) {}
void next() override
{
++it;
}
bool isValid() const override
{
return it != tables.end();
}
const String & name() const override
{
return it->first;
}
StoragePtr & table() const override
{
return it->second;
}
};
}