diff --git a/CMakeLists.txt b/CMakeLists.txt index 056046953..b255ba3e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,11 +110,6 @@ add_subdirectory(libs) # fmt set(fmt_source_dir ${libs_dir}/fmt) set(fmt_static_lib ${fmt_source_dir}/fmt/libfmt.a) -# yaml-cpp -# We no longer use yaml for configuration reading, maybe this dependancy should -# be removed. It is only used in tests/benchmark/query/strip/stripper.cpp -set(yaml_source_dir ${libs_dir}/yaml-cpp) -set(yaml_include_dir ${yaml_source_dir}/include) # prepare template and destination folders for query engine (tests) # and memgraph server binary @@ -158,7 +153,7 @@ if(CLANG_TIDY) -config='' -- -std=c++1y - -I${CMAKE_SOURCE_DIR}/include -I${fmt_source_dir} -I${yaml_include_dir} + -I${CMAKE_SOURCE_DIR}/include -I${fmt_source_dir} ) endif() # ----------------------------------------------------------------------------- @@ -276,7 +271,6 @@ message(STATUS "Generate coverage from unit tests: ${TEST_COVERAGE}") include_directories(${src_dir}) include_directories(${build_include_dir}) include_directories(SYSTEM ${fmt_source_dir}) -include_directories(SYSTEM ${yaml_include_dir}) include_directories(SYSTEM ${GTEST_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS}) include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/libs) # ----------------------------------------------------------------------------- @@ -351,7 +345,7 @@ set(memgraph_src_files ${src_dir}/database/graph_db_accessor.cpp ${src_dir}/data_structures/concurrent/skiplist_gc.cpp ${src_dir}/query/engine.cpp - ${src_dir}/query/stripped.cpp + ${src_dir}/query/frontend/stripped.cpp ${src_dir}/query/common.cpp ${src_dir}/query/console.cpp ${src_dir}/query/frontend/ast/ast.cpp @@ -367,7 +361,7 @@ set(memgraph_src_files # ----------------------------------------------------------------------------- # memgraph_lib and memgraph_pic depend on these libraries -set(MEMGRAPH_ALL_LIBS gflags stdc++fs Threads::Threads fmt yaml-cpp antlr_opencypher_parser_lib dl) +set(MEMGRAPH_ALL_LIBS gflags stdc++fs Threads::Threads fmt antlr_opencypher_parser_lib dl) if (READLINE_FOUND) list(APPEND MEMGRAPH_ALL_LIBS ${READLINE_LIBRARY}) endif() diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index 80dc828ea..704b6a8ee 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -21,13 +21,6 @@ set(GFLAGS_BUILD_gflags_nothreads_LIB OFF) set(GFLAGS_BUILD_gflags_LIB ON) add_subdirectory(gflags) - -# setup yaml cpp -# disable tests because yaml doesn't have MASTER_PROJECT flag like fmt has -# to override an option use option :) -option(YAML_CPP_BUILD_TOOLS "" OFF) -add_subdirectory(yaml-cpp) - # setup cppitertools # CLion compatiblity; the target won't be built file(GLOB __CPPITERTOOLS_SOURCES __main.cpp diff --git a/libs/setup.sh b/libs/setup.sh index dd2aeebe2..663bab77c 100755 --- a/libs/setup.sh +++ b/libs/setup.sh @@ -47,15 +47,6 @@ cd googletest git checkout ${googletest_tag} cd .. -# yaml-cpp -git clone https://github.com/jbeder/yaml-cpp -yaml_cpp_tag="519d33fea3fbcbe7e1f89f97ee0fa539cec33eb7" # master 18 Aug 2016 -# because a bug with link process had been fixed somewhen between -# this commit and v0.5.3 -cd yaml-cpp -git checkout ${yaml_cpp_tag} -cd .. - # lcov-to-coberatura-xml git clone https://github.com/eriwen/lcov-to-cobertura-xml.git lcov_to_xml_tag="59584761cb5da4687693faec05bf3e2b74e9dde9" # Dec 6, 2016 diff --git a/src/copy_hardcoded_queries.cpp b/src/copy_hardcoded_queries.cpp index c5d9ce887..541b0e3f6 100644 --- a/src/copy_hardcoded_queries.cpp +++ b/src/copy_hardcoded_queries.cpp @@ -7,7 +7,7 @@ namespace fs = std::experimental::filesystem; #include "logging/logger.hpp" #include "logging/streams/stdout.hpp" -#include "query/stripped.hpp" +#include "query/frontend/stripped.hpp" #include "utils/command_line/arguments.hpp" #include "utils/exceptions.hpp" #include "utils/file.hpp" diff --git a/src/query/frontend/ast/ast.hpp b/src/query/frontend/ast/ast.hpp index 0cc579afe..03e4bc942 100644 --- a/src/query/frontend/ast/ast.hpp +++ b/src/query/frontend/ast/ast.hpp @@ -529,15 +529,22 @@ class PrimitiveLiteral : public BaseLiteral { DEFVISITABLE(HierarchicalTreeVisitor); PrimitiveLiteral *Clone(AstTreeStorage &storage) const override { - return storage.Create(value_); + return storage.Create(value_, token_position_); } TypedValue value_; + // This field contains token position of literal used to create + // PrimitiveLiteral object. If PrimitiveLiteral object is not created from + // query leave its value at -1. + int token_position_ = -1; protected: PrimitiveLiteral(int uid) : BaseLiteral(uid) {} template PrimitiveLiteral(int uid, T value) : BaseLiteral(uid), value_(value) {} + template + PrimitiveLiteral(int uid, T value, int token_position) + : BaseLiteral(uid), value_(value), token_position_(token_position) {} }; class ListLiteral : public BaseLiteral { diff --git a/src/query/frontend/ast/cypher_main_visitor.cpp b/src/query/frontend/ast/cypher_main_visitor.cpp index e00962660..b2f261ca2 100644 --- a/src/query/frontend/ast/cypher_main_visitor.cpp +++ b/src/query/frontend/ast/cypher_main_visitor.cpp @@ -733,18 +733,20 @@ antlrcpp::Any CypherMainVisitor::visitAtom(CypherParser::AtomContext *ctx) { antlrcpp::Any CypherMainVisitor::visitLiteral( CypherParser::LiteralContext *ctx) { + int token_position = ctx->getStart()->getTokenIndex(); if (ctx->CYPHERNULL()) { return static_cast( - storage_.Create(TypedValue::Null)); + storage_.Create(TypedValue::Null, token_position)); } else if (ctx->StringLiteral()) { return static_cast(storage_.Create( - visitStringLiteral(ctx->StringLiteral()->getText()).as())); + visitStringLiteral(ctx->StringLiteral()->getText()).as(), + token_position)); } else if (ctx->booleanLiteral()) { return static_cast(storage_.Create( - ctx->booleanLiteral()->accept(this).as())); + ctx->booleanLiteral()->accept(this).as(), token_position)); } else if (ctx->numberLiteral()) { return static_cast(storage_.Create( - ctx->numberLiteral()->accept(this).as())); + ctx->numberLiteral()->accept(this).as(), token_position)); } else if (ctx->listLiteral()) { return static_cast(storage_.Create( ctx->listLiteral()->accept(this).as>())); diff --git a/src/query/stripped.cpp b/src/query/frontend/stripped.cpp similarity index 97% rename from src/query/stripped.cpp rename to src/query/frontend/stripped.cpp index 078500aa0..ccd9fc6aa 100644 --- a/src/query/stripped.cpp +++ b/src/query/frontend/stripped.cpp @@ -1,4 +1,4 @@ -#include "query/stripped.hpp" +#include "query/frontend/stripped.hpp" #include #include @@ -36,6 +36,7 @@ StrippedQuery::StrippedQuery(const std::string &query) // literal, appends is to the the stripped_query and adds the passed // value to stripped args. auto replace_stripped = [this, &token_strings](const TypedValue &value) { + // const std::string &new_value) { const auto &stripped_name = parameters_.Add(value); token_strings.push_back("$" + stripped_name); }; diff --git a/src/query/stripped.hpp b/src/query/frontend/stripped.hpp similarity index 97% rename from src/query/stripped.hpp rename to src/query/frontend/stripped.hpp index f09eaa427..c75018c17 100644 --- a/src/query/stripped.hpp +++ b/src/query/frontend/stripped.hpp @@ -3,7 +3,7 @@ #include #include "logging/loggable.hpp" -#include "parameters.hpp" +#include "query/parameters.hpp" #include "storage/property_value_store.hpp" #include "utils/assert.hpp" #include "utils/hashing/fnv.hpp" diff --git a/src/query/interpreter.hpp b/src/query/interpreter.hpp index bc5d4041d..59c1fee31 100644 --- a/src/query/interpreter.hpp +++ b/src/query/interpreter.hpp @@ -137,7 +137,7 @@ class Interpreter : public Loggable { } private: - // ConcurrentMap> query_plans; + // ConcurrentMap ast_cache_; }; } // namespace query diff --git a/src/query/plan_interface.hpp b/src/query/plan_interface.hpp index fc5ae2dff..67537b46c 100644 --- a/src/query/plan_interface.hpp +++ b/src/query/plan_interface.hpp @@ -2,7 +2,7 @@ #include "database/graph_db_accessor.hpp" -#include "query/stripped.hpp" +#include "query/frontend/stripped.hpp" /** * @class PlanInterface diff --git a/tests/benchmark/query/strip/stripper.cpp b/tests/benchmark/query/strip/stripper.cpp index aa75af32d..874e404f2 100644 --- a/tests/benchmark/query/strip/stripper.cpp +++ b/tests/benchmark/query/strip/stripper.cpp @@ -1,10 +1,14 @@ #define LOG_NO_INFO 1 +#include +#include +#include +#include + #include "benchmark/benchmark_api.h" #include "logging/default.hpp" #include "logging/streams/stdout.hpp" -#include "query/stripped.hpp" -#include "yaml-cpp/yaml.h" +#include "query/frontend/stripped.hpp" auto BM_Strip = [](benchmark::State &state, auto &function, std::string query) { while (state.KeepRunning()) { @@ -15,19 +19,19 @@ auto BM_Strip = [](benchmark::State &state, auto &function, std::string query) { state.SetComplexityN(state.range(0)); }; -int main(int argc, char **argv) { +int main(int argc, char *argv[]) { logging::init_async(); logging::log->pipe(std::make_unique()); - YAML::Node dataset = YAML::LoadFile( - "../../tests/data/cypher_queries/stripper/query_dict.yaml"); - auto preprocess = [](const std::string &query) { return query::StrippedQuery(query); }; - auto tests = dataset["benchmark_queries"].as>(); - for (auto &test : tests) { + std::string path = "../../tests/data/cypher_queries/stripper/query_dict.yaml"; + std::fstream queries_file(path); + + std::string test; + while (std::getline(queries_file, test)) { benchmark::RegisterBenchmark(test.c_str(), BM_Strip, preprocess, test) ->Range(1, 1) ->Complexity(benchmark::oN); diff --git a/tests/data/cypher_queries/stripper/query_dict.yaml b/tests/data/cypher_queries/stripper/query_dict.yaml index 8fbf3baf3..0987153b4 100644 --- a/tests/data/cypher_queries/stripper/query_dict.yaml +++ b/tests/data/cypher_queries/stripper/query_dict.yaml @@ -1,42 +1,21 @@ -benchmark_queries: - - "MATCH (a) RETURN size(collect(a))" - - - "CREATE (a:L), (b1), (b2) CREATE (a)-[:A]->(b1), (a)-[:A]->(b2)" - - - "MATCH (a:L)-[rel]->(b) RETURN a, count(*)" - - - "CREATE ({division: 'Sweden'})" - - - "MATCH (n) RETURN n.division, count(*) ORDER BY count(*) DESC, n.division ASC" - - - "UNWIND ['a', 'b', 'B', null, 'abc', 'abc1'] AS i RETURN max(i)" - - - "CREATE ({created: true})" - - - "MATCH (a)-[r]-(b) DELETE r, a, b RETURN count(*) AS c" - - - "MATCH (u:User) WITH {key: u} AS nodes DELETE nodes.key" - - - "CREATE ()-[:T {id: 42, alive: true, name: kifla, height: 4.2}]->()" - - - "MATCH p = ()-[r:T]-() WHERE r.id = 42 DELETE r" - - - "UNWIND range(0, 1000) AS i CREATE (:A {id: i}) MERGE (:B {id: i % 10})" - - - "MATCH (n) WHERE NOT(n.name = 'apa' AND false) RETURN n" - - - "CREATE ()-[:REL {property1: 12, property2: 24}]->()" - - - "MATCH (n:A) WHERE n.name = 'Andres' SET n.name = 'Michael' RETURN n" - - - "MATCH (n:A) SET (n).name = 'memgraph' RETURN n" - - - "CREATE (a {foo: [1, 2, 3]}) SET a.foo = a.foo + [4, 5] RETURN a.foo" - - - "MATCH (n:X {foo: 'A'}) SET n = {foo: 'B', baz: 'C'} RETURN n" - - - "MATCH (n:X {foo: 'A'}) SET n += {foo: null} RETURN n" - - - "MATCH (n) WITH n LIMIT toInteger(ceil(1.7)) RETURN count(*) AS count" - - - "MATCH (a:A), (b:B) MERGE (a)-[r:TYPE]->(b) ON CREATE SET r.name = 'Lola' RETURN count(r)" +MATCH (a) RETURN size(collect(a)) +CREATE (a:L), (b1), (b2) CREATE (a)-[:A]->(b1), (a)-[:A]->(b2) +MATCH (a:L)-[rel]->(b) RETURN a, count(*) +CREATE ({division: 'Sweden'}) +MATCH (n) RETURN n.division, count(*) ORDER BY count(*) DESC, n.division ASC +UNWIND ['a', 'b', 'B', null, 'abc', 'abc1'] AS i RETURN max(i) +CREATE ({created: true}) +MATCH (a)-[r]-(b) DELETE r, a, b RETURN count(*) AS c +MATCH (u:User) WITH {key: u} AS nodes DELETE nodes.key +CREATE ()-[:T {id: 42, alive: true, name: kifla, height: 4.2}]->() +MATCH p = ()-[r:T]-() WHERE r.id = 42 DELETE r +UNWIND range(0, 1000) AS i CREATE (:A {id: i}) MERGE (:B {id: i % 10}) +MATCH (n) WHERE NOT(n.name = 'apa' AND false) RETURN n +CREATE ()-[:REL {property1: 12, property2: 24}]->() +MATCH (n:A) WHERE n.name = 'Andres' SET n.name = 'Michael' RETURN n +MATCH (n:A) SET (n).name = 'memgraph' RETURN n +CREATE (a {foo: [1, 2, 3]}) SET a.foo = a.foo + [4, 5] RETURN a.foo +MATCH (n:X {foo: 'A'}) SET n = {foo: 'B', baz: 'C'} RETURN n +MATCH (n:X {foo: 'A'}) SET n += {foo: null} RETURN n +MATCH (n) WITH n LIMIT toInteger(ceil(1.7)) RETURN count(*) AS count +MATCH (a:A), (b:B) MERGE (a)-[r:TYPE]->(b) ON CREATE SET r.name = 'Lola' RETURN count(r) diff --git a/tests/integration/hardcoded_query/delete_all.cpp b/tests/integration/hardcoded_query/delete_all.cpp index 9c3906374..dbce8994f 100644 --- a/tests/integration/hardcoded_query/delete_all.cpp +++ b/tests/integration/hardcoded_query/delete_all.cpp @@ -3,7 +3,7 @@ #include "query/parameters.hpp" #include "query/plan_interface.hpp" -#include "query/stripped.hpp" +#include "query/frontend/stripped.hpp" #include "query/typed_value.hpp" #include "using.hpp" diff --git a/tests/integration/hardcoded_query/match_profile_garment_score.cpp b/tests/integration/hardcoded_query/match_profile_garment_score.cpp index 3f5faabd7..aed46357b 100644 --- a/tests/integration/hardcoded_query/match_profile_garment_score.cpp +++ b/tests/integration/hardcoded_query/match_profile_garment_score.cpp @@ -3,7 +3,7 @@ #include "query/parameters.hpp" #include "query/plan_interface.hpp" -#include "query/stripped.hpp" +#include "query/frontend/stripped.hpp" #include "query/typed_value.hpp" #include "storage/edge_accessor.hpp" #include "storage/vertex_accessor.hpp" diff --git a/tests/integration/query_engine_common.hpp b/tests/integration/query_engine_common.hpp index eded78dda..d2848cbf7 100644 --- a/tests/integration/query_engine_common.hpp +++ b/tests/integration/query_engine_common.hpp @@ -8,7 +8,7 @@ namespace fs = std::experimental::filesystem; #include "logging/default.hpp" #include "logging/streams/stdout.cpp" #include "query/engine.hpp" -#include "query/stripped.hpp" +#include "query/frontend/stripped.hpp" #include "stream/print_record_stream.hpp" #include "utils/command_line/arguments.hpp" #include "utils/file.hpp" diff --git a/tests/manual/query_hash.cpp b/tests/manual/query_hash.cpp index d748488d5..fdd4e25be 100644 --- a/tests/manual/query_hash.cpp +++ b/tests/manual/query_hash.cpp @@ -3,7 +3,7 @@ #include "logging/default.hpp" #include "logging/streams/stdout.hpp" -#include "query/stripped.hpp" +#include "query/frontend/stripped.hpp" #include "utils/command_line/arguments.hpp" #include "utils/type_discovery.hpp" diff --git a/tests/manual/query_stripper_timing.cpp b/tests/manual/query_stripper_timing.cpp index 807dad355..fcd73deb8 100644 --- a/tests/manual/query_stripper_timing.cpp +++ b/tests/manual/query_stripper_timing.cpp @@ -6,7 +6,7 @@ #include #include -#include "query/stripped.hpp" +#include "query/frontend/stripped.hpp" int main(int argc, const char **a) { if (argc < 2) { diff --git a/tests/unit/cypher_main_visitor.cpp b/tests/unit/cypher_main_visitor.cpp index 08b2dfdd6..36506c91e 100644 --- a/tests/unit/cypher_main_visitor.cpp +++ b/tests/unit/cypher_main_visitor.cpp @@ -228,7 +228,8 @@ TYPED_TEST(CypherMainVisitorTest, IntegerLiteral) { auto *literal = dynamic_cast( return_clause->body_.named_expressions[0]->expression_); ASSERT_TRUE(literal); - ASSERT_EQ(literal->value_.Value(), 42); + EXPECT_EQ(literal->value_.Value(), 42); + EXPECT_EQ(literal->token_position_, 2); } TYPED_TEST(CypherMainVisitorTest, IntegerLiteralTooLarge) { @@ -243,7 +244,8 @@ TYPED_TEST(CypherMainVisitorTest, BooleanLiteralTrue) { auto *literal = dynamic_cast( return_clause->body_.named_expressions[0]->expression_); ASSERT_TRUE(literal); - ASSERT_EQ(literal->value_.Value(), true); + EXPECT_EQ(literal->value_.Value(), true); + EXPECT_EQ(literal->token_position_, 2); } TYPED_TEST(CypherMainVisitorTest, BooleanLiteralFalse) { @@ -253,7 +255,8 @@ TYPED_TEST(CypherMainVisitorTest, BooleanLiteralFalse) { auto *literal = dynamic_cast( return_clause->body_.named_expressions[0]->expression_); ASSERT_TRUE(literal); - ASSERT_EQ(literal->value_.Value(), false); + EXPECT_EQ(literal->value_.Value(), false); + EXPECT_EQ(literal->token_position_, 2); } TYPED_TEST(CypherMainVisitorTest, NullLiteral) { @@ -263,7 +266,8 @@ TYPED_TEST(CypherMainVisitorTest, NullLiteral) { auto *literal = dynamic_cast( return_clause->body_.named_expressions[0]->expression_); ASSERT_TRUE(literal); - ASSERT_EQ(literal->value_.type(), TypedValue::Type::Null); + EXPECT_EQ(literal->value_.type(), TypedValue::Type::Null); + EXPECT_EQ(literal->token_position_, 2); } TYPED_TEST(CypherMainVisitorTest, ParenthesizedExpression) { @@ -602,7 +606,8 @@ TYPED_TEST(CypherMainVisitorTest, StringLiteralDoubleQuotes) { auto *literal = dynamic_cast( return_clause->body_.named_expressions[0]->expression_); ASSERT_TRUE(literal); - ASSERT_EQ(literal->value_.Value(), "mi'rko"); + EXPECT_EQ(literal->value_.Value(), "mi'rko"); + EXPECT_EQ(literal->token_position_, 2); } TYPED_TEST(CypherMainVisitorTest, StringLiteralSingleQuotes) { @@ -612,7 +617,8 @@ TYPED_TEST(CypherMainVisitorTest, StringLiteralSingleQuotes) { auto *literal = dynamic_cast( return_clause->body_.named_expressions[0]->expression_); ASSERT_TRUE(literal); - ASSERT_EQ(literal->value_.Value(), "mi\"rko"); + EXPECT_EQ(literal->value_.Value(), "mi\"rko"); + EXPECT_EQ(literal->token_position_, 2); } TYPED_TEST(CypherMainVisitorTest, StringLiteralEscapedChars) { @@ -622,7 +628,8 @@ TYPED_TEST(CypherMainVisitorTest, StringLiteralEscapedChars) { auto *literal = dynamic_cast( return_clause->body_.named_expressions[0]->expression_); ASSERT_TRUE(literal); - ASSERT_EQ(literal->value_.Value(), "\\'\"\b\b\f\f\n\n\r\r\t\t"); + EXPECT_EQ(literal->value_.Value(), "\\'\"\b\b\f\f\n\n\r\r\t\t"); + EXPECT_EQ(literal->token_position_, 2); } TYPED_TEST(CypherMainVisitorTest, StringLiteralEscapedUtf16) { @@ -632,7 +639,8 @@ TYPED_TEST(CypherMainVisitorTest, StringLiteralEscapedUtf16) { auto *literal = dynamic_cast( return_clause->body_.named_expressions[0]->expression_); ASSERT_TRUE(literal); - ASSERT_EQ(literal->value_.Value(), u8"\u221daaa\u221daaa"); + EXPECT_EQ(literal->value_.Value(), u8"\u221daaa\u221daaa"); + EXPECT_EQ(literal->token_position_, 2); } TYPED_TEST(CypherMainVisitorTest, StringLiteralEscapedUtf32) { @@ -642,8 +650,9 @@ TYPED_TEST(CypherMainVisitorTest, StringLiteralEscapedUtf32) { auto *literal = dynamic_cast( return_clause->body_.named_expressions[0]->expression_); ASSERT_TRUE(literal); - ASSERT_EQ(literal->value_.Value(), + EXPECT_EQ(literal->value_.Value(), u8"\U0001F600aaaa\U0001F600aaaaaaaa"); + EXPECT_EQ(literal->token_position_, 2); } TYPED_TEST(CypherMainVisitorTest, DoubleLiteral) { @@ -653,7 +662,8 @@ TYPED_TEST(CypherMainVisitorTest, DoubleLiteral) { auto *literal = dynamic_cast( return_clause->body_.named_expressions[0]->expression_); ASSERT_TRUE(literal); - ASSERT_EQ(literal->value_.Value(), 3.5); + EXPECT_EQ(literal->value_.Value(), 3.5); + EXPECT_EQ(literal->token_position_, 2); } TYPED_TEST(CypherMainVisitorTest, DoubleLiteralExponent) { @@ -663,7 +673,8 @@ TYPED_TEST(CypherMainVisitorTest, DoubleLiteralExponent) { auto *literal = dynamic_cast( return_clause->body_.named_expressions[0]->expression_); ASSERT_TRUE(literal); - ASSERT_EQ(literal->value_.Value(), 0.5); + EXPECT_EQ(literal->value_.Value(), 0.5); + EXPECT_EQ(literal->token_position_, 2); } TYPED_TEST(CypherMainVisitorTest, ListLiteral) { diff --git a/tests/unit/query_stripper.cpp b/tests/unit/query_stripper.cpp index 1643a350e..3df66d05e 100644 --- a/tests/unit/query_stripper.cpp +++ b/tests/unit/query_stripper.cpp @@ -5,7 +5,7 @@ #include "gtest/gtest.h" -#include "query/stripped.hpp" +#include "query/frontend/stripped.hpp" #include "query/typed_value.hpp" using query::TypedValue;