2013-09-03 20:21:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/IO/ReadBufferFromString.h>
|
|
|
|
|
|
|
|
#include <DB/Interpreters/executeQuery.h>
|
|
|
|
|
|
|
|
#include <DB/Parsers/ASTQueryWithOutput.h>
|
|
|
|
#include <DB/Parsers/ASTIdentifier.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/** Вернуть список запросов, исполняющихся прямо сейчас.
|
|
|
|
*/
|
|
|
|
class InterpreterShowProcesslistQuery
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
InterpreterShowProcesslistQuery(ASTPtr query_ptr_, Context & context_)
|
|
|
|
: query_ptr(query_ptr_), context(context_) {}
|
|
|
|
|
|
|
|
BlockIO execute()
|
|
|
|
{
|
2013-09-03 23:58:05 +00:00
|
|
|
return executeQuery(getRewrittenQuery(), context, true);
|
2013-09-03 20:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BlockInputStreamPtr executeAndFormat(WriteBuffer & buf)
|
|
|
|
{
|
|
|
|
String query = getRewrittenQuery();
|
|
|
|
ReadBufferFromString in(query);
|
|
|
|
BlockInputStreamPtr query_plan;
|
2013-09-03 23:58:05 +00:00
|
|
|
executeQuery(in, buf, context, query_plan, true);
|
2013-09-03 20:21:28 +00:00
|
|
|
return query_plan;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ASTPtr query_ptr;
|
|
|
|
Context context;
|
|
|
|
|
|
|
|
String getRewrittenQuery()
|
|
|
|
{
|
|
|
|
const ASTQueryWithOutput & query = dynamic_cast<const ASTQueryWithOutput &>(*query_ptr);
|
|
|
|
|
|
|
|
std::stringstream rewritten_query;
|
|
|
|
rewritten_query << "SELECT * FROM system.processes";
|
|
|
|
|
|
|
|
if (query.format)
|
|
|
|
rewritten_query << " FORMAT " << dynamic_cast<const ASTIdentifier &>(*query.format).name;
|
|
|
|
|
|
|
|
return rewritten_query.str();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|