2012-05-08 11:19:00 +00:00
|
|
|
#include <DB/Columns/ColumnString.h>
|
|
|
|
#include <DB/DataTypes/DataTypeString.h>
|
|
|
|
#include <DB/DataStreams/OneBlockInputStream.h>
|
|
|
|
#include <DB/Storages/StorageSystemTables.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
StorageSystemTables::StorageSystemTables(const std::string & name_, const Context & context_)
|
|
|
|
: name(name_), context(context_)
|
|
|
|
{
|
|
|
|
columns.push_back(NameAndTypePair("database", new DataTypeString));
|
|
|
|
columns.push_back(NameAndTypePair("name", new DataTypeString));
|
|
|
|
columns.push_back(NameAndTypePair("engine", new DataTypeString));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BlockInputStreams StorageSystemTables::read(
|
2012-05-30 04:45:49 +00:00
|
|
|
const Names & column_names, ASTPtr query, QueryProcessingStage::Enum & processed_stage, size_t max_block_size, unsigned threads)
|
2012-05-08 11:19:00 +00:00
|
|
|
{
|
|
|
|
check(column_names);
|
2012-05-22 18:32:45 +00:00
|
|
|
processed_stage = QueryProcessingStage::FetchColumns;
|
2012-05-08 11:19:00 +00:00
|
|
|
|
|
|
|
Block block;
|
|
|
|
|
|
|
|
ColumnWithNameAndType col_db;
|
|
|
|
col_db.name = "database";
|
|
|
|
col_db.type = new DataTypeString;
|
|
|
|
col_db.column = new ColumnString;
|
|
|
|
block.insert(col_db);
|
|
|
|
|
|
|
|
ColumnWithNameAndType col_name;
|
|
|
|
col_name.name = "name";
|
|
|
|
col_name.type = new DataTypeString;
|
|
|
|
col_name.column = new ColumnString;
|
|
|
|
block.insert(col_name);
|
|
|
|
|
|
|
|
ColumnWithNameAndType col_engine;
|
|
|
|
col_engine.name = "engine";
|
|
|
|
col_engine.type = new DataTypeString;
|
|
|
|
col_engine.column = new ColumnString;
|
|
|
|
block.insert(col_engine);
|
|
|
|
|
2012-05-30 05:53:09 +00:00
|
|
|
Poco::ScopedLock<Poco::Mutex> lock(*context.mutex);
|
2012-05-08 11:19:00 +00:00
|
|
|
|
|
|
|
for (Databases::const_iterator it = context.databases->begin(); it != context.databases->end(); ++it)
|
|
|
|
{
|
|
|
|
for (Tables::const_iterator jt = it->second.begin(); jt != it->second.end(); ++jt)
|
|
|
|
{
|
|
|
|
col_db.column->insert(it->first);
|
|
|
|
col_name.column->insert(jt->first);
|
|
|
|
col_engine.column->insert(jt->second->getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return BlockInputStreams(1, new OneBlockInputStream(block));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|