From 7ddce539fa460a65b23fbc9fc307653a554ccf84 Mon Sep 17 00:00:00 2001 From: gvolfing <107616712+gvolfing@users.noreply.github.com> Date: Tue, 16 May 2023 16:02:03 +0200 Subject: [PATCH] Add return build type command (#894) --- CMakeLists.txt | 2 ++ src/query/frontend/ast/ast.hpp | 2 +- .../frontend/ast/cypher_main_visitor.cpp | 3 +++ .../frontend/opencypher/grammar/Cypher.g4 | 4 ++- .../opencypher/grammar/MemgraphCypher.g4 | 1 + .../opencypher/grammar/MemgraphCypherLexer.g4 | 1 + .../frontend/semantic/required_privileges.cpp | 1 + .../frontend/stripped_lexer_constants.hpp | 3 ++- src/query/interpreter.cpp | 10 +++++++ src/utils/CMakeLists.txt | 3 ++- src/utils/build_info.cpp | 26 +++++++++++++++++++ src/utils/build_info.hpp | 24 +++++++++++++++++ 12 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 src/utils/build_info.cpp create mode 100644 src/utils/build_info.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 592930a40..1c2ac93cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -231,6 +231,8 @@ endif() message(STATUS "CMake build type: ${CMAKE_BUILD_TYPE}") # ----------------------------------------------------------------------------- +add_definitions( -DCMAKE_BUILD_TYPE_NAME="${CMAKE_BUILD_TYPE}") + if (NOT MG_ARCH) set(MG_ARCH_DESCR "Host architecture to build Memgraph on. Supported values are x86_64, ARM64.") if (${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "aarch64") diff --git a/src/query/frontend/ast/ast.hpp b/src/query/frontend/ast/ast.hpp index a1ecfafff..161903335 100644 --- a/src/query/frontend/ast/ast.hpp +++ b/src/query/frontend/ast/ast.hpp @@ -2786,7 +2786,7 @@ class InfoQuery : public memgraph::query::Query { static const utils::TypeInfo kType; const utils::TypeInfo &GetTypeInfo() const override { return kType; } - enum class InfoType { STORAGE, INDEX, CONSTRAINT }; + enum class InfoType { STORAGE, INDEX, CONSTRAINT, BUILD }; DEFVISITABLE(QueryVisitor); diff --git a/src/query/frontend/ast/cypher_main_visitor.cpp b/src/query/frontend/ast/cypher_main_visitor.cpp index a2aee8656..82cae5f55 100644 --- a/src/query/frontend/ast/cypher_main_visitor.cpp +++ b/src/query/frontend/ast/cypher_main_visitor.cpp @@ -124,6 +124,9 @@ antlrcpp::Any CypherMainVisitor::visitInfoQuery(MemgraphCypher::InfoQueryContext } else if (ctx->constraintInfo()) { info_query->info_type_ = InfoQuery::InfoType::CONSTRAINT; return info_query; + } else if (ctx->buildInfo()) { + info_query->info_type_ = InfoQuery::InfoType::BUILD; + return info_query; } else { throw utils::NotYetImplemented("Info query: '{}'", ctx->getText()); } diff --git a/src/query/frontend/opencypher/grammar/Cypher.g4 b/src/query/frontend/opencypher/grammar/Cypher.g4 index 65653d3b0..fceb4b906 100644 --- a/src/query/frontend/opencypher/grammar/Cypher.g4 +++ b/src/query/frontend/opencypher/grammar/Cypher.g4 @@ -46,7 +46,9 @@ indexInfo : INDEX INFO ; constraintInfo : CONSTRAINT INFO ; -infoQuery : SHOW ( storageInfo | indexInfo | constraintInfo ) ; +buildInfo : BUILD INFO ; + +infoQuery : SHOW ( storageInfo | indexInfo | constraintInfo | buildInfo) ; explainQuery : EXPLAIN cypherQuery ; diff --git a/src/query/frontend/opencypher/grammar/MemgraphCypher.g4 b/src/query/frontend/opencypher/grammar/MemgraphCypher.g4 index 07ddd8c52..1a7a7e803 100644 --- a/src/query/frontend/opencypher/grammar/MemgraphCypher.g4 +++ b/src/query/frontend/opencypher/grammar/MemgraphCypher.g4 @@ -31,6 +31,7 @@ memgraphCypherKeyword : cypherKeyword | BATCH_SIZE | BEFORE | BOOTSTRAP_SERVERS + | BUILD | CHECK | CLEAR | COMMIT diff --git a/src/query/frontend/opencypher/grammar/MemgraphCypherLexer.g4 b/src/query/frontend/opencypher/grammar/MemgraphCypherLexer.g4 index 62a2d916d..931960583 100644 --- a/src/query/frontend/opencypher/grammar/MemgraphCypherLexer.g4 +++ b/src/query/frontend/opencypher/grammar/MemgraphCypherLexer.g4 @@ -35,6 +35,7 @@ BATCH_INTERVAL : B A T C H UNDERSCORE I N T E R V A L ; BATCH_LIMIT : B A T C H UNDERSCORE L I M I T ; BATCH_SIZE : B A T C H UNDERSCORE S I Z E ; BEFORE : B E F O R E ; +BUILD : B U I L D ; BOOTSTRAP_SERVERS : B O O T S T R A P UNDERSCORE S E R V E R S ; CALL : C A L L ; CHECK : C H E C K ; diff --git a/src/query/frontend/semantic/required_privileges.cpp b/src/query/frontend/semantic/required_privileges.cpp index abb11bb63..29027bca4 100644 --- a/src/query/frontend/semantic/required_privileges.cpp +++ b/src/query/frontend/semantic/required_privileges.cpp @@ -43,6 +43,7 @@ class PrivilegeExtractor : public QueryVisitor, public HierarchicalTreeVis AddPrivilege(AuthQuery::Privilege::INDEX); break; case InfoQuery::InfoType::STORAGE: + case InfoQuery::InfoType::BUILD: AddPrivilege(AuthQuery::Privilege::STATS); break; case InfoQuery::InfoType::CONSTRAINT: diff --git a/src/query/frontend/stripped_lexer_constants.hpp b/src/query/frontend/stripped_lexer_constants.hpp index 36f6015cc..076fe1186 100644 --- a/src/query/frontend/stripped_lexer_constants.hpp +++ b/src/query/frontend/stripped_lexer_constants.hpp @@ -211,7 +211,8 @@ const trie::Trie kKeywords = {"union", "edge_types", "off", "in_memory_transactional", - "in_memory_analytical"}; + "in_memory_analytical", + "build"}; // Unicode codepoints that are allowed at the start of the unescaped name. const std::bitset kUnescapedNameAllowedStarts( diff --git a/src/query/interpreter.cpp b/src/query/interpreter.cpp index 4d6f54595..8d58b3093 100644 --- a/src/query/interpreter.cpp +++ b/src/query/interpreter.cpp @@ -57,6 +57,7 @@ #include "storage/v2/property_value.hpp" #include "storage/v2/storage_mode.hpp" #include "utils/algorithm.hpp" +#include "utils/build_info.hpp" #include "utils/csv_parsing.hpp" #include "utils/event_counter.hpp" #include "utils/exceptions.hpp" @@ -2394,6 +2395,15 @@ PreparedQuery PrepareInfoQuery(ParsedQuery parsed_query, bool in_explicit_transa return std::pair{results, QueryHandlerResult::NOTHING}; }; break; + + case InfoQuery::InfoType::BUILD: + header = {"build info", "value"}; + handler = [] { + std::vector> results{ + {TypedValue("build_type"), TypedValue(utils::GetBuildInfo().build_name)}}; + return std::pair{results, QueryHandlerResult::NOTHING}; + }; + break; } return PreparedQuery{std::move(header), std::move(parsed_query.required_privileges), diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 727379bfe..3677ebe6d 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -15,7 +15,8 @@ set(utils_src_files thread_pool.cpp tsc.cpp system_info.cpp - uuid.cpp) + uuid.cpp + build_info.cpp) find_package(Boost REQUIRED) find_package(fmt REQUIRED) diff --git a/src/utils/build_info.cpp b/src/utils/build_info.cpp new file mode 100644 index 000000000..9cc206dc4 --- /dev/null +++ b/src/utils/build_info.cpp @@ -0,0 +1,26 @@ +// Copyright 2023 Memgraph Ltd. +// +// 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. + +#include "build_info.hpp" + +namespace memgraph::utils { + +BuildInfo GetBuildInfo() { +#ifdef CMAKE_BUILD_TYPE_NAME + constexpr const char *build_info_name = CMAKE_BUILD_TYPE_NAME; +#else + constexpr const char *build_info_name = "unkown"; +#endif + BuildInfo info{build_info_name}; + return info; +} + +} // namespace memgraph::utils diff --git a/src/utils/build_info.hpp b/src/utils/build_info.hpp new file mode 100644 index 000000000..f50c92e35 --- /dev/null +++ b/src/utils/build_info.hpp @@ -0,0 +1,24 @@ +// Copyright 2023 Memgraph Ltd. +// +// 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. + +#pragma once + +#include + +namespace memgraph::utils { + +struct BuildInfo { + std::string build_name; +}; + +BuildInfo GetBuildInfo(); + +} // namespace memgraph::utils