2024-02-05 18:37:00 +08:00
|
|
|
// Copyright 2024 Memgraph Ltd.
|
2021-10-26 14:53:56 +08:00
|
|
|
//
|
|
|
|
// Use of this software is governed by the Business Source License
|
|
|
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
|
|
|
// License, and you may not use this file except in compliance with the Business Source License.
|
|
|
|
//
|
|
|
|
// As of the Change Date specified in that file, in accordance with
|
|
|
|
// the Business Source License, use of this software will be governed
|
|
|
|
// by the Apache License, Version 2.0, included in the file
|
|
|
|
// licenses/APL.txt.
|
|
|
|
|
2017-11-23 21:26:53 +08:00
|
|
|
#include "communication/result_stream_faker.hpp"
|
2022-11-04 22:23:43 +08:00
|
|
|
#include "license/license.hpp"
|
2021-06-30 17:19:13 +08:00
|
|
|
#include "query/config.hpp"
|
2017-11-23 21:26:53 +08:00
|
|
|
#include "query/interpreter.hpp"
|
2023-09-20 19:13:54 +08:00
|
|
|
#include "query/interpreter_context.hpp"
|
2023-06-29 17:44:55 +08:00
|
|
|
#include "storage/v2/config.hpp"
|
|
|
|
#include "storage/v2/inmemory/storage.hpp"
|
2021-06-14 21:47:57 +08:00
|
|
|
#include "storage/v2/isolation_level.hpp"
|
2021-05-14 21:38:59 +08:00
|
|
|
#include "utils/on_scope_exit.hpp"
|
2017-11-23 21:26:53 +08:00
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
|
|
|
|
// parse the first cmd line argument as the query
|
|
|
|
if (argc < 2) {
|
|
|
|
std::cout << "Usage: ./single_query 'RETURN \"query here\"'" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
2019-10-10 17:23:33 +08:00
|
|
|
|
2021-05-14 21:38:59 +08:00
|
|
|
auto data_directory = std::filesystem::temp_directory_path() / "single_query_test";
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::utils::OnScopeExit([&data_directory] { std::filesystem::remove_all(data_directory); });
|
2023-11-06 19:50:49 +08:00
|
|
|
memgraph::storage::Config db_config{.durability.storage_directory = data_directory,
|
|
|
|
.disk.main_storage_directory = data_directory / "disk"};
|
2021-09-30 01:14:39 +08:00
|
|
|
|
2022-11-04 22:23:43 +08:00
|
|
|
memgraph::license::global_license_checker.EnableTesting();
|
2023-11-06 19:50:49 +08:00
|
|
|
memgraph::replication::ReplicationState repl_state(memgraph::storage::ReplicationStateRootPath(db_config));
|
|
|
|
memgraph::utils::Gatekeeper<memgraph::dbms::Database> db_gk(db_config, repl_state);
|
2023-09-20 19:13:54 +08:00
|
|
|
auto db_acc_opt = db_gk.access();
|
|
|
|
MG_ASSERT(db_acc_opt, "Failed to access db");
|
|
|
|
auto &db_acc = *db_acc_opt;
|
2024-02-05 18:37:00 +08:00
|
|
|
memgraph::system::System system_state;
|
|
|
|
memgraph::query::InterpreterContext interpreter_context(memgraph::query::InterpreterConfig{}, nullptr, &repl_state,
|
|
|
|
system_state
|
|
|
|
#ifdef MG_ENTERPRISE
|
|
|
|
,
|
|
|
|
nullptr
|
|
|
|
#endif
|
|
|
|
);
|
2023-09-20 19:13:54 +08:00
|
|
|
memgraph::query::Interpreter interpreter{&interpreter_context, db_acc};
|
2019-10-10 17:23:33 +08:00
|
|
|
|
2023-09-20 19:13:54 +08:00
|
|
|
ResultStreamFaker stream(db_acc->storage());
|
2024-02-22 22:00:39 +08:00
|
|
|
memgraph::query::AllowEverythingAuthChecker auth_checker;
|
|
|
|
interpreter.SetUser(auth_checker.GenQueryUser(std::nullopt, std::nullopt));
|
2023-10-05 22:58:39 +08:00
|
|
|
auto [header, _1, qid, _2] = interpreter.Prepare(argv[1], {}, {});
|
2019-10-10 17:23:33 +08:00
|
|
|
stream.Header(header);
|
|
|
|
auto summary = interpreter.PullAll(&stream);
|
|
|
|
stream.Summary(summary);
|
2018-07-20 18:31:22 +08:00
|
|
|
std::cout << stream;
|
2019-10-10 17:23:33 +08:00
|
|
|
|
2017-11-23 21:26:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|