memgraph/include/query_engine/program_executor.hpp

44 lines
1.0 KiB
C++
Raw Normal View History

#pragma once
#include <string>
#include "database/db.hpp"
#include "query_engine/exceptions/exceptions.hpp"
2016-07-18 01:32:35 +08:00
#include "query_engine/util.hpp"
#include "query_program.hpp"
// preparations before execution
// execution
// postprocess the results
// BARRIER!
2016-08-30 12:34:08 +08:00
#ifdef BARRIER
namespace barrier
{
2016-08-30 12:34:08 +08:00
Db &trans(::Db &ref);
}
2016-08-30 12:34:08 +08:00
#endif
template <typename Stream>
class ProgramExecutor
{
public:
// QueryProgram has to know about the Stream
// Stream has to be passed in this function for every execution
2016-08-30 12:34:08 +08:00
auto execute(QueryProgram<Stream> &program, Db &db, Stream &stream)
{
2016-07-18 01:32:35 +08:00
try {
// TODO: return result of query/code exection
2016-08-30 12:34:08 +08:00
#ifdef BARRIER
return program.code->run(barrier::trans(db),
program.stripped.arguments, stream);
#else
return program.code->run(db, program.stripped.arguments, stream);
2016-08-30 12:34:08 +08:00
#endif
2016-07-18 01:32:35 +08:00
} catch (...) {
// TODO: return more information about the error
throw QueryEngineException("code execution error");
}
}
};