2023-06-29 17:44:55 +08:00
|
|
|
// Copyright 2023 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-05-30 21:19:38 +08:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-11 21:11:48 +08:00
|
|
|
#include <iterator>
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
[E129-MG <-T0982-MG] implement edge type filtering (#489)
* GRANT, REVOKE, DENY and access_checker DONE
* Added AccessChecker to ExecutionContext
* grammar expanded; (#462)
* current
* T0954 mg expand user and role to hold permissions on labels (#465)
* added FineGrainedAccessPermissions class to model
* expanded user and role with fine grained access permissions
* fixed grammar
* [E129 < T0953-MG] GRANT, DENY, REVOKE added in interpreter and mainVisitor (#464)
* GRANT, DENY, REVOKE added in interpreter and mainVisitor
* Commented labelPermissons
* remove labelsPermission adding
* Fixed
* Removed extra lambda
* fixed
* [E129<-T0955-MG] Expand ExecutionContext with label related information (#467)
* added
* Added FineGrainedAccessChecker to Context
* fixed
* Added filtering
* testing
* Added edge filtering to storage, need to add filtering in simple Expand in operator.cpp
* Removed storage changes
* MATCH filtering working
* EdgeTypeFiltering working, just need to test everything again
* Removed FineGrainedAccessChecker
* Removed Expand Path
* Fix
* Tested FineGrainedAccessHandler, need to test AuthChecker
* Added integration test for lba
* Fixed merge conflicts
* PR fix
* fixed
* PR fix
* Fix test
* removed .vscode, .cache, .githooks
* githooks
* added tests
* fixed build
* Changed ast.lcp and User pointer to value in context.hpp
* Fixed test
* Remove denies on grant all
* AuthChecker
* Pr fix, auth_checker still not fixed
* Create mg-glue and extract UserBasedAuthChecker from AuthChecker
* Build fixed, need to fix test
* e2e tests
* e2e test working
* Added unit test, e2e and FineGrainedChecker
* Mege E129, auth_checker tests
* Fixed test
* e2e fix
Co-authored-by: Boris Taševski <36607228+BorisTasevski@users.noreply.github.com>
Co-authored-by: josipmrden <josip.mrden@external-basf.com>
Co-authored-by: János Benjamin Antal <benjamin.antal@memgraph.io>
2022-08-16 21:57:23 +08:00
|
|
|
#include "auth/models.hpp"
|
|
|
|
#include "glue/auth_checker.hpp"
|
2017-04-25 21:38:46 +08:00
|
|
|
#include "query/common.hpp"
|
2017-09-13 16:27:12 +08:00
|
|
|
#include "query/context.hpp"
|
2019-11-22 01:38:01 +08:00
|
|
|
#include "query/db_accessor.hpp"
|
2017-04-11 21:11:48 +08:00
|
|
|
#include "query/frontend/semantic/symbol_table.hpp"
|
2017-04-13 16:01:16 +08:00
|
|
|
#include "query/interpret/frame.hpp"
|
2017-04-25 21:38:46 +08:00
|
|
|
#include "query/plan/operator.hpp"
|
2019-11-22 01:25:25 +08:00
|
|
|
#include "storage/v2/storage.hpp"
|
2021-01-21 22:47:56 +08:00
|
|
|
#include "utils/logging.hpp"
|
2019-11-22 01:25:25 +08:00
|
|
|
|
2017-04-11 21:11:48 +08:00
|
|
|
#include "query_common.hpp"
|
|
|
|
|
2022-02-22 20:33:45 +08:00
|
|
|
using namespace memgraph::query;
|
|
|
|
using namespace memgraph::query::plan;
|
2017-04-11 21:11:48 +08:00
|
|
|
|
2017-06-27 17:50:57 +08:00
|
|
|
using Bound = ScanAllByLabelPropertyRange::Bound;
|
|
|
|
|
2022-02-22 20:33:45 +08:00
|
|
|
ExecutionContext MakeContext(const AstStorage &storage, const SymbolTable &symbol_table,
|
|
|
|
memgraph::query::DbAccessor *dba) {
|
2023-07-29 23:59:11 +08:00
|
|
|
ExecutionContext context{.db_accessor = dba};
|
2019-01-16 18:30:17 +08:00
|
|
|
context.symbol_table = symbol_table;
|
2021-02-18 22:32:43 +08:00
|
|
|
context.evaluation_context.properties = NamesToProperties(storage.properties_, dba);
|
2019-01-16 18:30:17 +08:00
|
|
|
context.evaluation_context.labels = NamesToLabels(storage.labels_, dba);
|
Remove GraphDbAccessor and storage types from Ast
Summary:
This diff removes the need for a database when parsing a query and
creating an Ast. Instead of storing storage::{Label,Property,EdgeType}
in Ast nodes, we store the name and an index into all of the names. This
allows for easy creation of a map from {Label,Property,EdgeType} index
into the concrete storage type. Obviously, this comes with a performance
penalty during execution, but it should be minor. The upside is that the
query/frontend minimally depends on storage (PropertyValue), which makes
writing tests easier as well as running them a lot faster (there is no
database setup). This is most noticeable in the ast_serialization test
which took a long time due to start up of a distributed database.
Reviewers: mtomic, llugovic
Reviewed By: mtomic
Subscribers: mferencevic, pullbot
Differential Revision: https://phabricator.memgraph.io/D1774
2019-01-14 21:41:37 +08:00
|
|
|
return context;
|
|
|
|
}
|
2022-09-14 07:10:28 +08:00
|
|
|
#ifdef MG_ENTERPRISE
|
[E129-MG <-T0982-MG] implement edge type filtering (#489)
* GRANT, REVOKE, DENY and access_checker DONE
* Added AccessChecker to ExecutionContext
* grammar expanded; (#462)
* current
* T0954 mg expand user and role to hold permissions on labels (#465)
* added FineGrainedAccessPermissions class to model
* expanded user and role with fine grained access permissions
* fixed grammar
* [E129 < T0953-MG] GRANT, DENY, REVOKE added in interpreter and mainVisitor (#464)
* GRANT, DENY, REVOKE added in interpreter and mainVisitor
* Commented labelPermissons
* remove labelsPermission adding
* Fixed
* Removed extra lambda
* fixed
* [E129<-T0955-MG] Expand ExecutionContext with label related information (#467)
* added
* Added FineGrainedAccessChecker to Context
* fixed
* Added filtering
* testing
* Added edge filtering to storage, need to add filtering in simple Expand in operator.cpp
* Removed storage changes
* MATCH filtering working
* EdgeTypeFiltering working, just need to test everything again
* Removed FineGrainedAccessChecker
* Removed Expand Path
* Fix
* Tested FineGrainedAccessHandler, need to test AuthChecker
* Added integration test for lba
* Fixed merge conflicts
* PR fix
* fixed
* PR fix
* Fix test
* removed .vscode, .cache, .githooks
* githooks
* added tests
* fixed build
* Changed ast.lcp and User pointer to value in context.hpp
* Fixed test
* Remove denies on grant all
* AuthChecker
* Pr fix, auth_checker still not fixed
* Create mg-glue and extract UserBasedAuthChecker from AuthChecker
* Build fixed, need to fix test
* e2e tests
* e2e test working
* Added unit test, e2e and FineGrainedChecker
* Mege E129, auth_checker tests
* Fixed test
* e2e fix
Co-authored-by: Boris Taševski <36607228+BorisTasevski@users.noreply.github.com>
Co-authored-by: josipmrden <josip.mrden@external-basf.com>
Co-authored-by: János Benjamin Antal <benjamin.antal@memgraph.io>
2022-08-16 21:57:23 +08:00
|
|
|
ExecutionContext MakeContextWithFineGrainedChecker(const AstStorage &storage, const SymbolTable &symbol_table,
|
|
|
|
memgraph::query::DbAccessor *dba,
|
|
|
|
memgraph::glue::FineGrainedAuthChecker *auth_checker) {
|
2023-07-29 23:59:11 +08:00
|
|
|
ExecutionContext context{.db_accessor = dba};
|
[E129-MG <-T0982-MG] implement edge type filtering (#489)
* GRANT, REVOKE, DENY and access_checker DONE
* Added AccessChecker to ExecutionContext
* grammar expanded; (#462)
* current
* T0954 mg expand user and role to hold permissions on labels (#465)
* added FineGrainedAccessPermissions class to model
* expanded user and role with fine grained access permissions
* fixed grammar
* [E129 < T0953-MG] GRANT, DENY, REVOKE added in interpreter and mainVisitor (#464)
* GRANT, DENY, REVOKE added in interpreter and mainVisitor
* Commented labelPermissons
* remove labelsPermission adding
* Fixed
* Removed extra lambda
* fixed
* [E129<-T0955-MG] Expand ExecutionContext with label related information (#467)
* added
* Added FineGrainedAccessChecker to Context
* fixed
* Added filtering
* testing
* Added edge filtering to storage, need to add filtering in simple Expand in operator.cpp
* Removed storage changes
* MATCH filtering working
* EdgeTypeFiltering working, just need to test everything again
* Removed FineGrainedAccessChecker
* Removed Expand Path
* Fix
* Tested FineGrainedAccessHandler, need to test AuthChecker
* Added integration test for lba
* Fixed merge conflicts
* PR fix
* fixed
* PR fix
* Fix test
* removed .vscode, .cache, .githooks
* githooks
* added tests
* fixed build
* Changed ast.lcp and User pointer to value in context.hpp
* Fixed test
* Remove denies on grant all
* AuthChecker
* Pr fix, auth_checker still not fixed
* Create mg-glue and extract UserBasedAuthChecker from AuthChecker
* Build fixed, need to fix test
* e2e tests
* e2e test working
* Added unit test, e2e and FineGrainedChecker
* Mege E129, auth_checker tests
* Fixed test
* e2e fix
Co-authored-by: Boris Taševski <36607228+BorisTasevski@users.noreply.github.com>
Co-authored-by: josipmrden <josip.mrden@external-basf.com>
Co-authored-by: János Benjamin Antal <benjamin.antal@memgraph.io>
2022-08-16 21:57:23 +08:00
|
|
|
context.symbol_table = symbol_table;
|
|
|
|
context.evaluation_context.properties = NamesToProperties(storage.properties_, dba);
|
|
|
|
context.evaluation_context.labels = NamesToLabels(storage.labels_, dba);
|
|
|
|
context.auth_checker = std::make_unique<memgraph::glue::FineGrainedAuthChecker>(std::move(*auth_checker));
|
|
|
|
|
|
|
|
return context;
|
|
|
|
}
|
2022-09-14 07:10:28 +08:00
|
|
|
#endif
|
[E129-MG <-T0982-MG] implement edge type filtering (#489)
* GRANT, REVOKE, DENY and access_checker DONE
* Added AccessChecker to ExecutionContext
* grammar expanded; (#462)
* current
* T0954 mg expand user and role to hold permissions on labels (#465)
* added FineGrainedAccessPermissions class to model
* expanded user and role with fine grained access permissions
* fixed grammar
* [E129 < T0953-MG] GRANT, DENY, REVOKE added in interpreter and mainVisitor (#464)
* GRANT, DENY, REVOKE added in interpreter and mainVisitor
* Commented labelPermissons
* remove labelsPermission adding
* Fixed
* Removed extra lambda
* fixed
* [E129<-T0955-MG] Expand ExecutionContext with label related information (#467)
* added
* Added FineGrainedAccessChecker to Context
* fixed
* Added filtering
* testing
* Added edge filtering to storage, need to add filtering in simple Expand in operator.cpp
* Removed storage changes
* MATCH filtering working
* EdgeTypeFiltering working, just need to test everything again
* Removed FineGrainedAccessChecker
* Removed Expand Path
* Fix
* Tested FineGrainedAccessHandler, need to test AuthChecker
* Added integration test for lba
* Fixed merge conflicts
* PR fix
* fixed
* PR fix
* Fix test
* removed .vscode, .cache, .githooks
* githooks
* added tests
* fixed build
* Changed ast.lcp and User pointer to value in context.hpp
* Fixed test
* Remove denies on grant all
* AuthChecker
* Pr fix, auth_checker still not fixed
* Create mg-glue and extract UserBasedAuthChecker from AuthChecker
* Build fixed, need to fix test
* e2e tests
* e2e test working
* Added unit test, e2e and FineGrainedChecker
* Mege E129, auth_checker tests
* Fixed test
* e2e fix
Co-authored-by: Boris Taševski <36607228+BorisTasevski@users.noreply.github.com>
Co-authored-by: josipmrden <josip.mrden@external-basf.com>
Co-authored-by: János Benjamin Antal <benjamin.antal@memgraph.io>
2022-08-16 21:57:23 +08:00
|
|
|
|
2018-07-02 21:34:33 +08:00
|
|
|
/** Helper function that collects all the results from the given Produce. */
|
2021-02-18 22:32:43 +08:00
|
|
|
std::vector<std::vector<TypedValue>> CollectProduce(const Produce &produce, ExecutionContext *context) {
|
2019-01-16 18:30:17 +08:00
|
|
|
Frame frame(context->symbol_table.max_position());
|
2017-04-11 21:11:48 +08:00
|
|
|
|
|
|
|
// top level node in the operator tree is a produce (return)
|
|
|
|
// so stream out results
|
|
|
|
|
|
|
|
// collect the symbols from the return clause
|
|
|
|
std::vector<Symbol> symbols;
|
2023-11-22 21:05:02 +08:00
|
|
|
for (auto *named_expression : produce.named_expressions_)
|
2019-02-05 20:16:07 +08:00
|
|
|
symbols.emplace_back(context->symbol_table.at(*named_expression));
|
2017-04-11 21:11:48 +08:00
|
|
|
|
|
|
|
// stream out results
|
2022-02-22 20:33:45 +08:00
|
|
|
auto cursor = produce.MakeCursor(memgraph::utils::NewDeleteResource());
|
2018-07-02 21:34:33 +08:00
|
|
|
std::vector<std::vector<TypedValue>> results;
|
Remove GraphDbAccessor and storage types from Ast
Summary:
This diff removes the need for a database when parsing a query and
creating an Ast. Instead of storing storage::{Label,Property,EdgeType}
in Ast nodes, we store the name and an index into all of the names. This
allows for easy creation of a map from {Label,Property,EdgeType} index
into the concrete storage type. Obviously, this comes with a performance
penalty during execution, but it should be minor. The upside is that the
query/frontend minimally depends on storage (PropertyValue), which makes
writing tests easier as well as running them a lot faster (there is no
database setup). This is most noticeable in the ast_serialization test
which took a long time due to start up of a distributed database.
Reviewers: mtomic, llugovic
Reviewed By: mtomic
Subscribers: mferencevic, pullbot
Differential Revision: https://phabricator.memgraph.io/D1774
2019-01-14 21:41:37 +08:00
|
|
|
while (cursor->Pull(frame, *context)) {
|
2017-04-11 21:11:48 +08:00
|
|
|
std::vector<TypedValue> values;
|
|
|
|
for (auto &symbol : symbols) values.emplace_back(frame[symbol]);
|
2018-07-02 21:34:33 +08:00
|
|
|
results.emplace_back(values);
|
2017-04-11 21:11:48 +08:00
|
|
|
}
|
|
|
|
|
2018-07-02 21:34:33 +08:00
|
|
|
return results;
|
2017-04-11 21:11:48 +08:00
|
|
|
}
|
|
|
|
|
2019-01-16 18:30:17 +08:00
|
|
|
int PullAll(const LogicalOperator &logical_op, ExecutionContext *context) {
|
|
|
|
Frame frame(context->symbol_table.max_position());
|
2022-02-22 20:33:45 +08:00
|
|
|
auto cursor = logical_op.MakeCursor(memgraph::utils::NewDeleteResource());
|
2017-04-11 21:11:48 +08:00
|
|
|
int count = 0;
|
2023-06-29 17:44:55 +08:00
|
|
|
while (cursor->Pull(frame, *context)) {
|
|
|
|
count++;
|
|
|
|
}
|
2017-04-11 21:11:48 +08:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... TNamedExpressions>
|
2021-02-18 22:32:43 +08:00
|
|
|
auto MakeProduce(std::shared_ptr<LogicalOperator> input, TNamedExpressions... named_expressions) {
|
|
|
|
return std::make_shared<Produce>(input, std::vector<NamedExpression *>{named_expressions...});
|
2017-04-11 21:11:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ScanAllTuple {
|
|
|
|
NodeAtom *node_;
|
|
|
|
std::shared_ptr<LogicalOperator> op_;
|
|
|
|
Symbol sym_;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and returns a tuple of stuff for a scan-all starting
|
|
|
|
* from the node with the given name.
|
|
|
|
*
|
2017-05-19 21:37:28 +08:00
|
|
|
* Returns ScanAllTuple(node_atom, scan_all_logical_op, symbol).
|
2017-04-11 21:11:48 +08:00
|
|
|
*/
|
2021-02-18 22:32:43 +08:00
|
|
|
ScanAllTuple MakeScanAll(AstStorage &storage, SymbolTable &symbol_table, const std::string &identifier,
|
2022-02-22 20:33:45 +08:00
|
|
|
std::shared_ptr<LogicalOperator> input = {nullptr},
|
|
|
|
memgraph::storage::View view = memgraph::storage::View::OLD) {
|
2023-11-22 21:05:02 +08:00
|
|
|
auto *node = memgraph::query::test_common::GetNode(storage, identifier);
|
2017-05-12 17:37:22 +08:00
|
|
|
auto symbol = symbol_table.CreateSymbol(identifier, true);
|
2019-02-05 20:16:07 +08:00
|
|
|
node->identifier_->MapTo(symbol);
|
2019-09-05 22:32:53 +08:00
|
|
|
auto logical_op = std::make_shared<ScanAll>(input, symbol, view);
|
2017-05-19 21:37:28 +08:00
|
|
|
return ScanAllTuple{node, logical_op, symbol};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and returns a tuple of stuff for a scan-all starting
|
|
|
|
* from the node with the given name and label.
|
|
|
|
*
|
|
|
|
* Returns ScanAllTuple(node_atom, scan_all_logical_op, symbol).
|
|
|
|
*/
|
2021-02-18 22:32:43 +08:00
|
|
|
ScanAllTuple MakeScanAllByLabel(AstStorage &storage, SymbolTable &symbol_table, const std::string &identifier,
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::storage::LabelId label, std::shared_ptr<LogicalOperator> input = {nullptr},
|
|
|
|
memgraph::storage::View view = memgraph::storage::View::OLD) {
|
2023-11-22 21:05:02 +08:00
|
|
|
auto *node = memgraph::query::test_common::GetNode(storage, identifier);
|
2017-05-19 21:37:28 +08:00
|
|
|
auto symbol = symbol_table.CreateSymbol(identifier, true);
|
2019-02-05 20:16:07 +08:00
|
|
|
node->identifier_->MapTo(symbol);
|
2021-02-18 22:32:43 +08:00
|
|
|
auto logical_op = std::make_shared<ScanAllByLabel>(input, symbol, label, view);
|
2017-04-11 21:11:48 +08:00
|
|
|
return ScanAllTuple{node, logical_op, symbol};
|
|
|
|
}
|
|
|
|
|
2017-06-27 17:50:57 +08:00
|
|
|
/**
|
|
|
|
* Creates and returns a tuple of stuff for a scan-all starting from the node
|
|
|
|
* with the given name and label whose property values are in range.
|
|
|
|
*
|
|
|
|
* Returns ScanAllTuple(node_atom, scan_all_logical_op, symbol).
|
|
|
|
*/
|
2021-02-18 22:32:43 +08:00
|
|
|
ScanAllTuple MakeScanAllByLabelPropertyRange(AstStorage &storage, SymbolTable &symbol_table, std::string identifier,
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::storage::LabelId label, memgraph::storage::PropertyId property,
|
2021-02-18 22:32:43 +08:00
|
|
|
const std::string &property_name, std::optional<Bound> lower_bound,
|
|
|
|
std::optional<Bound> upper_bound,
|
|
|
|
std::shared_ptr<LogicalOperator> input = {nullptr},
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::storage::View view = memgraph::storage::View::OLD) {
|
2023-11-22 21:05:02 +08:00
|
|
|
auto *node = memgraph::query::test_common::GetNode(storage, identifier);
|
2017-06-27 17:50:57 +08:00
|
|
|
auto symbol = symbol_table.CreateSymbol(identifier, true);
|
2019-02-05 20:16:07 +08:00
|
|
|
node->identifier_->MapTo(symbol);
|
2021-02-18 22:32:43 +08:00
|
|
|
auto logical_op = std::make_shared<ScanAllByLabelPropertyRange>(input, symbol, label, property, property_name,
|
|
|
|
lower_bound, upper_bound, view);
|
2017-06-27 17:50:57 +08:00
|
|
|
return ScanAllTuple{node, logical_op, symbol};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and returns a tuple of stuff for a scan-all starting from the node
|
|
|
|
* with the given name and label whose property value is equal to given value.
|
|
|
|
*
|
|
|
|
* Returns ScanAllTuple(node_atom, scan_all_logical_op, symbol).
|
|
|
|
*/
|
2021-02-18 22:32:43 +08:00
|
|
|
ScanAllTuple MakeScanAllByLabelPropertyValue(AstStorage &storage, SymbolTable &symbol_table, std::string identifier,
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::storage::LabelId label, memgraph::storage::PropertyId property,
|
2021-02-18 22:32:43 +08:00
|
|
|
const std::string &property_name, Expression *value,
|
|
|
|
std::shared_ptr<LogicalOperator> input = {nullptr},
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::storage::View view = memgraph::storage::View::OLD) {
|
2023-11-22 21:05:02 +08:00
|
|
|
auto *node = memgraph::query::test_common::GetNode(storage, identifier);
|
2017-06-27 17:50:57 +08:00
|
|
|
auto symbol = symbol_table.CreateSymbol(identifier, true);
|
2019-02-05 20:16:07 +08:00
|
|
|
node->identifier_->MapTo(symbol);
|
2021-02-18 22:32:43 +08:00
|
|
|
auto logical_op =
|
|
|
|
std::make_shared<ScanAllByLabelPropertyValue>(input, symbol, label, property, property_name, value, view);
|
2017-06-27 17:50:57 +08:00
|
|
|
return ScanAllTuple{node, logical_op, symbol};
|
|
|
|
}
|
|
|
|
|
2017-04-11 21:11:48 +08:00
|
|
|
struct ExpandTuple {
|
|
|
|
EdgeAtom *edge_;
|
|
|
|
Symbol edge_sym_;
|
|
|
|
NodeAtom *node_;
|
|
|
|
Symbol node_sym_;
|
|
|
|
std::shared_ptr<LogicalOperator> op_;
|
|
|
|
};
|
|
|
|
|
2021-02-18 22:32:43 +08:00
|
|
|
ExpandTuple MakeExpand(AstStorage &storage, SymbolTable &symbol_table, std::shared_ptr<LogicalOperator> input,
|
|
|
|
Symbol input_symbol, const std::string &edge_identifier, EdgeAtom::Direction direction,
|
2022-02-22 20:33:45 +08:00
|
|
|
const std::vector<memgraph::storage::EdgeTypeId> &edge_types, const std::string &node_identifier,
|
|
|
|
bool existing_node, memgraph::storage::View view) {
|
2023-11-22 21:05:02 +08:00
|
|
|
auto *edge = memgraph::query::test_common::GetEdge(storage, edge_identifier, direction);
|
2017-05-12 17:37:22 +08:00
|
|
|
auto edge_sym = symbol_table.CreateSymbol(edge_identifier, true);
|
2019-02-05 20:16:07 +08:00
|
|
|
edge->identifier_->MapTo(edge_sym);
|
2017-04-11 21:11:48 +08:00
|
|
|
|
2023-11-22 21:05:02 +08:00
|
|
|
auto *node = memgraph::query::test_common::GetNode(storage, node_identifier);
|
2017-05-12 17:37:22 +08:00
|
|
|
auto node_sym = symbol_table.CreateSymbol(node_identifier, true);
|
2019-02-05 20:16:07 +08:00
|
|
|
node->identifier_->MapTo(node_sym);
|
2017-04-11 21:11:48 +08:00
|
|
|
|
2021-01-21 22:47:56 +08:00
|
|
|
auto op =
|
2021-02-18 22:32:43 +08:00
|
|
|
std::make_shared<Expand>(input, input_symbol, node_sym, edge_sym, direction, edge_types, existing_node, view);
|
2017-04-11 21:11:48 +08:00
|
|
|
|
|
|
|
return ExpandTuple{edge, edge_sym, node, node_sym, op};
|
|
|
|
}
|
|
|
|
|
2018-08-29 16:26:27 +08:00
|
|
|
struct UnwindTuple {
|
|
|
|
Symbol sym_;
|
|
|
|
std::shared_ptr<LogicalOperator> op_;
|
|
|
|
};
|
|
|
|
|
2021-02-18 22:32:43 +08:00
|
|
|
UnwindTuple MakeUnwind(SymbolTable &symbol_table, const std::string &symbol_name,
|
|
|
|
std::shared_ptr<LogicalOperator> input, Expression *input_expression) {
|
2018-08-29 16:26:27 +08:00
|
|
|
auto sym = symbol_table.CreateSymbol(symbol_name, true);
|
2022-02-22 20:33:45 +08:00
|
|
|
auto op = std::make_shared<memgraph::query::plan::Unwind>(input, input_expression, sym);
|
2018-08-29 16:26:27 +08:00
|
|
|
return UnwindTuple{sym, op};
|
|
|
|
}
|
|
|
|
|
2019-11-22 01:25:25 +08:00
|
|
|
template <typename TIterable>
|
|
|
|
auto CountIterable(TIterable &&iterable) {
|
|
|
|
uint64_t count = 0;
|
|
|
|
for (auto it = iterable.begin(); it != iterable.end(); ++it) {
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2022-02-22 20:33:45 +08:00
|
|
|
inline uint64_t CountEdges(memgraph::query::DbAccessor *dba, memgraph::storage::View view) {
|
2019-11-22 01:25:25 +08:00
|
|
|
uint64_t count = 0;
|
|
|
|
for (auto vertex : dba->Vertices(view)) {
|
|
|
|
auto maybe_edges = vertex.OutEdges(view);
|
2021-01-21 22:47:56 +08:00
|
|
|
MG_ASSERT(maybe_edges.HasValue());
|
2023-09-08 23:12:25 +08:00
|
|
|
count += CountIterable(maybe_edges->edges);
|
2019-11-22 01:25:25 +08:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|