2017-02-14 16:37:32 +08:00
|
|
|
#include "../integration/query_engine_common.hpp"
|
2017-02-15 21:10:16 +08:00
|
|
|
#include "dbms/dbms.hpp"
|
2016-07-11 09:39:33 +08:00
|
|
|
|
2017-02-14 16:37:32 +08:00
|
|
|
#include "utils/fswatcher.hpp"
|
2016-07-11 09:39:33 +08:00
|
|
|
|
2017-02-14 16:37:32 +08:00
|
|
|
using namespace std::chrono_literals;
|
|
|
|
using namespace tests::integration;
|
2016-07-11 09:39:33 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
// init arguments
|
|
|
|
REGISTER_ARGS(argc, argv);
|
2016-07-18 01:32:35 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
// forlder with query implementations
|
|
|
|
auto implementations_folder =
|
|
|
|
fs::path(GET_ARG("-i", "tests/integration/hardcoded_query").get_string());
|
2016-08-29 01:50:54 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
// init engine
|
|
|
|
auto log = init_logging("ManualQueryEngine");
|
|
|
|
Dbms dbms;
|
|
|
|
auto db_accessor = dbms.active();
|
2017-02-21 22:37:32 +08:00
|
|
|
StreamT stream(std::cout); // inject path to data queries
|
2017-02-18 18:54:37 +08:00
|
|
|
QueryEngineT query_engine;
|
|
|
|
// IMPORTANT: PrintRecordStream can be replaces with a smarter
|
|
|
|
// object that can test the results
|
2017-02-14 16:37:32 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
WarmUpEngine(log, query_engine, db_accessor, stream);
|
2017-02-14 16:37:32 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
// init watcher
|
|
|
|
FSWatcher watcher;
|
|
|
|
QueryPreprocessor preprocessor;
|
2017-02-14 16:37:32 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
int i = 0;
|
|
|
|
watcher.watch(
|
2017-02-21 22:37:32 +08:00
|
|
|
WatchDescriptor(implementations_folder, FSEventType::All),
|
2017-02-18 18:54:37 +08:00
|
|
|
[&](FSEvent event) {
|
|
|
|
i++; // bacause only close_no_write could be detected and this
|
|
|
|
// call will cause close no write again
|
|
|
|
if (i % 2 == 1) {
|
|
|
|
// take only cpp files
|
|
|
|
if (event.path.extension() != ".cpp") return;
|
2017-02-14 16:37:32 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
auto query_mark = std::string("// Query: ");
|
|
|
|
auto lines = read_lines(event.path);
|
|
|
|
for (auto& line : lines) {
|
|
|
|
auto pos = line.find(query_mark);
|
|
|
|
if (pos == std::string::npos) continue;
|
|
|
|
auto query = line.substr(pos + query_mark.size());
|
|
|
|
log.info("Reload: {}", query);
|
|
|
|
query_engine.Unload(query);
|
|
|
|
try {
|
|
|
|
query_engine.ReloadCustom(query, event.path);
|
|
|
|
query_engine.Run(query, db_accessor, stream);
|
|
|
|
} catch (PlanCompilationException& e) {
|
|
|
|
log.info("Query compilation failed: {}", e.what());
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
log.info("Query execution failed: unknown reason");
|
2017-02-14 16:37:32 +08:00
|
|
|
}
|
2017-02-18 18:54:37 +08:00
|
|
|
log.info("Number of available query plans: {}",
|
|
|
|
query_engine.Size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-02-14 16:37:32 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
// TODO: watcher for injected query
|
2017-02-14 16:37:32 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
std::this_thread::sleep_for(1000s);
|
2017-02-14 16:37:32 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
watcher.stop();
|
2016-11-02 23:05:02 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
return 0;
|
2016-07-11 09:39:33 +08:00
|
|
|
}
|