2024-02-20 04:09:54 +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-02-14 16:37:32 +08:00
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
|
2021-01-21 22:47:56 +08:00
|
|
|
#include <gflags/gflags.h>
|
2017-06-21 17:29:13 +08:00
|
|
|
|
2017-06-13 22:25:08 +08:00
|
|
|
#include "query/frontend/stripped.hpp"
|
2024-02-20 04:09:54 +08:00
|
|
|
#include "storage/v2/fmt.hpp"
|
2017-02-14 16:37:32 +08:00
|
|
|
|
2017-07-06 19:53:39 +08:00
|
|
|
DEFINE_string(q, "CREATE (n) RETURN n", "Query");
|
|
|
|
|
2017-02-14 16:37:32 +08:00
|
|
|
/**
|
|
|
|
* Useful when somebody wants to get a hash for some query.
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* ./query_hash -q "CREATE (n {name: \"test\n"}) RETURN n"
|
|
|
|
*/
|
2017-02-18 18:54:37 +08:00
|
|
|
int main(int argc, char **argv) {
|
2017-07-06 19:53:39 +08:00
|
|
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
2017-02-18 18:54:37 +08:00
|
|
|
|
|
|
|
// take query from input args
|
2017-07-06 19:53:39 +08:00
|
|
|
auto query = FLAGS_q;
|
2017-02-18 18:54:37 +08:00
|
|
|
|
|
|
|
// run preprocessing
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::query::frontend::StrippedQuery preprocessed(query);
|
2017-02-18 18:54:37 +08:00
|
|
|
|
|
|
|
// print query, stripped query, hash and variable values (propertie values)
|
2017-04-18 18:11:25 +08:00
|
|
|
std::cout << fmt::format("Query: {}\n", query);
|
2017-06-08 00:28:31 +08:00
|
|
|
std::cout << fmt::format("Stripped query: {}\n", preprocessed.query());
|
|
|
|
std::cout << fmt::format("Query hash: {}\n", preprocessed.hash());
|
2017-04-18 18:11:25 +08:00
|
|
|
std::cout << fmt::format("Property values:\n");
|
2017-06-15 00:53:02 +08:00
|
|
|
for (int i = 0; i < preprocessed.literals().size(); ++i) {
|
|
|
|
fmt::format(" {}", preprocessed.literals().At(i).second);
|
2017-04-18 18:11:25 +08:00
|
|
|
}
|
|
|
|
std::cout << std::endl;
|
2017-02-18 18:54:37 +08:00
|
|
|
|
|
|
|
return 0;
|
2017-02-14 16:37:32 +08:00
|
|
|
}
|