ClickHouse/dbms/src/Interpreters/InterpreterQuery.cpp

227 lines
6.8 KiB
C++
Raw Normal View History

2011-10-30 11:30:52 +00:00
#include <DB/Parsers/ASTInsertQuery.h>
#include <DB/Parsers/ASTSelectQuery.h>
#include <DB/Parsers/ASTCreateQuery.h>
2011-11-05 23:31:19 +00:00
#include <DB/Parsers/ASTDropQuery.h>
2012-06-18 06:19:13 +00:00
#include <DB/Parsers/ASTRenameQuery.h>
2012-06-18 07:49:19 +00:00
#include <DB/Parsers/ASTShowTablesQuery.h>
2012-07-12 19:49:22 +00:00
#include <DB/Parsers/ASTUseQuery.h>
2012-08-02 19:03:32 +00:00
#include <DB/Parsers/ASTSetQuery.h>
2012-07-31 19:08:49 +00:00
#include <DB/Parsers/ASTOptimizeQuery.h>
2013-08-07 13:07:42 +00:00
#include <DB/Parsers/ASTAlterQuery.h>
#include <DB/Parsers/TablePropertiesQueriesASTs.h>
2014-08-05 10:52:06 +00:00
#include <DB/Parsers/ASTCheckQuery.h>
2011-10-30 11:30:52 +00:00
#include <DB/Interpreters/InterpreterSelectQuery.h>
#include <DB/Interpreters/InterpreterInsertQuery.h>
#include <DB/Interpreters/InterpreterCreateQuery.h>
2011-11-05 23:31:19 +00:00
#include <DB/Interpreters/InterpreterDropQuery.h>
2012-06-18 06:19:13 +00:00
#include <DB/Interpreters/InterpreterRenameQuery.h>
2012-06-18 07:49:19 +00:00
#include <DB/Interpreters/InterpreterShowTablesQuery.h>
2012-07-12 19:49:22 +00:00
#include <DB/Interpreters/InterpreterUseQuery.h>
2012-08-02 19:03:32 +00:00
#include <DB/Interpreters/InterpreterSetQuery.h>
2012-07-31 19:08:49 +00:00
#include <DB/Interpreters/InterpreterOptimizeQuery.h>
#include <DB/Interpreters/InterpreterExistsQuery.h>
#include <DB/Interpreters/InterpreterDescribeQuery.h>
#include <DB/Interpreters/InterpreterShowCreateQuery.h>
2011-10-30 11:30:52 +00:00
#include <DB/Interpreters/InterpreterQuery.h>
2013-08-07 13:07:42 +00:00
#include <DB/Interpreters/InterpreterAlterQuery.h>
#include <DB/Interpreters/InterpreterShowProcesslistQuery.h>
2014-08-05 10:52:06 +00:00
#include <DB/Interpreters/InterpreterCheckQuery.h>
2011-10-30 11:30:52 +00:00
namespace DB
{
2012-05-22 18:32:45 +00:00
InterpreterQuery::InterpreterQuery(ASTPtr query_ptr_, Context & context_, QueryProcessingStage::Enum stage_)
: query_ptr(query_ptr_), context(context_), stage(stage_)
2011-10-30 11:30:52 +00:00
{
}
2012-01-09 19:20:48 +00:00
void InterpreterQuery::execute(WriteBuffer & ostr, ReadBuffer * remaining_data_istr, BlockInputStreamPtr & query_plan)
2011-10-30 11:30:52 +00:00
{
if (typeid_cast<ASTSelectQuery *>(&*query_ptr))
2011-10-30 11:30:52 +00:00
{
2012-05-22 18:32:45 +00:00
InterpreterSelectQuery interpreter(query_ptr, context, stage);
2011-10-30 11:30:52 +00:00
query_plan = interpreter.executeAndFormat(ostr);
}
else if (typeid_cast<ASTInsertQuery *>(&*query_ptr))
2011-10-30 11:30:52 +00:00
{
throwIfReadOnly();
2012-03-05 00:09:41 +00:00
InterpreterInsertQuery interpreter(query_ptr, context);
2011-10-30 11:30:52 +00:00
interpreter.execute(remaining_data_istr);
}
else if (typeid_cast<ASTCreateQuery *>(&*query_ptr))
2011-10-30 11:30:52 +00:00
{
throwIfReadOnly();
2012-03-05 00:09:41 +00:00
InterpreterCreateQuery interpreter(query_ptr, context);
2011-11-01 15:16:04 +00:00
interpreter.execute();
2011-10-30 11:30:52 +00:00
}
else if (typeid_cast<ASTDropQuery *>(&*query_ptr))
2011-11-05 23:31:19 +00:00
{
throwIfReadOnly();
2011-11-05 23:31:19 +00:00
InterpreterDropQuery interpreter(query_ptr, context);
interpreter.execute();
}
else if (typeid_cast<ASTRenameQuery *>(&*query_ptr))
2012-06-18 06:19:13 +00:00
{
throwIfReadOnly();
2012-06-18 06:19:13 +00:00
InterpreterRenameQuery interpreter(query_ptr, context);
interpreter.execute();
}
else if (typeid_cast<ASTShowTablesQuery *>(&*query_ptr))
2012-06-18 07:49:19 +00:00
{
InterpreterShowTablesQuery interpreter(query_ptr, context);
query_plan = interpreter.executeAndFormat(ostr);
}
else if (typeid_cast<ASTUseQuery *>(&*query_ptr))
2012-07-12 19:49:22 +00:00
{
InterpreterUseQuery interpreter(query_ptr, context);
interpreter.execute();
}
else if (typeid_cast<ASTSetQuery *>(&*query_ptr))
2012-08-02 19:03:32 +00:00
{
/// readonly проверяется внутри InterpreterSetQuery
2012-08-02 19:03:32 +00:00
InterpreterSetQuery interpreter(query_ptr, context);
interpreter.execute();
}
else if (typeid_cast<ASTOptimizeQuery *>(&*query_ptr))
2012-07-31 19:08:49 +00:00
{
throwIfReadOnly();
2012-07-31 19:08:49 +00:00
InterpreterOptimizeQuery interpreter(query_ptr, context);
interpreter.execute();
}
else if (typeid_cast<ASTExistsQuery *>(&*query_ptr))
{
InterpreterExistsQuery interpreter(query_ptr, context);
query_plan = interpreter.executeAndFormat(ostr);
}
else if (typeid_cast<ASTShowCreateQuery *>(&*query_ptr))
{
InterpreterShowCreateQuery interpreter(query_ptr, context);
query_plan = interpreter.executeAndFormat(ostr);
}
else if (typeid_cast<ASTDescribeQuery *>(&*query_ptr))
{
InterpreterDescribeQuery interpreter(query_ptr, context);
query_plan = interpreter.executeAndFormat(ostr);
}
else if (typeid_cast<ASTShowProcesslistQuery *>(&*query_ptr))
{
InterpreterShowProcesslistQuery interpreter(query_ptr, context);
query_plan = interpreter.executeAndFormat(ostr);
}
else if (typeid_cast<ASTAlterQuery *>(&*query_ptr))
2013-08-07 13:07:42 +00:00
{
throwIfReadOnly();
InterpreterAlterQuery interpreter(query_ptr, context);
interpreter.execute();
}
2014-08-05 10:52:06 +00:00
else if (typeid_cast<ASTCheckQuery *>(&*query_ptr))
{
InterpreterCheckQuery interpreter(query_ptr, context);
query_plan = interpreter.execute();
}
2011-10-30 11:30:52 +00:00
else
throw Exception("Unknown type of query: " + query_ptr->getID(), ErrorCodes::UNKNOWN_TYPE_OF_QUERY);
}
2012-03-11 08:52:56 +00:00
BlockIO InterpreterQuery::execute()
{
BlockIO res;
if (typeid_cast<ASTSelectQuery *>(&*query_ptr))
2012-03-11 08:52:56 +00:00
{
2012-05-30 01:38:02 +00:00
InterpreterSelectQuery interpreter(query_ptr, context, stage);
2012-03-11 08:52:56 +00:00
res.in = interpreter.execute();
2012-03-19 12:57:56 +00:00
res.in_sample = interpreter.getSampleBlock();
2012-03-11 08:52:56 +00:00
}
else if (typeid_cast<ASTInsertQuery *>(&*query_ptr))
2012-03-11 08:52:56 +00:00
{
throwIfReadOnly();
2012-03-11 08:52:56 +00:00
InterpreterInsertQuery interpreter(query_ptr, context);
res = interpreter.execute();
2012-03-11 08:52:56 +00:00
}
else if (typeid_cast<ASTCreateQuery *>(&*query_ptr))
2012-03-11 08:52:56 +00:00
{
throwIfReadOnly();
2012-03-11 08:52:56 +00:00
InterpreterCreateQuery interpreter(query_ptr, context);
interpreter.execute();
}
else if (typeid_cast<ASTDropQuery *>(&*query_ptr))
2012-03-11 08:52:56 +00:00
{
throwIfReadOnly();
2012-03-11 08:52:56 +00:00
InterpreterDropQuery interpreter(query_ptr, context);
interpreter.execute();
}
else if (typeid_cast<ASTRenameQuery *>(&*query_ptr))
2012-06-18 06:19:13 +00:00
{
throwIfReadOnly();
2012-06-18 06:19:13 +00:00
InterpreterRenameQuery interpreter(query_ptr, context);
interpreter.execute();
}
else if (typeid_cast<ASTShowTablesQuery *>(&*query_ptr))
2012-06-18 07:49:19 +00:00
{
InterpreterShowTablesQuery interpreter(query_ptr, context);
res = interpreter.execute();
}
else if (typeid_cast<ASTUseQuery *>(&*query_ptr))
2012-07-12 19:49:22 +00:00
{
InterpreterUseQuery interpreter(query_ptr, context);
interpreter.execute();
}
else if (typeid_cast<ASTSetQuery *>(&*query_ptr))
2012-08-02 19:03:32 +00:00
{
/// readonly проверяется внутри InterpreterSetQuery
2012-08-02 19:03:32 +00:00
InterpreterSetQuery interpreter(query_ptr, context);
interpreter.execute();
}
else if (typeid_cast<ASTOptimizeQuery *>(&*query_ptr))
2012-07-31 19:08:49 +00:00
{
throwIfReadOnly();
2012-07-31 19:08:49 +00:00
InterpreterOptimizeQuery interpreter(query_ptr, context);
interpreter.execute();
}
else if (typeid_cast<ASTExistsQuery *>(&*query_ptr))
{
InterpreterExistsQuery interpreter(query_ptr, context);
res = interpreter.execute();
}
else if (typeid_cast<ASTShowCreateQuery *>(&*query_ptr))
{
InterpreterShowCreateQuery interpreter(query_ptr, context);
res = interpreter.execute();
}
else if (typeid_cast<ASTDescribeQuery *>(&*query_ptr))
{
InterpreterDescribeQuery interpreter(query_ptr, context);
res = interpreter.execute();
}
else if (typeid_cast<ASTShowProcesslistQuery *>(&*query_ptr))
{
InterpreterShowProcesslistQuery interpreter(query_ptr, context);
res = interpreter.execute();
}
else if (typeid_cast<ASTAlterQuery *>(&*query_ptr))
2013-08-07 13:07:42 +00:00
{
throwIfReadOnly();
InterpreterAlterQuery interpreter(query_ptr, context);
interpreter.execute();
}
2014-08-05 10:52:06 +00:00
else if (typeid_cast<ASTCheckQuery *>(&*query_ptr))
{
InterpreterCheckQuery interpreter(query_ptr, context);
res.in = interpreter.execute();
res.in_sample = interpreter.getSampleBlock();
}
2012-03-11 08:52:56 +00:00
else
throw Exception("Unknown type of query: " + query_ptr->getID(), ErrorCodes::UNKNOWN_TYPE_OF_QUERY);
return res;
}
2011-10-30 11:30:52 +00:00
}