ClickHouse/dbms/src/Interpreters/InterpreterQuery.cpp

168 lines
4.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>
#include <DB/Parsers/ASTExistsQuery.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>
2011-10-30 11:30:52 +00:00
#include <DB/Interpreters/InterpreterQuery.h>
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 (dynamic_cast<ASTSelectQuery *>(&*query_ptr))
{
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 (dynamic_cast<ASTInsertQuery *>(&*query_ptr))
{
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 (dynamic_cast<ASTCreateQuery *>(&*query_ptr))
{
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
}
2011-11-05 23:31:19 +00:00
else if (dynamic_cast<ASTDropQuery *>(&*query_ptr))
{
throwIfReadOnly();
2011-11-05 23:31:19 +00:00
InterpreterDropQuery interpreter(query_ptr, context);
interpreter.execute();
}
2012-06-18 06:19:13 +00:00
else if (dynamic_cast<ASTRenameQuery *>(&*query_ptr))
{
throwIfReadOnly();
2012-06-18 06:19:13 +00:00
InterpreterRenameQuery interpreter(query_ptr, context);
interpreter.execute();
}
2012-06-18 07:49:19 +00:00
else if (dynamic_cast<ASTShowTablesQuery *>(&*query_ptr))
{
InterpreterShowTablesQuery interpreter(query_ptr, context);
query_plan = interpreter.executeAndFormat(ostr);
}
2012-07-12 19:49:22 +00:00
else if (dynamic_cast<ASTUseQuery *>(&*query_ptr))
{
InterpreterUseQuery interpreter(query_ptr, context);
interpreter.execute();
}
2012-08-02 19:03:32 +00:00
else if (dynamic_cast<ASTSetQuery *>(&*query_ptr))
{
throwIfReadOnly();
2012-08-02 19:03:32 +00:00
InterpreterSetQuery interpreter(query_ptr, context);
interpreter.execute();
}
2012-07-31 19:08:49 +00:00
else if (dynamic_cast<ASTOptimizeQuery *>(&*query_ptr))
{
throwIfReadOnly();
2012-07-31 19:08:49 +00:00
InterpreterOptimizeQuery interpreter(query_ptr, context);
interpreter.execute();
}
2012-12-17 17:21:09 +00:00
else if (dynamic_cast<ASTExistsQuery *>(&*query_ptr))
{
InterpreterExistsQuery interpreter(query_ptr, context);
query_plan = interpreter.executeAndFormat(ostr);
}
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 (dynamic_cast<ASTSelectQuery *>(&*query_ptr))
{
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 (dynamic_cast<ASTInsertQuery *>(&*query_ptr))
{
throwIfReadOnly();
2012-03-11 08:52:56 +00:00
InterpreterInsertQuery interpreter(query_ptr, context);
res.out = interpreter.execute();
2012-03-19 12:57:56 +00:00
res.out_sample = interpreter.getSampleBlock();
2012-03-11 08:52:56 +00:00
}
else if (dynamic_cast<ASTCreateQuery *>(&*query_ptr))
{
throwIfReadOnly();
2012-03-11 08:52:56 +00:00
InterpreterCreateQuery interpreter(query_ptr, context);
interpreter.execute();
}
else if (dynamic_cast<ASTDropQuery *>(&*query_ptr))
{
throwIfReadOnly();
2012-03-11 08:52:56 +00:00
InterpreterDropQuery interpreter(query_ptr, context);
interpreter.execute();
}
2012-06-18 06:19:13 +00:00
else if (dynamic_cast<ASTRenameQuery *>(&*query_ptr))
{
throwIfReadOnly();
2012-06-18 06:19:13 +00:00
InterpreterRenameQuery interpreter(query_ptr, context);
interpreter.execute();
}
2012-06-18 07:49:19 +00:00
else if (dynamic_cast<ASTShowTablesQuery *>(&*query_ptr))
{
InterpreterShowTablesQuery interpreter(query_ptr, context);
res = interpreter.execute();
}
2012-07-12 19:49:22 +00:00
else if (dynamic_cast<ASTUseQuery *>(&*query_ptr))
{
InterpreterUseQuery interpreter(query_ptr, context);
interpreter.execute();
}
2012-08-02 19:03:32 +00:00
else if (dynamic_cast<ASTSetQuery *>(&*query_ptr))
{
throwIfReadOnly();
2012-08-02 19:03:32 +00:00
InterpreterSetQuery interpreter(query_ptr, context);
interpreter.execute();
}
2012-07-31 19:08:49 +00:00
else if (dynamic_cast<ASTOptimizeQuery *>(&*query_ptr))
{
throwIfReadOnly();
2012-07-31 19:08:49 +00:00
InterpreterOptimizeQuery interpreter(query_ptr, context);
interpreter.execute();
}
else if (dynamic_cast<ASTExistsQuery *>(&*query_ptr))
{
InterpreterExistsQuery interpreter(query_ptr, context);
res = interpreter.execute();
}
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
}