#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace DB { InterpreterQuery::InterpreterQuery(ASTPtr query_ptr_, Context & context_, QueryProcessingStage::Enum stage_) : query_ptr(query_ptr_), context(context_), stage(stage_) { } void InterpreterQuery::execute(WriteBuffer & ostr, ReadBuffer * remaining_data_istr, BlockInputStreamPtr & query_plan) { if (typeid_cast(&*query_ptr)) { InterpreterSelectQuery interpreter(query_ptr, context, stage); query_plan = interpreter.executeAndFormat(ostr); } else if (typeid_cast(&*query_ptr)) { throwIfReadOnly(); InterpreterInsertQuery interpreter(query_ptr, context); interpreter.execute(remaining_data_istr); } else if (typeid_cast(&*query_ptr)) { throwIfReadOnly(); InterpreterCreateQuery interpreter(query_ptr, context); interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { throwIfReadOnly(); InterpreterDropQuery interpreter(query_ptr, context); interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { throwIfReadOnly(); InterpreterRenameQuery interpreter(query_ptr, context); interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { InterpreterShowTablesQuery interpreter(query_ptr, context); query_plan = interpreter.executeAndFormat(ostr); } else if (typeid_cast(&*query_ptr)) { InterpreterUseQuery interpreter(query_ptr, context); interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { /// readonly проверяется внутри InterpreterSetQuery InterpreterSetQuery interpreter(query_ptr, context); interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { throwIfReadOnly(); InterpreterOptimizeQuery interpreter(query_ptr, context); interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { InterpreterExistsQuery interpreter(query_ptr, context); query_plan = interpreter.executeAndFormat(ostr); } else if (typeid_cast(&*query_ptr)) { InterpreterShowCreateQuery interpreter(query_ptr, context); query_plan = interpreter.executeAndFormat(ostr); } else if (typeid_cast(&*query_ptr)) { InterpreterDescribeQuery interpreter(query_ptr, context); query_plan = interpreter.executeAndFormat(ostr); } else if (typeid_cast(&*query_ptr)) { InterpreterShowProcesslistQuery interpreter(query_ptr, context); query_plan = interpreter.executeAndFormat(ostr); } else if (typeid_cast(&*query_ptr)) { throwIfReadOnly(); InterpreterAlterQuery interpreter(query_ptr, context); interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { InterpreterCheckQuery interpreter(query_ptr, context); query_plan = interpreter.execute(); } else throw Exception("Unknown type of query: " + query_ptr->getID(), ErrorCodes::UNKNOWN_TYPE_OF_QUERY); } BlockIO InterpreterQuery::execute() { BlockIO res; if (typeid_cast(&*query_ptr)) { InterpreterSelectQuery interpreter(query_ptr, context, stage); res.in = interpreter.execute(); res.in_sample = interpreter.getSampleBlock(); } else if (typeid_cast(&*query_ptr)) { throwIfReadOnly(); InterpreterInsertQuery interpreter(query_ptr, context); res = interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { throwIfReadOnly(); InterpreterCreateQuery interpreter(query_ptr, context); interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { throwIfReadOnly(); InterpreterDropQuery interpreter(query_ptr, context); interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { throwIfReadOnly(); InterpreterRenameQuery interpreter(query_ptr, context); interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { InterpreterShowTablesQuery interpreter(query_ptr, context); res = interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { InterpreterUseQuery interpreter(query_ptr, context); interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { /// readonly проверяется внутри InterpreterSetQuery InterpreterSetQuery interpreter(query_ptr, context); interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { throwIfReadOnly(); InterpreterOptimizeQuery interpreter(query_ptr, context); interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { InterpreterExistsQuery interpreter(query_ptr, context); res = interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { InterpreterShowCreateQuery interpreter(query_ptr, context); res = interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { InterpreterDescribeQuery interpreter(query_ptr, context); res = interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { InterpreterShowProcesslistQuery interpreter(query_ptr, context); res = interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { throwIfReadOnly(); InterpreterAlterQuery interpreter(query_ptr, context); interpreter.execute(); } else if (typeid_cast(&*query_ptr)) { InterpreterCheckQuery interpreter(query_ptr, context); res.in = interpreter.execute(); res.in_sample = interpreter.getSampleBlock(); } else throw Exception("Unknown type of query: " + query_ptr->getID(), ErrorCodes::UNKNOWN_TYPE_OF_QUERY); return res; } }