From a6e51639f99fa8c7baaae3fd9b57c39cd96aeb23 Mon Sep 17 00:00:00 2001 From: Marko Budiselic <mbudiselicbuda@gmail.com> Date: Tue, 20 Sep 2022 14:53:26 +0200 Subject: [PATCH] Add more --- CMakeLists.txt | 14 +- src/query/db_accessor.hpp | 8 +- src/query/interpreter.cpp | 11 +- src/query/metadata.cpp | 3 + src/query/plan/operator.cpp | 2 + src/query/plan/pretty_print.cpp | 3 + src/query/plan/read_write_type_checker.cpp | 1 + src/query/procedure/mg_procedure_impl.cpp | 5 + src/query/procedure/py_module.cpp | 499 ++++++++++++++------- src/query/stream/common.hpp | 1 + src/query/stream/sources.cpp | 12 +- src/storage/v2/durability/snapshot.cpp | 8 +- src/storage/v2/edge_accessor.hpp | 4 +- src/storage/v2/vertex_accessor.hpp | 4 +- src/utils/exceptions.hpp | 1 + 15 files changed, 387 insertions(+), 189 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 61413d609..4b87ab8b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -179,18 +179,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) -# c99-designator is disabled because of required mixture of designated and -# non-designated initializers in Python Query Module code (`py_module.cpp`). -# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall \ -# -Werror=switch -Werror=switch-bool -Werror=return-type \ -# -Werror=return-stack-address \ -# -Wno-c99-designator \ -# -DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT") - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall \ - -Werror=switch -Werror=switch-bool -Werror=return-type \ - -Werror=return-local-addr \ - -Wno-c99-designator \ +# TODO(gitbuda): Add support for both clang and GCC with the valid flags. +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ -DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT") # Don't omit frame pointer in RelWithDebInfo, for additional callchain debug. diff --git a/src/query/db_accessor.hpp b/src/query/db_accessor.hpp index 8c6ddd0ff..ecd719e78 100644 --- a/src/query/db_accessor.hpp +++ b/src/query/db_accessor.hpp @@ -85,9 +85,9 @@ class EdgeAccessor final { bool IsCycle() const; - int64_t CypherId() const { return impl_.GidX().AsInt(); } + int64_t CypherId() const { return impl_.Gid().AsInt(); } - storage::Gid Gid() const noexcept { return impl_.GidX(); } + storage::Gid Gid() const noexcept { return impl_.Gid(); } bool operator==(const EdgeAccessor &e) const noexcept { return impl_ == e.impl_; } @@ -170,9 +170,9 @@ class VertexAccessor final { storage::Result<size_t> OutDegree(storage::View view) const { return impl_.OutDegree(view); } - int64_t CypherId() const { return impl_.GidX().AsInt(); } + int64_t CypherId() const { return impl_.Gid().AsInt(); } - storage::Gid Gid() const noexcept { return impl_.GidX(); } + storage::Gid Gid() const noexcept { return impl_.Gid(); } bool operator==(const VertexAccessor &v) const noexcept { static_assert(noexcept(impl_ == v.impl_)); diff --git a/src/query/interpreter.cpp b/src/query/interpreter.cpp index 76970992b..3525cc756 100644 --- a/src/query/interpreter.cpp +++ b/src/query/interpreter.cpp @@ -476,6 +476,7 @@ Callback HandleAuthQuery(AuthQuery *auth_query, AuthQueryHandler *auth, const Pa default: break; } + throw 1; } // namespace Callback HandleReplicationQuery(ReplicationQuery *repl_query, const Parameters ¶meters, @@ -525,6 +526,7 @@ Callback HandleReplicationQuery(ReplicationQuery *repl_query, const Parameters & return std::vector<std::vector<TypedValue>>{{TypedValue("replica")}}; } } + throw 1; }; return callback; } @@ -605,6 +607,7 @@ Callback HandleReplicationQuery(ReplicationQuery *repl_query, const Parameters & return callback; } } + throw 1; } std::optional<std::string> StringPointerToOptional(const std::string *str) { @@ -836,6 +839,7 @@ Callback HandleStreamQuery(StreamQuery *stream_query, const Parameters ¶mete return callback; } } + throw 1; } Callback HandleConfigQuery() { @@ -948,6 +952,7 @@ Callback HandleSettingQuery(SettingQuery *setting_query, const Parameters ¶m return callback; } } + throw 1; } // Struct for lazy pulling from a vector @@ -1686,6 +1691,7 @@ TriggerEventType ToTriggerEventType(const TriggerQuery::EventType event_type) { case TriggerQuery::EventType::EDGE_UPDATE: return TriggerEventType::EDGE_UPDATE; } + throw 1; } Callback CreateTrigger(TriggerQuery *trigger_query, @@ -1763,6 +1769,7 @@ PreparedQuery PrepareTriggerQuery(ParsedQuery parsed_query, const bool in_explic case TriggerQuery::Action::SHOW_TRIGGERS: return ShowTriggers(interpreter_context); } + throw 1; }); return PreparedQuery{std::move(callback.header), std::move(parsed_query.required_privileges), @@ -1826,6 +1833,7 @@ constexpr auto ToStorageIsolationLevel(const IsolationLevelQuery::IsolationLevel case IsolationLevelQuery::IsolationLevel::READ_UNCOMMITTED: return storage::IsolationLevel::READ_UNCOMMITTED; } + throw 1; } PreparedQuery PrepareIsolationLevelQuery(ParsedQuery parsed_query, const bool in_explicit_transaction, @@ -1849,6 +1857,7 @@ PreparedQuery PrepareIsolationLevelQuery(ParsedQuery parsed_query, const bool in case IsolationLevelQuery::IsolationLevelScope::NEXT: return [interpreter, isolation_level] { interpreter->SetNextTransactionIsolationLevel(isolation_level); }; } + throw 1; }(); return PreparedQuery{ @@ -2590,7 +2599,7 @@ void Interpreter::Commit() { SPDLOG_DEBUG("Finished committing the transaction"); if (!commit_confirmed_by_all_sync_repplicas) { - throw ReplicationException("At least one SYNC replica has not confirmed committing last transaction."); + throw ReplicationException(std::string("At least one SYNC replica has not confirmed committing last transaction.")); } } diff --git a/src/query/metadata.cpp b/src/query/metadata.cpp index 47b207bc0..e5f6df535 100644 --- a/src/query/metadata.cpp +++ b/src/query/metadata.cpp @@ -28,6 +28,7 @@ constexpr std::string_view GetSeverityLevelString(const SeverityLevel level) { case SeverityLevel::WARNING: return "WARNING"sv; } + throw 1; } constexpr std::string_view GetCodeString(const NotificationCode code) { @@ -77,6 +78,7 @@ constexpr std::string_view GetCodeString(const NotificationCode code) { case NotificationCode::STOP_ALL_STREAMS: return "StopAllStreams"sv; } + throw 1; } } // namespace @@ -112,6 +114,7 @@ std::string ExecutionStatsKeyToString(const ExecutionStats::Key key) { case ExecutionStats::Key::UPDATED_PROPERTIES: return std::string("properties-set"); } + throw 1; } } // namespace memgraph::query diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp index 6cfab8e95..dd3721bf5 100644 --- a/src/query/plan/operator.cpp +++ b/src/query/plan/operator.cpp @@ -566,6 +566,7 @@ UniqueCursorPtr ScanAllByLabelPropertyRange::MakeCursor(utils::MemoryResource *m } catch (const TypedValueException &) { throw QueryRuntimeException("'{}' cannot be used as a property value.", value.type()); } + throw 1; }; auto maybe_lower = convert(lower_bound_); auto maybe_upper = convert(upper_bound_); @@ -3150,6 +3151,7 @@ TypedValue DefaultAggregationOpValue(const Aggregate::Element &element, utils::M case Aggregation::Op::PROJECT: return TypedValue(query::Graph(memory)); } + throw 1; } } // namespace diff --git a/src/query/plan/pretty_print.cpp b/src/query/plan/pretty_print.cpp index 17644068a..360596520 100644 --- a/src/query/plan/pretty_print.cpp +++ b/src/query/plan/pretty_print.cpp @@ -301,6 +301,7 @@ std::string ToString(EdgeAtom::Direction dir) { case EdgeAtom::Direction::OUT: return "out"; } + throw 1; } std::string ToString(EdgeAtom::Type type) { @@ -316,6 +317,7 @@ std::string ToString(EdgeAtom::Type type) { case EdgeAtom::Type::SINGLE: return "single"; } + throw 1; } std::string ToString(Ordering ord) { @@ -325,6 +327,7 @@ std::string ToString(Ordering ord) { case Ordering::DESC: return "desc"; } + throw 1; } json ToJson(Expression *expression) { diff --git a/src/query/plan/read_write_type_checker.cpp b/src/query/plan/read_write_type_checker.cpp index 1d2e752d4..51ad93bce 100644 --- a/src/query/plan/read_write_type_checker.cpp +++ b/src/query/plan/read_write_type_checker.cpp @@ -123,6 +123,7 @@ std::string ReadWriteTypeChecker::TypeToString(const RWType type) { case RWType::RW: return "rw"; } + throw 1; } } // namespace memgraph::query::plan diff --git a/src/query/procedure/mg_procedure_impl.cpp b/src/query/procedure/mg_procedure_impl.cpp index 70948bf5a..59a3e54e6 100644 --- a/src/query/procedure/mg_procedure_impl.cpp +++ b/src/query/procedure/mg_procedure_impl.cpp @@ -305,6 +305,7 @@ mgp_value_type FromTypedValueType(memgraph::query::TypedValue::Type type) { case memgraph::query::TypedValue::Type::Graph: throw std::logic_error{"mgp_value for TypedValue::Type::Graph doesn't exist."}; } + throw 1; } } // namespace @@ -361,6 +362,7 @@ memgraph::query::TypedValue ToTypedValue(const mgp_value &val, memgraph::utils:: case MGP_VALUE_TYPE_DURATION: return memgraph::query::TypedValue(val.duration_v->duration, memory); } + throw 1; } mgp_value::mgp_value(memgraph::utils::MemoryResource *m) noexcept : type(MGP_VALUE_TYPE_NULL), memory(m) {} @@ -1645,6 +1647,7 @@ memgraph::storage::PropertyValue ToPropertyValue(const mgp_value &value) { case MGP_VALUE_TYPE_PATH: throw ValueConversionException{"A path is not a valid property value!"}; } + throw 1; } } // namespace @@ -2934,6 +2937,7 @@ std::ostream &PrintValue(const TypedValue &value, std::ostream *stream) { case TypedValue::Type::Graph: LOG_FATAL("value must not be a graph element"); } + throw 1; } } // namespace @@ -3006,6 +3010,7 @@ mgp_source_type StreamSourceTypeToMgpSourceType(const StreamSourceType type) { case StreamSourceType::PULSAR: return mgp_source_type::PULSAR; } + throw 1; } } // namespace diff --git a/src/query/procedure/py_module.cpp b/src/query/procedure/py_module.cpp index f1959649f..6ca21a97d 100644 --- a/src/query/procedure/py_module.cpp +++ b/src/query/procedure/py_module.cpp @@ -216,16 +216,58 @@ static PyMethodDef PyVerticesIteratorMethods[] = { {nullptr}, }; -// clang-format off -static PyTypeObject PyVerticesIteratorType = { - PyVarObject_HEAD_INIT(nullptr, 0) - .tp_name = "_mgp.VerticesIterator", - .tp_basicsize = sizeof(PyVerticesIterator), - .tp_dealloc = reinterpret_cast<destructor>(PyVerticesIteratorDealloc), - .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_doc = "Wraps struct mgp_vertices_iterator.", - .tp_methods = PyVerticesIteratorMethods, +struct PyTypeBuilder { + PyTypeObject object{PyVarObject_HEAD_INIT(nullptr, 0)}; + constexpr PyTypeBuilder &&Name(const char *name) && { + object.tp_name = name; + return std::move(*this); + } + constexpr PyTypeBuilder &&BasicSize(const size_t size) && { + object.tp_basicsize = size; + return std::move(*this); + } + constexpr PyTypeBuilder &&Dealloc(const destructor dealloc) && { + object.tp_dealloc = dealloc; + return std::move(*this); + } + constexpr PyTypeBuilder &&Flags(const unsigned long flags) && { + object.tp_flags = flags; + return std::move(*this); + } + constexpr PyTypeBuilder &&Doc(const char *doc) && { + object.tp_doc = doc; + return std::move(*this); + } + constexpr PyTypeBuilder &&Methods(struct PyMethodDef *methods) && { + object.tp_methods = methods; + return std::move(*this); + } + constexpr PyTypeBuilder &&RichCompare(const richcmpfunc richcmp) && { + object.tp_richcompare = richcmp; + return std::move(*this); + } + constexpr PyTypeObject Build() const && { return object; } }; + +static PyTypeObject PyVerticesIteratorType = PyTypeBuilder{} + .Name("_mgp.VerticesIterator") + .BasicSize(sizeof(PyVerticesIterator)) + .Dealloc(reinterpret_cast<destructor>(PyVerticesIteratorDealloc)) + .Flags(Py_TPFLAGS_DEFAULT) + .Doc("Wraps struct mgp_vertices_iterator.") + .Methods(PyVerticesIteratorMethods) + .Build(); + +// clang-format off +// static PyTypeObject PyVerticesIteratorType = { +// PyVarObject_HEAD_INIT(nullptr, 0) +// .tp_name = "_mgp.VerticesIterator", +// .tp_basicsize = sizeof(PyVerticesIterator), +// .tp_dealloc = reinterpret_cast<destructor>(PyVerticesIteratorDealloc), +// .tp_flags = Py_TPFLAGS_DEFAULT, +// .tp_doc = "Wraps struct mgp_vertices_iterator.", +// .tp_methods = PyVerticesIteratorMethods, +// }; // clang-format on // clang-format off @@ -288,17 +330,26 @@ static PyMethodDef PyEdgesIteratorMethods[] = { {nullptr}, }; -// clang-format off -static PyTypeObject PyEdgesIteratorType = { - PyVarObject_HEAD_INIT(nullptr, 0) - .tp_name = "_mgp.EdgesIterator", - .tp_basicsize = sizeof(PyEdgesIterator), - .tp_dealloc = reinterpret_cast<destructor>(PyEdgesIteratorDealloc), - .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_doc = "Wraps struct mgp_edges_iterator.", - .tp_methods = PyEdgesIteratorMethods, -}; -// clang-format on +static PyTypeObject PyEdgesIteratorType = PyTypeBuilder{} + .Name("_mgp.EdgesIterator") + .BasicSize(sizeof(PyEdgesIterator)) + .Dealloc(reinterpret_cast<destructor>(PyEdgesIteratorDealloc)) + .Flags(Py_TPFLAGS_DEFAULT) + .Doc("Wraps struct mgp_edges_iterator.") + .Methods(PyEdgesIteratorMethods) + .Build(); + +// // clang-format off +// static PyTypeObject PyEdgesIteratorType = { +// PyVarObject_HEAD_INIT(nullptr, 0) +// .tp_name = "_mgp.EdgesIterator", +// .tp_basicsize = sizeof(PyEdgesIterator), +// .tp_dealloc = reinterpret_cast<destructor>(PyEdgesIteratorDealloc), +// .tp_flags = Py_TPFLAGS_DEFAULT, +// .tp_doc = "Wraps struct mgp_edges_iterator.", +// .tp_methods = PyEdgesIteratorMethods, +// }; +// // clang-format on PyObject *PyGraphInvalidate(PyGraph *self, PyObject *Py_UNUSED(ignored)) { self->graph = nullptr; @@ -404,16 +455,24 @@ static PyMethodDef PyGraphMethods[] = { {nullptr}, }; -// clang-format off -static PyTypeObject PyGraphType = { - PyVarObject_HEAD_INIT(nullptr, 0) - .tp_name = "_mgp.Graph", - .tp_basicsize = sizeof(PyGraph), - .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_doc = "Wraps struct mgp_graph.", - .tp_methods = PyGraphMethods, -}; -// clang-format on +static PyTypeObject PyGraphType = PyTypeBuilder{} + .Name("_mgp.Graph") + .BasicSize(sizeof(PyGraph)) + .Flags(Py_TPFLAGS_DEFAULT) + .Doc("Wraps struct mgp_graph.") + .Methods(PyGraphMethods) + .Build(); + +// // clang-format off +// static PyTypeObject PyGraphType = { +// PyVarObject_HEAD_INIT(nullptr, 0) +// .tp_name = "_mgp.Graph", +// .tp_basicsize = sizeof(PyGraph), +// .tp_flags = Py_TPFLAGS_DEFAULT, +// .tp_doc = "Wraps struct mgp_graph.", +// .tp_methods = PyGraphMethods, +// }; +// // clang-format on PyObject *MakePyGraph(mgp_graph *graph, mgp_memory *memory) { MG_ASSERT(!graph || (graph && memory)); @@ -431,15 +490,22 @@ struct PyCypherType { }; // clang-format on -// clang-format off -static PyTypeObject PyCypherTypeType = { - PyVarObject_HEAD_INIT(nullptr, 0) - .tp_name = "_mgp.Type", - .tp_basicsize = sizeof(PyCypherType), - .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_doc = "Wraps struct mgp_type.", -}; -// clang-format on +static PyTypeObject PyCypherTypeType = PyTypeBuilder{} + .Name("_mgp.Type") + .BasicSize(sizeof(PyCypherType)) + .Flags(Py_TPFLAGS_DEFAULT) + .Doc("Wraps struct mgp_type.") + .Build(); + +// // clang-format off +// static PyTypeObject PyCypherTypeType = { +// PyVarObject_HEAD_INIT(nullptr, 0) +// .tp_name = "_mgp.Type", +// .tp_basicsize = sizeof(PyCypherType), +// .tp_flags = Py_TPFLAGS_DEFAULT, +// .tp_doc = "Wraps struct mgp_type.", +// }; +// // clang-format on PyObject *MakePyCypherType(mgp_type *type) { MG_ASSERT(type); @@ -558,16 +624,24 @@ static PyMethodDef PyQueryProcMethods[] = { {nullptr}, }; -// clang-format off -static PyTypeObject PyQueryProcType = { - PyVarObject_HEAD_INIT(nullptr, 0) - .tp_name = "_mgp.Proc", - .tp_basicsize = sizeof(PyQueryProc), - .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_doc = "Wraps struct mgp_proc.", - .tp_methods = PyQueryProcMethods, -}; -// clang-format on +static PyTypeObject PyQueryProcType = PyTypeBuilder{} + .Name("_mgp.Proc") + .BasicSize(sizeof(PyQueryProc)) + .Flags(Py_TPFLAGS_DEFAULT) + .Doc("Wraps struct mgp_proc.") + .Methods(PyQueryProcMethods) + .Build(); + +// // clang-format off +// static PyTypeObject PyQueryProcType = { +// PyVarObject_HEAD_INIT(nullptr, 0) +// .tp_name = "_mgp.Proc", +// .tp_basicsize = sizeof(PyQueryProc), +// .tp_flags = Py_TPFLAGS_DEFAULT, +// .tp_doc = "Wraps struct mgp_proc.", +// .tp_methods = PyQueryProcMethods, +// }; +// // clang-format on PyObject *PyMagicFuncAddArg(PyMagicFunc *self, PyObject *args) { return PyCallableAddArg(self, args); } @@ -583,18 +657,26 @@ static PyMethodDef PyMagicFuncMethods[] = { {nullptr}, }; -// clang-format off -// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) -static PyTypeObject PyMagicFuncType = { - PyVarObject_HEAD_INIT(nullptr, 0) - .tp_name = "_mgp.Func", - .tp_basicsize = sizeof(PyMagicFunc), - // NOLINTNEXTLINE(hicpp-signed-bitwise) - .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_doc = "Wraps struct mgp_func.", - .tp_methods = PyMagicFuncMethods, -}; -// clang-format on +static PyTypeObject PyMagicFuncType = PyTypeBuilder{} + .Name("_mgp.Func") + .BasicSize(sizeof(PyMagicFunc)) + .Flags(Py_TPFLAGS_DEFAULT) + .Doc("Wraps struct mgp_func.") + .Methods(PyMagicFuncMethods) + .Build(); + +// // clang-format off +// // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) +// static PyTypeObject PyMagicFuncType = { +// PyVarObject_HEAD_INIT(nullptr, 0) +// .tp_name = "_mgp.Func", +// .tp_basicsize = sizeof(PyMagicFunc), +// // NOLINTNEXTLINE(hicpp-signed-bitwise) +// .tp_flags = Py_TPFLAGS_DEFAULT, +// .tp_doc = "Wraps struct mgp_func.", +// .tp_methods = PyMagicFuncMethods, +// }; +// // clang-format on // clang-format off struct PyQueryModule { @@ -745,17 +827,26 @@ void PyMessageDealloc(PyMessage *self) { Py_TYPE(self)->tp_free(self); } -// NOLINTNEXTLINE -static PyTypeObject PyMessageType = { - PyVarObject_HEAD_INIT(nullptr, 0).tp_name = "_mgp.Message", - .tp_basicsize = sizeof(PyMessage), - .tp_dealloc = reinterpret_cast<destructor>(PyMessageDealloc), - // NOLINTNEXTLINE - .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_doc = "Wraps struct mgp_message.", - // NOLINTNEXTLINE - .tp_methods = PyMessageMethods, -}; +static PyTypeObject PyMessageType = PyTypeBuilder{} + .Name("_mgp.Message") + .BasicSize(sizeof(PyMessage)) + .Flags(Py_TPFLAGS_DEFAULT) + .Dealloc(reinterpret_cast<destructor>(PyMessageDealloc)) + .Doc("Wraps struct mgp_message.") + .Methods(PyMessageMethods) + .Build(); + +// // NOLINTNEXTLINE +// static PyTypeObject PyMessageType = { +// PyVarObject_HEAD_INIT(nullptr, 0).tp_name = "_mgp.Message", +// .tp_basicsize = sizeof(PyMessage), +// .tp_dealloc = reinterpret_cast<destructor>(PyMessageDealloc), +// // NOLINTNEXTLINE +// .tp_flags = Py_TPFLAGS_DEFAULT, +// .tp_doc = "Wraps struct mgp_message.", +// // NOLINTNEXTLINE +// .tp_methods = PyMessageMethods, +// }; PyObject *PyMessagesInvalidate(PyMessages *self, PyObject *Py_UNUSED(ignored)) { self->messages = nullptr; @@ -814,16 +905,24 @@ static PyMethodDef PyMessagesMethods[] = { {nullptr}, }; -// NOLINTNEXTLINE -static PyTypeObject PyMessagesType = { - PyVarObject_HEAD_INIT(nullptr, 0).tp_name = "_mgp.Messages", - .tp_basicsize = sizeof(PyMessages), - // NOLINTNEXTLINE - .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_doc = "Wraps struct mgp_messages.", - // NOLINTNEXTLINE - .tp_methods = PyMessagesMethods, -}; +static PyTypeObject PyMessagesType = PyTypeBuilder{} + .Name("_mgp.Messages") + .BasicSize(sizeof(PyMessages)) + .Flags(Py_TPFLAGS_DEFAULT) + .Doc("Wraps struct mgp_messages.") + .Methods(PyMessageMethods) + .Build(); + +// // NOLINTNEXTLINE +// static PyTypeObject PyMessagesType = { +// PyVarObject_HEAD_INIT(nullptr, 0).tp_name = "_mgp.Messages", +// .tp_basicsize = sizeof(PyMessages), +// // NOLINTNEXTLINE +// .tp_flags = Py_TPFLAGS_DEFAULT, +// .tp_doc = "Wraps struct mgp_messages.", +// // NOLINTNEXTLINE +// .tp_methods = PyMessagesMethods, +// }; PyObject *MakePyMessages(mgp_messages *msgs, mgp_memory *memory) { MG_ASSERT(!msgs || (msgs && memory)); @@ -1232,16 +1331,24 @@ static PyMethodDef PyQueryModuleMethods[] = { {nullptr}, }; -// clang-format off -static PyTypeObject PyQueryModuleType = { - PyVarObject_HEAD_INIT(nullptr, 0) - .tp_name = "_mgp.Module", - .tp_basicsize = sizeof(PyQueryModule), - .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_doc = "Wraps struct mgp_module.", - .tp_methods = PyQueryModuleMethods, -}; -// clang-format on +static PyTypeObject PyQueryModuleType = PyTypeBuilder{} + .Name("_mgp.Module") + .BasicSize(sizeof(PyQueryModule)) + .Flags(Py_TPFLAGS_DEFAULT) + .Doc("Wraps struct mgp_module.") + .Methods(PyQueryModuleMethods) + .Build(); + +// // clang-format off +// static PyTypeObject PyQueryModuleType = { +// PyVarObject_HEAD_INIT(nullptr, 0) +// .tp_name = "_mgp.Module", +// .tp_basicsize = sizeof(PyQueryModule), +// .tp_flags = Py_TPFLAGS_DEFAULT, +// .tp_doc = "Wraps struct mgp_module.", +// .tp_methods = PyQueryModuleMethods, +// }; +// // clang-format on PyObject *MakePyQueryModule(mgp_module *module) { MG_ASSERT(module); @@ -1326,15 +1433,44 @@ static PyMethodDef PyMgpModuleMethods[] = { {nullptr}, }; -// clang-format off -static PyModuleDef PyMgpModule = { - PyModuleDef_HEAD_INIT, - .m_name = "_mgp", - .m_doc = "Contains raw bindings to mg_procedure.h C API.", - .m_size = -1, - .m_methods = PyMgpModuleMethods, +struct PyModuleBuilder { + PyModuleDef object{PyModuleDef_HEAD_INIT}; + ; + constexpr PyModuleBuilder &&Name(const char *name) && { + object.m_name = name; + return std::move(*this); + } + constexpr PyModuleBuilder &&Size(const size_t size) && { + object.m_size = size; + return std::move(*this); + } + constexpr PyModuleBuilder &&Doc(const char *doc) && { + object.m_doc = doc; + return std::move(*this); + } + constexpr PyModuleBuilder &&Methods(struct PyMethodDef *methods) && { + object.m_methods = methods; + return std::move(*this); + } + constexpr PyModuleDef Build() const && { return object; } }; -// clang-format on + +static PyModuleDef PyMgpModule = PyModuleBuilder{} + .Name("_mgp") + .Doc("Contains raw bindings to mg_procedure.h C API") + .Size(-1) + .Methods(PyMgpModuleMethods) + .Build(); + +// // clang-format off +// static PyModuleDef PyMgpModule = { +// PyModuleDef_HEAD_INIT, +// .m_name = "_mgp", +// .m_doc = "Contains raw bindings to mg_procedure.h C API.", +// .m_size = -1, +// .m_methods = PyMgpModuleMethods, +// }; +// // clang-format on // clang-format off struct PyPropertiesIterator { @@ -1401,17 +1537,26 @@ static PyMethodDef PyPropertiesIteratorMethods[] = { {nullptr}, }; -// clang-format off -static PyTypeObject PyPropertiesIteratorType = { - PyVarObject_HEAD_INIT(nullptr, 0) - .tp_name = "_mgp.PropertiesIterator", - .tp_basicsize = sizeof(PyPropertiesIterator), - .tp_dealloc = reinterpret_cast<destructor>(PyPropertiesIteratorDealloc), - .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_doc = "Wraps struct mgp_properties_iterator.", - .tp_methods = PyPropertiesIteratorMethods, -}; -// clang-format on +static PyTypeObject PyPropertiesIteratorType = PyTypeBuilder{} + .Name("_mgp.PropertiesIterator") + .BasicSize(sizeof(PyPropertiesIterator)) + .Dealloc(reinterpret_cast<destructor>(PyPropertiesIteratorDealloc)) + .Flags(Py_TPFLAGS_DEFAULT) + .Doc("Wraps struct mgp_properties_iterator.") + .Methods(PyPropertiesIteratorMethods) + .Build(); + +// // clang-format off +// static PyTypeObject PyPropertiesIteratorType = { +// PyVarObject_HEAD_INIT(nullptr, 0) +// .tp_name = "_mgp.PropertiesIterator", +// .tp_basicsize = sizeof(PyPropertiesIterator), +// .tp_dealloc = reinterpret_cast<destructor>(PyPropertiesIteratorDealloc), +// .tp_flags = Py_TPFLAGS_DEFAULT, +// .tp_doc = "Wraps struct mgp_properties_iterator.", +// .tp_methods = PyPropertiesIteratorMethods, +// }; +// // clang-format on // clang-format off struct PyEdge { @@ -1561,18 +1706,28 @@ static PyMethodDef PyEdgeMethods[] = { PyObject *PyEdgeRichCompare(PyObject *self, PyObject *other, int op); -// clang-format off -static PyTypeObject PyEdgeType = { - PyVarObject_HEAD_INIT(nullptr, 0) - .tp_name = "_mgp.Edge", - .tp_basicsize = sizeof(PyEdge), - .tp_dealloc = reinterpret_cast<destructor>(PyEdgeDealloc), - .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_doc = "Wraps struct mgp_edge.", - .tp_richcompare = PyEdgeRichCompare, - .tp_methods = PyEdgeMethods, -}; -// clang-format on +static PyTypeObject PyEdgeType = PyTypeBuilder{} + .Name("_mgp.Edge") + .BasicSize(sizeof(PyEdge)) + .Dealloc(reinterpret_cast<destructor>(PyEdgeDealloc)) + .Flags(Py_TPFLAGS_DEFAULT) + .Doc("Wraps struct mgp_edge.") + .RichCompare(PyEdgeRichCompare) + .Methods(PyEdgeMethods) + .Build(); + +// // clang-format off +// static PyTypeObject PyEdgeType = { +// PyVarObject_HEAD_INIT(nullptr, 0) +// .tp_name = "_mgp.Edge", +// .tp_basicsize = sizeof(PyEdge), +// .tp_dealloc = reinterpret_cast<destructor>(PyEdgeDealloc), +// .tp_flags = Py_TPFLAGS_DEFAULT, +// .tp_doc = "Wraps struct mgp_edge.", +// .tp_richcompare = PyEdgeRichCompare, +// .tp_methods = PyEdgeMethods, +// }; +// // clang-format on PyObject *MakePyEdgeWithoutCopy(mgp_edge &edge, PyGraph *py_graph) { MG_ASSERT(py_graph); @@ -1849,18 +2004,28 @@ static PyMethodDef PyVertexMethods[] = { PyObject *PyVertexRichCompare(PyObject *self, PyObject *other, int op); -// clang-format off -static PyTypeObject PyVertexType = { - PyVarObject_HEAD_INIT(nullptr, 0) - .tp_name = "_mgp.Vertex", - .tp_basicsize = sizeof(PyVertex), - .tp_dealloc = reinterpret_cast<destructor>(PyVertexDealloc), - .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_doc = "Wraps struct mgp_vertex.", - .tp_richcompare = PyVertexRichCompare, - .tp_methods = PyVertexMethods, -}; -// clang-format on +static PyTypeObject PyVertexType = PyTypeBuilder{} + .Name("_mgp.Vertex") + .BasicSize(sizeof(PyVertex)) + .Dealloc(reinterpret_cast<destructor>(PyVertexDealloc)) + .Flags(Py_TPFLAGS_DEFAULT) + .Doc("Wraps struct mgp_vertex.") + .RichCompare(PyVertexRichCompare) + .Methods(PyVertexMethods) + .Build(); + +// // clang-format off +// static PyTypeObject PyVertexType = { +// PyVarObject_HEAD_INIT(nullptr, 0) +// .tp_name = "_mgp.Vertex", +// .tp_basicsize = sizeof(PyVertex), +// .tp_dealloc = reinterpret_cast<destructor>(PyVertexDealloc), +// .tp_flags = Py_TPFLAGS_DEFAULT, +// .tp_doc = "Wraps struct mgp_vertex.", +// .tp_richcompare = PyVertexRichCompare, +// .tp_methods = PyVertexMethods, +// }; +// // clang-format on PyObject *MakePyVertexWithoutCopy(mgp_vertex &vertex, PyGraph *py_graph) { MG_ASSERT(py_graph); @@ -2001,17 +2166,26 @@ static PyMethodDef PyPathMethods[] = { {nullptr}, }; -// clang-format off -static PyTypeObject PyPathType = { - PyVarObject_HEAD_INIT(nullptr, 0) - .tp_name = "_mgp.Path", - .tp_basicsize = sizeof(PyPath), - .tp_dealloc = reinterpret_cast<destructor>(PyPathDealloc), - .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_doc = "Wraps struct mgp_path.", - .tp_methods = PyPathMethods, -}; -// clang-format on +static PyTypeObject PyPathType = PyTypeBuilder{} + .Name("_mgp.Path") + .BasicSize(sizeof(PyPath)) + .Dealloc(reinterpret_cast<destructor>(PyPathDealloc)) + .Flags(Py_TPFLAGS_DEFAULT) + .Doc("Wraps struct mgp_path.") + .Methods(PyPathMethods) + .Build(); + +// // clang-format off +// static PyTypeObject PyPathType = { +// PyVarObject_HEAD_INIT(nullptr, 0) +// .tp_name = "_mgp.Path", +// .tp_basicsize = sizeof(PyPath), +// .tp_dealloc = reinterpret_cast<destructor>(PyPathDealloc), +// .tp_flags = Py_TPFLAGS_DEFAULT, +// .tp_doc = "Wraps struct mgp_path.", +// .tp_methods = PyPathMethods, +// }; +// // clang-format on PyObject *MakePyPath(mgp_path *path, PyGraph *py_graph) { MG_ASSERT(path); @@ -2119,18 +2293,26 @@ static PyMethodDef PyLoggerMethods[] = { {nullptr}, }; -// clang-format off -// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) -static PyTypeObject PyLoggerType = { - PyVarObject_HEAD_INIT(nullptr, 0) - .tp_name = "_mgp.Logger", - .tp_basicsize = sizeof(PyLogger), - // NOLINTNEXTLINE(hicpp-signed-bitwise) - .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_doc = "Logging API.", - .tp_methods = PyLoggerMethods, -}; -// clang-format on +static PyTypeObject PyLoggerType = PyTypeBuilder{} + .Name("_mgp.Logger") + .BasicSize(sizeof(PyLogger)) + .Flags(Py_TPFLAGS_DEFAULT) + .Doc("Logging API.") + .Methods(PyLoggerMethods) + .Build(); + +// // clang-format off +// // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) +// static PyTypeObject PyLoggerType = { +// PyVarObject_HEAD_INIT(nullptr, 0) +// .tp_name = "_mgp.Logger", +// .tp_basicsize = sizeof(PyLogger), +// // NOLINTNEXTLINE(hicpp-signed-bitwise) +// .tp_flags = Py_TPFLAGS_DEFAULT, +// .tp_doc = "Logging API.", +// .tp_methods = PyLoggerMethods, +// }; +// // clang-format on struct PyMgpError { const char *name; @@ -2363,6 +2545,7 @@ py::Object MgpValueToPyObject(const mgp_value &value, PyGraph *py_graph) { return py_duration; } } + throw 1; } mgp_value *PyObjectToMgpValue(PyObject *o, mgp_memory *memory) { diff --git a/src/query/stream/common.hpp b/src/query/stream/common.hpp index 0882d9cd4..e471f9581 100644 --- a/src/query/stream/common.hpp +++ b/src/query/stream/common.hpp @@ -75,6 +75,7 @@ constexpr std::string_view StreamSourceTypeToString(StreamSourceType type) { case StreamSourceType::PULSAR: return "pulsar"; } + throw 1; } template <Stream T> diff --git a/src/query/stream/sources.cpp b/src/query/stream/sources.cpp index 82ddc6216..90115534f 100644 --- a/src/query/stream/sources.cpp +++ b/src/query/stream/sources.cpp @@ -33,9 +33,9 @@ KafkaStream::KafkaStream(std::string stream_name, StreamInfo stream_info, KafkaStream::StreamInfo KafkaStream::Info(std::string transformation_name) const { const auto &info = consumer_->Info(); - return {{.batch_interval = info.batch_interval, - .batch_size = info.batch_size, - .transformation_name = std::move(transformation_name)}, + return {.common_info = {.batch_interval = info.batch_interval, + .batch_size = info.batch_size, + .transformation_name = std::move(transformation_name)}, .topics = info.topics, .consumer_group = info.consumer_group, .bootstrap_servers = info.bootstrap_servers, @@ -101,9 +101,9 @@ PulsarStream::PulsarStream(std::string stream_name, StreamInfo stream_info, PulsarStream::StreamInfo PulsarStream::Info(std::string transformation_name) const { const auto &info = consumer_->Info(); - return {{.batch_interval = info.batch_interval, - .batch_size = info.batch_size, - .transformation_name = std::move(transformation_name)}, + return {.common_info = {.batch_interval = info.batch_interval, + .batch_size = info.batch_size, + .transformation_name = std::move(transformation_name)}, .topics = info.topics, .service_url = info.service_url}; } diff --git a/src/storage/v2/durability/snapshot.cpp b/src/storage/v2/durability/snapshot.cpp index ae38882bc..16c7d017c 100644 --- a/src/storage/v2/durability/snapshot.cpp +++ b/src/storage/v2/durability/snapshot.cpp @@ -775,15 +775,15 @@ void CreateSnapshot(Transaction *transaction, const std::filesystem::path &snaps const auto &in_edges = maybe_in_edges.GetValue(); snapshot.WriteUint(in_edges.size()); for (const auto &item : in_edges) { - snapshot.WriteUint(item.GidX().AsUint()); - snapshot.WriteUint(item.FromVertex().GidX().AsUint()); + snapshot.WriteUint(item.Gid().AsUint()); + snapshot.WriteUint(item.FromVertex().Gid().AsUint()); write_mapping(item.EdgeType()); } const auto &out_edges = maybe_out_edges.GetValue(); snapshot.WriteUint(out_edges.size()); for (const auto &item : out_edges) { - snapshot.WriteUint(item.GidX().AsUint()); - snapshot.WriteUint(item.ToVertex().GidX().AsUint()); + snapshot.WriteUint(item.Gid().AsUint()); + snapshot.WriteUint(item.ToVertex().Gid().AsUint()); write_mapping(item.EdgeType()); } } diff --git a/src/storage/v2/edge_accessor.hpp b/src/storage/v2/edge_accessor.hpp index 32879f339..95f128f50 100644 --- a/src/storage/v2/edge_accessor.hpp +++ b/src/storage/v2/edge_accessor.hpp @@ -68,7 +68,7 @@ class EdgeAccessor final { /// @throw std::bad_alloc Result<std::map<PropertyId, PropertyValue>> Properties(View view) const; - Gid GidX() const noexcept { + storage::Gid Gid() const noexcept { if (config_.properties_on_edges) { return edge_.ptr->gid; } else { @@ -107,6 +107,6 @@ class EdgeAccessor final { namespace std { template <> struct hash<memgraph::storage::EdgeAccessor> { - size_t operator()(const memgraph::storage::EdgeAccessor &e) const { return e.GidX().AsUint(); } + size_t operator()(const memgraph::storage::EdgeAccessor &e) const { return e.Gid().AsUint(); } }; } // namespace std diff --git a/src/storage/v2/vertex_accessor.hpp b/src/storage/v2/vertex_accessor.hpp index 16d9dc4fc..6c617e09f 100644 --- a/src/storage/v2/vertex_accessor.hpp +++ b/src/storage/v2/vertex_accessor.hpp @@ -94,7 +94,7 @@ class VertexAccessor final { Result<size_t> OutDegree(View view) const; - Gid GidX() const noexcept { return vertex_->gid; } + storage::Gid Gid() const noexcept { return vertex_->gid; } bool operator==(const VertexAccessor &other) const noexcept { return vertex_ == other.vertex_ && transaction_ == other.transaction_; @@ -123,6 +123,6 @@ class VertexAccessor final { namespace std { template <> struct hash<memgraph::storage::VertexAccessor> { - size_t operator()(const memgraph::storage::VertexAccessor &v) const noexcept { return v.GidX().AsUint(); } + size_t operator()(const memgraph::storage::VertexAccessor &v) const noexcept { return v.Gid().AsUint(); } }; } // namespace std diff --git a/src/utils/exceptions.hpp b/src/utils/exceptions.hpp index 0e8379adb..03e719e52 100644 --- a/src/utils/exceptions.hpp +++ b/src/utils/exceptions.hpp @@ -18,6 +18,7 @@ #include <exception> #include <string_view> +#include <fmt/core.h> // https://github.com/fmtlib/fmt/issues/2419 #include <fmt/format.h> #include <fmt/ostream.h>