mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
dbms: development [#CONV-2944].
This commit is contained in:
parent
5bc7288e0d
commit
859a86b382
@ -13,7 +13,11 @@ namespace DB
|
||||
|
||||
using Poco::SharedPtr;
|
||||
|
||||
typedef std::map<std::string, DataTypePtr> NamesAndTypes;
|
||||
typedef SharedPtr<NamesAndTypes> NamesAndTypesPtr;
|
||||
typedef std::pair<std::string, DataTypePtr> NameAndTypePair;
|
||||
typedef std::list<NameAndTypePair> NamesAndTypesList;
|
||||
typedef SharedPtr<NamesAndTypesList> NamesAndTypesListPtr;
|
||||
|
||||
typedef std::map<std::string, DataTypePtr> NamesAndTypesMap;
|
||||
typedef SharedPtr<NamesAndTypesMap> NamesAndTypesMapPtr;
|
||||
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ struct Context
|
||||
AggregateFunctionFactoryPtr aggregate_function_factory; /// Агрегатные функции.
|
||||
DataTypeFactoryPtr data_type_factory; /// Типы данных.
|
||||
StorageFactoryPtr storage_factory; /// Движки таблиц.
|
||||
NamesAndTypes columns; /// Столбцы текущей обрабатываемой таблицы.
|
||||
NamesAndTypesMap columns; /// Столбцы текущей обрабатываемой таблицы.
|
||||
|
||||
SharedPtr<Poco::FastMutex> mutex; /// Для доступа и модификации разделяемых объектов.
|
||||
|
||||
|
@ -36,7 +36,10 @@ public:
|
||||
|
||||
/** Получить список имён и типов столбцов таблицы.
|
||||
*/
|
||||
virtual const NamesAndTypes & getColumns() const = 0;
|
||||
virtual const NamesAndTypesList & getColumnsList() const = 0;
|
||||
|
||||
NamesAndTypesMap getColumnsMap() const;
|
||||
const DataTypePtr getDataTypeByName(const String & column_name) const;
|
||||
|
||||
/** То же самое, но в виде блока-образца.
|
||||
*/
|
||||
@ -76,7 +79,7 @@ public:
|
||||
/** ALTER таблицы в виде изменения столбцов, не затрагивающий изменение Storage или его параметров.
|
||||
* (ALTER, затрагивающий изменение движка, делается внешним кодом, путём копирования данных.)
|
||||
*/
|
||||
virtual void alter(NamesAndTypesPtr columns)
|
||||
virtual void alter(NamesAndTypesListPtr columns)
|
||||
{
|
||||
throw Exception("Method alter() is not supported by storage " + getName(), ErrorCodes::NOT_IMPLEMENTED);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public:
|
||||
const String & name,
|
||||
const String & data_path,
|
||||
const String & table_name,
|
||||
NamesAndTypesPtr columns) const;
|
||||
NamesAndTypesListPtr columns) const;
|
||||
};
|
||||
|
||||
typedef SharedPtr<StorageFactory> StorageFactoryPtr;
|
||||
|
@ -79,13 +79,13 @@ public:
|
||||
* (корректность имён и путей не проверяется)
|
||||
* состоящую из указанных столбцов; создать файлы, если их нет.
|
||||
*/
|
||||
StorageLog(const std::string & path_, const std::string & name_, NamesAndTypesPtr columns_,
|
||||
StorageLog(const std::string & path_, const std::string & name_, NamesAndTypesListPtr columns_,
|
||||
const std::string & extension_ = ".bin");
|
||||
|
||||
std::string getName() const { return "Log"; }
|
||||
std::string getTableName() const { return name; }
|
||||
|
||||
const NamesAndTypes & getColumns() const { return *columns; }
|
||||
const NamesAndTypesList & getColumnsList() const { return *columns; }
|
||||
|
||||
BlockInputStreamPtr read(
|
||||
const Names & column_names,
|
||||
@ -98,7 +98,7 @@ public:
|
||||
private:
|
||||
const std::string path;
|
||||
const std::string name;
|
||||
NamesAndTypesPtr columns;
|
||||
NamesAndTypesListPtr columns;
|
||||
const std::string extension;
|
||||
|
||||
typedef std::map<std::string, Poco::File> Files_t;
|
||||
|
@ -47,12 +47,12 @@ friend class MemoryBlockInputStream;
|
||||
friend class MemoryBlockOutputStream;
|
||||
|
||||
public:
|
||||
StorageMemory(const std::string & name_, NamesAndTypesPtr columns_);
|
||||
StorageMemory(const std::string & name_, NamesAndTypesListPtr columns_);
|
||||
|
||||
std::string getName() const { return "Memory"; }
|
||||
std::string getTableName() const { return name; }
|
||||
|
||||
const NamesAndTypes & getColumns() const { return *columns; }
|
||||
const NamesAndTypesList & getColumnsList() const { return *columns; }
|
||||
|
||||
BlockInputStreamPtr read(
|
||||
const Names & column_names,
|
||||
@ -64,7 +64,7 @@ public:
|
||||
|
||||
private:
|
||||
const std::string name;
|
||||
NamesAndTypesPtr columns;
|
||||
NamesAndTypesListPtr columns;
|
||||
|
||||
/// Сами данные
|
||||
Blocks data;
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
std::string getName() const { return "SystemNumbers"; }
|
||||
std::string getTableName() const { return "Numbers"; }
|
||||
|
||||
const NamesAndTypes & getColumns() const { return columns; }
|
||||
const NamesAndTypesList & getColumnsList() const { return columns; }
|
||||
|
||||
BlockInputStreamPtr read(
|
||||
const Names & column_names,
|
||||
@ -46,7 +46,7 @@ public:
|
||||
|
||||
private:
|
||||
const std::string name;
|
||||
NamesAndTypes columns;
|
||||
NamesAndTypesList columns;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
std::string getName() const { return "SystemOne"; }
|
||||
std::string getTableName() const { return "One"; }
|
||||
|
||||
const NamesAndTypes & getColumns() const { return columns; }
|
||||
const NamesAndTypesList & getColumnsList() const { return columns; }
|
||||
|
||||
BlockInputStreamPtr read(
|
||||
const Names & column_names,
|
||||
@ -42,7 +42,7 @@ public:
|
||||
|
||||
private:
|
||||
const std::string name;
|
||||
NamesAndTypes columns;
|
||||
NamesAndTypesList columns;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -28,12 +28,9 @@ int main(int argc, char ** argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
typedef std::pair<std::string, SharedPtr<DB::IDataType> > NameAndTypePair;
|
||||
typedef std::list<NameAndTypePair> NamesAndTypesList;
|
||||
DB::NamesAndTypesListPtr names_and_types_list = new DB::NamesAndTypesList;
|
||||
|
||||
NamesAndTypesList names_and_types_list;
|
||||
|
||||
boost::assign::push_back(names_and_types_list)
|
||||
boost::assign::push_back(*names_and_types_list)
|
||||
("WatchID", new DB::DataTypeUInt64)
|
||||
("JavaEnable", new DB::DataTypeUInt8)
|
||||
("Title", new DB::DataTypeString)
|
||||
@ -96,13 +93,13 @@ int main(int argc, char ** argv)
|
||||
|
||||
SharedPtr<DB::DataTypes> data_types = new DB::DataTypes;
|
||||
|
||||
for (NamesAndTypesList::const_iterator it = names_and_types_list.begin(); it != names_and_types_list.end(); ++it)
|
||||
for (DB::NamesAndTypesList::const_iterator it = names_and_types_list->begin(); it != names_and_types_list->end(); ++it)
|
||||
data_types->push_back(it->second);
|
||||
|
||||
/// создаём описание, как читать данные из tab separated дампа
|
||||
|
||||
DB::Block sample;
|
||||
for (NamesAndTypesList::const_iterator it = names_and_types_list.begin(); it != names_and_types_list.end(); ++it)
|
||||
for (DB::NamesAndTypesList::const_iterator it = names_and_types_list->begin(); it != names_and_types_list->end(); ++it)
|
||||
{
|
||||
DB::ColumnWithNameAndType elem;
|
||||
elem.name = it->first;
|
||||
|
@ -35,12 +35,9 @@ int main(int argc, char ** argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
typedef std::pair<std::string, SharedPtr<DB::IDataType> > NameAndTypePair;
|
||||
typedef std::list<NameAndTypePair> NamesAndTypesList;
|
||||
DB::NamesAndTypesListPtr names_and_types_list = new DB::NamesAndTypesList;
|
||||
|
||||
NamesAndTypesList names_and_types_list;
|
||||
|
||||
boost::assign::push_back(names_and_types_list)
|
||||
boost::assign::push_back(*names_and_types_list)
|
||||
("WatchID", new DB::DataTypeUInt64)
|
||||
("JavaEnable", new DB::DataTypeUInt8)
|
||||
("Title", new DB::DataTypeString)
|
||||
@ -101,8 +98,6 @@ int main(int argc, char ** argv)
|
||||
("WithHash", new DB::DataTypeUInt8)
|
||||
;
|
||||
|
||||
SharedPtr<DB::NamesAndTypes> names_and_types_map = new DB::NamesAndTypes;
|
||||
|
||||
DB::Context context;
|
||||
|
||||
/* (*context.functions)["plus"] = new DB::FunctionPlus;
|
||||
@ -124,11 +119,8 @@ int main(int argc, char ** argv)
|
||||
(*context.functions)["xor"] = new DB::FunctionXor;
|
||||
(*context.functions)["not"] = new DB::FunctionNot;
|
||||
*/
|
||||
for (NamesAndTypesList::const_iterator it = names_and_types_list.begin(); it != names_and_types_list.end(); ++it)
|
||||
{
|
||||
names_and_types_map->insert(*it);
|
||||
for (DB::NamesAndTypesList::const_iterator it = names_and_types_list->begin(); it != names_and_types_list->end(); ++it)
|
||||
context.columns[it->first] = it->second;
|
||||
}
|
||||
|
||||
DB::ParserSelectQuery parser;
|
||||
DB::ASTPtr ast;
|
||||
@ -152,7 +144,7 @@ int main(int argc, char ** argv)
|
||||
|
||||
/// создаём объект существующей таблицы хит лога
|
||||
|
||||
DB::StorageLog table("./", "HitLog", names_and_types_map, ".bin");
|
||||
DB::StorageLog table("./", "HitLog", names_and_types_list, ".bin");
|
||||
|
||||
/// читаем из неё, применяем выражение, фильтруем, и пишем в tsv виде в консоль
|
||||
|
||||
|
@ -30,12 +30,9 @@ int main(int argc, char ** argv)
|
||||
|
||||
try
|
||||
{
|
||||
typedef std::pair<std::string, SharedPtr<DB::IDataType> > NameAndTypePair;
|
||||
typedef std::list<NameAndTypePair> NamesAndTypesList;
|
||||
DB::NamesAndTypesListPtr names_and_types_list = new DB::NamesAndTypesList;
|
||||
|
||||
NamesAndTypesList names_and_types_list;
|
||||
|
||||
boost::assign::push_back(names_and_types_list)
|
||||
boost::assign::push_back(*names_and_types_list)
|
||||
("WatchID", new DB::DataTypeUInt64)
|
||||
("JavaEnable", new DB::DataTypeUInt8)
|
||||
("Title", new DB::DataTypeString)
|
||||
@ -96,18 +93,14 @@ int main(int argc, char ** argv)
|
||||
("WithHash", new DB::DataTypeUInt8)
|
||||
;
|
||||
|
||||
SharedPtr<DB::NamesAndTypes> names_and_types_map = new DB::NamesAndTypes;
|
||||
DB::Names column_names;
|
||||
|
||||
for (NamesAndTypesList::const_iterator it = names_and_types_list.begin(); it != names_and_types_list.end(); ++it)
|
||||
{
|
||||
names_and_types_map->insert(*it);
|
||||
for (DB::NamesAndTypesList::const_iterator it = names_and_types_list->begin(); it != names_and_types_list->end(); ++it)
|
||||
column_names.push_back(it->first);
|
||||
}
|
||||
|
||||
/// создаём объект существующей таблицы хит лога
|
||||
|
||||
DB::StorageLog table("./", "HitLog", names_and_types_map, ".bin");
|
||||
DB::StorageLog table("./", "HitLog", names_and_types_list, ".bin");
|
||||
|
||||
/// читаем из неё
|
||||
if (argc == 2 && 0 == strcmp(argv[1], "read"))
|
||||
|
@ -35,12 +35,9 @@ int main(int argc, char ** argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
typedef std::pair<std::string, SharedPtr<DB::IDataType> > NameAndTypePair;
|
||||
typedef std::list<NameAndTypePair> NamesAndTypesList;
|
||||
DB::NamesAndTypesListPtr names_and_types_list = new DB::NamesAndTypesList;
|
||||
|
||||
NamesAndTypesList names_and_types_list;
|
||||
|
||||
boost::assign::push_back(names_and_types_list)
|
||||
boost::assign::push_back(*names_and_types_list)
|
||||
("WatchID", new DB::DataTypeUInt64)
|
||||
("JavaEnable", new DB::DataTypeUInt8)
|
||||
("Title", new DB::DataTypeString)
|
||||
@ -101,9 +98,9 @@ int main(int argc, char ** argv)
|
||||
("WithHash", new DB::DataTypeUInt8)
|
||||
;
|
||||
|
||||
SharedPtr<DB::NamesAndTypes> names_and_types_map = new DB::NamesAndTypes;
|
||||
DB::NamesAndTypesMapPtr names_and_types_map = new DB::NamesAndTypesMap;
|
||||
|
||||
for (NamesAndTypesList::const_iterator it = names_and_types_list.begin(); it != names_and_types_list.end(); ++it)
|
||||
for (DB::NamesAndTypesList::const_iterator it = names_and_types_list->begin(); it != names_and_types_list->end(); ++it)
|
||||
names_and_types_map->insert(*it);
|
||||
|
||||
DB::ParserSelectQuery parser;
|
||||
@ -128,7 +125,7 @@ int main(int argc, char ** argv)
|
||||
|
||||
/// создаём объект существующей таблицы хит лога
|
||||
|
||||
DB::StorageLog table("./", "HitLog", names_and_types_map, ".bin");
|
||||
DB::StorageLog table("./", "HitLog", names_and_types_list, ".bin");
|
||||
|
||||
/// читаем из неё, сортируем, и пишем в tsv виде в консоль
|
||||
|
||||
|
@ -24,7 +24,7 @@ void Expression::addSemantic(ASTPtr & ast)
|
||||
if (dynamic_cast<ASTAsterisk *>(&*ast))
|
||||
{
|
||||
ASTExpressionList * all_columns = new ASTExpressionList(ast->range);
|
||||
for (NamesAndTypes::const_iterator it = context.columns.begin(); it != context.columns.end(); ++it)
|
||||
for (NamesAndTypesMap::const_iterator it = context.columns.begin(); it != context.columns.end(); ++it)
|
||||
all_columns->children.push_back(new ASTIdentifier(ast->range, it->first));
|
||||
ast = all_columns;
|
||||
|
||||
@ -68,7 +68,7 @@ void Expression::addSemantic(ASTPtr & ast)
|
||||
{
|
||||
if (node->kind == ASTIdentifier::Column)
|
||||
{
|
||||
NamesAndTypes::const_iterator it = context.columns.find(node->name);
|
||||
NamesAndTypesMap::const_iterator it = context.columns.find(node->name);
|
||||
if (it == context.columns.end())
|
||||
throw Exception("Unknown identifier " + node->name, ErrorCodes::UNKNOWN_IDENTIFIER);
|
||||
|
||||
|
@ -31,7 +31,7 @@ StoragePtr InterpreterCreateQuery::execute()
|
||||
String as_database_name = create.as_database.empty() ? context.current_database : create.as_database;
|
||||
String as_table_name = create.as_table;
|
||||
|
||||
NamesAndTypesPtr columns = new NamesAndTypes;
|
||||
NamesAndTypesListPtr columns = new NamesAndTypesList;
|
||||
String data_path = context.path + "data/" + database_name + "/"; /// TODO: эскейпинг
|
||||
String metadata_path = context.path + "metadata/" + database_name + "/" + table_name + ".sql";
|
||||
|
||||
@ -64,17 +64,19 @@ StoragePtr InterpreterCreateQuery::execute()
|
||||
{
|
||||
ASTNameTypePair & name_and_type_pair = dynamic_cast<ASTNameTypePair &>(**it);
|
||||
StringRange type_range = name_and_type_pair.type->range;
|
||||
(*columns)[name_and_type_pair.name] = context.data_type_factory->get(String(type_range.first, type_range.second - type_range.first));
|
||||
columns->push_back(NameAndTypePair(
|
||||
name_and_type_pair.name,
|
||||
context.data_type_factory->get(String(type_range.first, type_range.second - type_range.first))));
|
||||
}
|
||||
}
|
||||
else if (!create.as_table.empty())
|
||||
columns = new NamesAndTypes((*context.databases)[as_database_name][as_table_name]->getColumns());
|
||||
columns = new NamesAndTypesList((*context.databases)[as_database_name][as_table_name]->getColumnsList());
|
||||
else if (create.select)
|
||||
{
|
||||
Block sample = interpreter_select->getSampleBlock();
|
||||
columns = new NamesAndTypes;
|
||||
columns = new NamesAndTypesList;
|
||||
for (size_t i = 0; i < sample.columns(); ++i)
|
||||
(*columns)[sample.getByPosition(i).name] = sample.getByPosition(i).type;
|
||||
columns->push_back(NameAndTypePair(sample.getByPosition(i).name, sample.getByPosition(i).type));
|
||||
}
|
||||
else
|
||||
throw Exception("Incorrect CREATE query: required list of column descriptions or AS section or SELECT.", ErrorCodes::INCORRECT_QUERY);
|
||||
@ -108,7 +110,7 @@ StoragePtr InterpreterCreateQuery::execute()
|
||||
metadata_file << "ATTACH TABLE " << table_name << "\n"
|
||||
<< "(\n";
|
||||
|
||||
for (NamesAndTypes::const_iterator it = columns->begin(); it != columns->end(); ++it)
|
||||
for (NamesAndTypesList::const_iterator it = columns->begin(); it != columns->end(); ++it)
|
||||
metadata_file << (it != columns->begin() ? ",\n" : "") << "\t" << it->first << " " << it->second->getName();
|
||||
|
||||
metadata_file << "\n) ENGINE = " << storage_name << "\n";
|
||||
|
@ -64,7 +64,7 @@ StoragePtr InterpreterSelectQuery::getTable()
|
||||
|
||||
DataTypes InterpreterSelectQuery::getReturnTypes()
|
||||
{
|
||||
context.columns = getTable()->getColumns();
|
||||
context.columns = getTable()->getColumnsMap();
|
||||
Expression expression(dynamic_cast<ASTSelectQuery &>(*query_ptr).select_expression_list, context);
|
||||
return expression.getReturnTypes();
|
||||
}
|
||||
@ -72,7 +72,7 @@ DataTypes InterpreterSelectQuery::getReturnTypes()
|
||||
|
||||
Block InterpreterSelectQuery::getSampleBlock()
|
||||
{
|
||||
context.columns = getTable()->getColumns();
|
||||
context.columns = getTable()->getColumnsMap();
|
||||
Expression expression(dynamic_cast<ASTSelectQuery &>(*query_ptr).select_expression_list, context);
|
||||
return expression.getSampleBlock();
|
||||
}
|
||||
@ -86,13 +86,13 @@ BlockInputStreamPtr InterpreterSelectQuery::execute()
|
||||
|
||||
/// Какие столбцы читать из этой таблицы
|
||||
|
||||
context.columns = table->getColumns();
|
||||
context.columns = table->getColumnsMap();
|
||||
Poco::SharedPtr<Expression> expression = new Expression(query_ptr, context);
|
||||
Names required_columns = expression->getRequiredColumns();
|
||||
|
||||
/// Если не указан ни один столбец из таблицы, то будем читать первый попавшийся (чтобы хотя бы знать число строк).
|
||||
if (required_columns.empty())
|
||||
required_columns.push_back(table->getColumns().begin()->first);
|
||||
required_columns.push_back(table->getColumnsMap().begin()->first);
|
||||
|
||||
size_t limit_length = 0;
|
||||
size_t limit_offset = 0;
|
||||
|
@ -43,12 +43,9 @@ int main(int argc, char ** argv)
|
||||
/// Заранее инициализируем DateLUT, чтобы первая инициализация потом не влияла на измеряемую скорость выполнения.
|
||||
Yandex::DateLUTSingleton::instance();
|
||||
|
||||
typedef std::pair<std::string, SharedPtr<DB::IDataType> > NameAndTypePair;
|
||||
typedef std::list<NameAndTypePair> NamesAndTypesList;
|
||||
DB::NamesAndTypesListPtr names_and_types_list = new DB::NamesAndTypesList;
|
||||
|
||||
NamesAndTypesList names_and_types_list;
|
||||
|
||||
boost::assign::push_back(names_and_types_list)
|
||||
boost::assign::push_back(*names_and_types_list)
|
||||
("WatchID", new DB::DataTypeUInt64)
|
||||
("JavaEnable", new DB::DataTypeUInt8)
|
||||
("Title", new DB::DataTypeString)
|
||||
@ -109,13 +106,6 @@ int main(int argc, char ** argv)
|
||||
("WithHash", new DB::DataTypeUInt8)
|
||||
;
|
||||
|
||||
SharedPtr<DB::NamesAndTypes> names_and_types_map = new DB::NamesAndTypes;
|
||||
|
||||
for (NamesAndTypesList::const_iterator it = names_and_types_list.begin(); it != names_and_types_list.end(); ++it)
|
||||
{
|
||||
names_and_types_map->insert(*it);
|
||||
}
|
||||
|
||||
DB::Context context;
|
||||
|
||||
boost::assign::insert(*context.functions)
|
||||
@ -193,9 +183,9 @@ int main(int argc, char ** argv)
|
||||
|
||||
DB::loadMetadata(context);
|
||||
|
||||
(*context.databases)["default"]["hits"] = new DB::StorageLog("./data/default/", "hits", names_and_types_map, ".bin");
|
||||
(*context.databases)["default"]["hits2"] = new DB::StorageLog("./data/default/", "hits2", names_and_types_map, ".bin");
|
||||
(*context.databases)["default"]["hits3"] = new DB::StorageLog("./data/default/", "hits3", names_and_types_map, ".bin");
|
||||
(*context.databases)["default"]["hits"] = new DB::StorageLog("./data/default/", "hits", names_and_types_list, ".bin");
|
||||
(*context.databases)["default"]["hits2"] = new DB::StorageLog("./data/default/", "hits2", names_and_types_list, ".bin");
|
||||
(*context.databases)["default"]["hits3"] = new DB::StorageLog("./data/default/", "hits3", names_and_types_list, ".bin");
|
||||
(*context.databases)["system"]["one"] = new DB::StorageSystemOne("one");
|
||||
(*context.databases)["system"]["numbers"] = new DB::StorageSystemNumbers("numbers");
|
||||
context.current_database = "default";
|
||||
|
@ -6,10 +6,10 @@
|
||||
namespace DB
|
||||
{
|
||||
|
||||
static std::string listOfColumns(const NamesAndTypes & available_columns)
|
||||
static std::string listOfColumns(const NamesAndTypesMap & available_columns)
|
||||
{
|
||||
std::stringstream s;
|
||||
for (NamesAndTypes::const_iterator it = available_columns.begin(); it != available_columns.end(); ++it)
|
||||
for (NamesAndTypesMap::const_iterator it = available_columns.begin(); it != available_columns.end(); ++it)
|
||||
{
|
||||
if (it != available_columns.begin())
|
||||
s << ", ";
|
||||
@ -19,12 +19,35 @@ static std::string listOfColumns(const NamesAndTypes & available_columns)
|
||||
}
|
||||
|
||||
|
||||
NamesAndTypesMap IStorage::getColumnsMap() const
|
||||
{
|
||||
NamesAndTypesMap res;
|
||||
|
||||
const NamesAndTypesList & names_and_types = getColumnsList();
|
||||
for (NamesAndTypesList::const_iterator it = names_and_types.begin(); it != names_and_types.end(); ++it)
|
||||
res.insert(*it);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
const DataTypePtr IStorage::getDataTypeByName(const String & column_name) const
|
||||
{
|
||||
const NamesAndTypesList & names_and_types = getColumnsList();
|
||||
for (NamesAndTypesList::const_iterator it = names_and_types.begin(); it != names_and_types.end(); ++it)
|
||||
if (it->first == column_name)
|
||||
return it->second;
|
||||
|
||||
throw Exception("There is no column " + column_name + " in table " + getTableName(), ErrorCodes::NO_SUCH_COLUMN_IN_TABLE);
|
||||
}
|
||||
|
||||
|
||||
Block IStorage::getSampleBlock() const
|
||||
{
|
||||
Block res;
|
||||
const NamesAndTypes & names_and_types = getColumns();
|
||||
const NamesAndTypesList & names_and_types = getColumnsList();
|
||||
|
||||
for (NamesAndTypes::const_iterator it = names_and_types.begin(); it != names_and_types.end(); ++it)
|
||||
for (NamesAndTypesList::const_iterator it = names_and_types.begin(); it != names_and_types.end(); ++it)
|
||||
{
|
||||
ColumnWithNameAndType col;
|
||||
col.name = it->first;
|
||||
@ -39,7 +62,7 @@ Block IStorage::getSampleBlock() const
|
||||
|
||||
void IStorage::check(const Names & column_names) const
|
||||
{
|
||||
const NamesAndTypes & available_columns = getColumns();
|
||||
const NamesAndTypesMap & available_columns = getColumnsMap();
|
||||
|
||||
if (column_names.empty())
|
||||
throw Exception("Empty list of columns queried for table " + getTableName()
|
||||
@ -66,13 +89,13 @@ void IStorage::check(const Names & column_names) const
|
||||
|
||||
void IStorage::check(const Block & block) const
|
||||
{
|
||||
const NamesAndTypes & available_columns = getColumns();
|
||||
const NamesAndTypesMap & available_columns = getColumnsMap();
|
||||
|
||||
for (size_t i = 0; i < block.columns(); ++i)
|
||||
{
|
||||
const ColumnWithNameAndType & column = block.getByPosition(i);
|
||||
|
||||
NamesAndTypes::const_iterator it = available_columns.find(column.name);
|
||||
NamesAndTypesMap::const_iterator it = available_columns.find(column.name);
|
||||
if (available_columns.end() == it)
|
||||
throw Exception("There is no column with name " + column.name + " in table " + getTableName()
|
||||
+ ". There are columns: " + listOfColumns(available_columns),
|
||||
|
@ -13,7 +13,7 @@ StoragePtr StorageFactory::get(
|
||||
const String & name,
|
||||
const String & data_path,
|
||||
const String & table_name,
|
||||
NamesAndTypesPtr columns) const
|
||||
NamesAndTypesListPtr columns) const
|
||||
{
|
||||
if (name == "Log")
|
||||
return new StorageLog(data_path, table_name, columns);
|
||||
|
@ -28,7 +28,7 @@ Block LogBlockInputStream::readImpl()
|
||||
{
|
||||
ColumnWithNameAndType column;
|
||||
column.name = *it;
|
||||
column.type = (*storage.columns)[*it];
|
||||
column.type = storage.getDataTypeByName(*it);
|
||||
column.column = column.type->createColumn();
|
||||
column.type->deserializeBinary(*column.column, streams[column.name]->compressed, block_size);
|
||||
|
||||
@ -43,7 +43,7 @@ Block LogBlockInputStream::readImpl()
|
||||
LogBlockOutputStream::LogBlockOutputStream(StorageLog & storage_)
|
||||
: storage(storage_)
|
||||
{
|
||||
for (NamesAndTypes::const_iterator it = storage.columns->begin(); it != storage.columns->end(); ++it)
|
||||
for (NamesAndTypesList::const_iterator it = storage.columns->begin(); it != storage.columns->end(); ++it)
|
||||
streams.insert(std::make_pair(it->first, new Stream(storage.files[it->first].path())));
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ void LogBlockOutputStream::write(const Block & block)
|
||||
}
|
||||
|
||||
|
||||
StorageLog::StorageLog(const std::string & path_, const std::string & name_, NamesAndTypesPtr columns_,
|
||||
StorageLog::StorageLog(const std::string & path_, const std::string & name_, NamesAndTypesListPtr columns_,
|
||||
const std::string & extension_)
|
||||
: path(path_), name(name_), columns(columns_), extension(extension_)
|
||||
{
|
||||
@ -68,7 +68,7 @@ StorageLog::StorageLog(const std::string & path_, const std::string & name_, Nam
|
||||
Poco::File dir(path + name + '/');
|
||||
dir.createDirectories();
|
||||
|
||||
for (NamesAndTypes::const_iterator it = columns->begin(); it != columns->end(); ++it)
|
||||
for (NamesAndTypesList::const_iterator it = columns->begin(); it != columns->end(); ++it)
|
||||
{
|
||||
if (files.end() != files.find(it->first))
|
||||
throw Exception("Duplicate column with name " + it->first + " in constructor of StorageLog.",
|
||||
|
@ -40,7 +40,7 @@ void MemoryBlockOutputStream::write(const Block & block)
|
||||
}
|
||||
|
||||
|
||||
StorageMemory::StorageMemory(const std::string & name_, NamesAndTypesPtr columns_)
|
||||
StorageMemory::StorageMemory(const std::string & name_, NamesAndTypesListPtr columns_)
|
||||
: name(name_), columns(columns_)
|
||||
{
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ Block NumbersBlockInputStream::readImpl()
|
||||
StorageSystemNumbers::StorageSystemNumbers(const std::string & name_)
|
||||
: name(name_)
|
||||
{
|
||||
columns["number"] = new DataTypeUInt64;
|
||||
columns.push_back(NameAndTypePair("number", new DataTypeUInt64));
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,7 +36,7 @@ Block OneValueBlockInputStream::readImpl()
|
||||
StorageSystemOne::StorageSystemOne(const std::string & name_)
|
||||
: name(name_)
|
||||
{
|
||||
columns["dummy"] = new DataTypeUInt8;
|
||||
columns.push_back(NameAndTypePair("dummy", new DataTypeUInt8));
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,12 +28,9 @@ int main(int argc, char ** argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
typedef std::pair<std::string, SharedPtr<DB::IDataType> > NameAndTypePair;
|
||||
typedef std::list<NameAndTypePair> NamesAndTypesList;
|
||||
DB::NamesAndTypesListPtr names_and_types_list = new DB::NamesAndTypesList;
|
||||
|
||||
NamesAndTypesList names_and_types_list;
|
||||
|
||||
boost::assign::push_back(names_and_types_list)
|
||||
boost::assign::push_back(*names_and_types_list)
|
||||
("WatchID", new DB::DataTypeUInt64)
|
||||
("JavaEnable", new DB::DataTypeUInt8)
|
||||
("Title", new DB::DataTypeString)
|
||||
@ -94,25 +91,23 @@ int main(int argc, char ** argv)
|
||||
("WithHash", new DB::DataTypeUInt8)
|
||||
;
|
||||
|
||||
SharedPtr<DB::NamesAndTypes> names_and_types_map = new DB::NamesAndTypes;
|
||||
SharedPtr<DB::DataTypes> data_types = new DB::DataTypes;
|
||||
DB::Names column_names;
|
||||
|
||||
for (NamesAndTypesList::const_iterator it = names_and_types_list.begin(); it != names_and_types_list.end(); ++it)
|
||||
for (DB::NamesAndTypesList::const_iterator it = names_and_types_list->begin(); it != names_and_types_list->end(); ++it)
|
||||
{
|
||||
names_and_types_map->insert(*it);
|
||||
data_types->push_back(it->second);
|
||||
column_names.push_back(it->first);
|
||||
}
|
||||
|
||||
/// создаём таблицу хит лога
|
||||
|
||||
DB::StorageLog table("./", "HitLog", names_and_types_map, ".bin");
|
||||
DB::StorageLog table("./", "HitLog", names_and_types_list, ".bin");
|
||||
|
||||
/// создаём описание, как читать данные из tab separated дампа
|
||||
|
||||
DB::Block sample;
|
||||
for (NamesAndTypesList::const_iterator it = names_and_types_list.begin(); it != names_and_types_list.end(); ++it)
|
||||
for (DB::NamesAndTypesList::const_iterator it = names_and_types_list->begin(); it != names_and_types_list->end(); ++it)
|
||||
{
|
||||
DB::ColumnWithNameAndType elem;
|
||||
elem.name = it->first;
|
||||
|
@ -21,9 +21,9 @@ int main(int argc, char ** argv)
|
||||
|
||||
/// создаём таблицу с парой столбцов
|
||||
|
||||
SharedPtr<DB::NamesAndTypes> names_and_types = new DB::NamesAndTypes;
|
||||
(*names_and_types)["a"] = new DB::DataTypeUInt64;
|
||||
(*names_and_types)["b"] = new DB::DataTypeUInt8;
|
||||
DB::NamesAndTypesListPtr names_and_types = new DB::NamesAndTypesList;
|
||||
names_and_types->push_back(DB::NameAndTypePair("a", new DB::DataTypeUInt64));
|
||||
names_and_types->push_back(DB::NameAndTypePair("b", new DB::DataTypeUInt8));
|
||||
|
||||
DB::StorageLog table("./", "test", names_and_types, ".bin");
|
||||
|
||||
@ -33,7 +33,7 @@ int main(int argc, char ** argv)
|
||||
|
||||
DB::ColumnWithNameAndType column1;
|
||||
column1.name = "a";
|
||||
column1.type = (*names_and_types)["a"];
|
||||
column1.type = table.getDataTypeByName("a");
|
||||
column1.column = column1.type->createColumn();
|
||||
DB::ColumnUInt64::Container_t & vec1 = dynamic_cast<DB::ColumnUInt64&>(*column1.column).getData();
|
||||
|
||||
@ -45,7 +45,7 @@ int main(int argc, char ** argv)
|
||||
|
||||
DB::ColumnWithNameAndType column2;
|
||||
column2.name = "b";
|
||||
column2.type = (*names_and_types)["b"];
|
||||
column2.type = table.getDataTypeByName("b");
|
||||
column2.column = column2.type->createColumn();
|
||||
DB::ColumnUInt8::Container_t & vec2 = dynamic_cast<DB::ColumnUInt8&>(*column2.column).getData();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user