Migrate tests to storage v2 part 3
Reviewers: teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2560
This commit is contained in:
parent
8a94b16e79
commit
fc146a71e0
@ -109,7 +109,7 @@ add_unit_test(query_cost_estimator.cpp)
|
||||
target_link_libraries(${test_prefix}query_cost_estimator mg-single-node-v2 mg-auth kvstore_dummy_lib)
|
||||
|
||||
add_unit_test(query_expression_evaluator.cpp)
|
||||
target_link_libraries(${test_prefix}query_expression_evaluator mg-single-node kvstore_dummy_lib)
|
||||
target_link_libraries(${test_prefix}query_expression_evaluator mg-single-node-v2 mg-auth kvstore_dummy_lib)
|
||||
|
||||
add_unit_test(plan_pretty_print.cpp)
|
||||
target_link_libraries(${test_prefix}plan_pretty_print mg-single-node-v2 mg-auth kvstore_dummy_lib)
|
||||
@ -124,7 +124,7 @@ add_unit_test(query_profile.cpp)
|
||||
target_link_libraries(${test_prefix}query_profile mg-single-node-v2 mg-auth kvstore_dummy_lib)
|
||||
|
||||
add_unit_test(query_plan_accumulate_aggregate.cpp)
|
||||
target_link_libraries(${test_prefix}query_plan_accumulate_aggregate mg-single-node kvstore_dummy_lib)
|
||||
target_link_libraries(${test_prefix}query_plan_accumulate_aggregate mg-single-node-v2 mg-auth kvstore_dummy_lib)
|
||||
|
||||
add_unit_test(query_plan_bag_semantics.cpp)
|
||||
target_link_libraries(${test_prefix}query_plan_bag_semantics mg-single-node-v2 mg-auth kvstore_dummy_lib)
|
||||
@ -141,7 +141,7 @@ add_unit_test(query_plan_edge_cases.cpp)
|
||||
target_link_libraries(${test_prefix}query_plan_edge_cases mg-single-node-v2 mg-auth kvstore_dummy_lib)
|
||||
|
||||
add_unit_test(query_plan_match_filter_return.cpp)
|
||||
target_link_libraries(${test_prefix}query_plan_match_filter_return mg-single-node kvstore_dummy_lib)
|
||||
target_link_libraries(${test_prefix}query_plan_match_filter_return mg-single-node-v2 mg-auth kvstore_dummy_lib)
|
||||
|
||||
add_unit_test(query_plan.cpp)
|
||||
target_link_libraries(${test_prefix}query_plan mg-single-node-v2 mg-auth kvstore_dummy_lib)
|
||||
|
@ -32,14 +32,8 @@
|
||||
|
||||
#include "query/frontend/ast/ast.hpp"
|
||||
#include "query/frontend/ast/pretty_print.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
#ifdef MG_SINGLE_NODE_V2
|
||||
#include "storage/v2/id_types.hpp"
|
||||
#else
|
||||
// TODO (mferencevic): Remove once all cpp tests are migrated to v2.
|
||||
#include "storage/common/types/types.hpp"
|
||||
#endif
|
||||
#include "utils/string.hpp"
|
||||
|
||||
namespace query {
|
||||
|
||||
@ -121,7 +115,6 @@ auto GetOrderBy(T... exprs) {
|
||||
/// Create PropertyLookup with given name and property.
|
||||
///
|
||||
/// Name is used to create the Identifier which is used for property lookup.
|
||||
#ifdef MG_SINGLE_NODE_V2
|
||||
template <class TDbAccessor>
|
||||
auto GetPropertyLookup(AstStorage &storage, TDbAccessor &dba,
|
||||
const std::string &name, storage::PropertyId property) {
|
||||
@ -129,31 +122,13 @@ auto GetPropertyLookup(AstStorage &storage, TDbAccessor &dba,
|
||||
storage.Create<Identifier>(name),
|
||||
storage.GetPropertyIx(dba.PropertyToName(property)));
|
||||
}
|
||||
#else
|
||||
template <class TDbAccessor>
|
||||
auto GetPropertyLookup(AstStorage &storage, TDbAccessor &dba,
|
||||
const std::string &name, storage::Property property) {
|
||||
return storage.Create<PropertyLookup>(
|
||||
storage.Create<Identifier>(name),
|
||||
storage.GetPropertyIx(dba.PropertyName(property)));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MG_SINGLE_NODE_V2
|
||||
template <class TDbAccessor>
|
||||
auto GetPropertyLookup(AstStorage &storage, TDbAccessor &dba, Expression *expr,
|
||||
storage::PropertyId property) {
|
||||
return storage.Create<PropertyLookup>(
|
||||
expr, storage.GetPropertyIx(dba.PropertyToName(property)));
|
||||
}
|
||||
#else
|
||||
template <class TDbAccessor>
|
||||
auto GetPropertyLookup(AstStorage &storage, TDbAccessor &dba, Expression *expr,
|
||||
storage::Property property) {
|
||||
return storage.Create<PropertyLookup>(
|
||||
expr, storage.GetPropertyIx(dba.PropertyName(property)));
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class TDbAccessor>
|
||||
auto GetPropertyLookup(AstStorage &storage, TDbAccessor &dba, Expression *expr,
|
||||
@ -164,11 +139,7 @@ auto GetPropertyLookup(AstStorage &storage, TDbAccessor &dba, Expression *expr,
|
||||
template <class TDbAccessor>
|
||||
auto GetPropertyLookup(
|
||||
AstStorage &storage, TDbAccessor &, const std::string &name,
|
||||
#ifdef MG_SINGLE_NODE_V2
|
||||
const std::pair<std::string, storage::PropertyId> &prop_pair) {
|
||||
#else
|
||||
const std::pair<std::string, storage::Property> &prop_pair) {
|
||||
#endif
|
||||
return storage.Create<PropertyLookup>(storage.Create<Identifier>(name),
|
||||
storage.GetPropertyIx(prop_pair.first));
|
||||
}
|
||||
@ -176,11 +147,7 @@ auto GetPropertyLookup(
|
||||
template <class TDbAccessor>
|
||||
auto GetPropertyLookup(
|
||||
AstStorage &storage, TDbAccessor &, Expression *expr,
|
||||
#ifdef MG_SINGLE_NODE_V2
|
||||
const std::pair<std::string, storage::PropertyId> &prop_pair) {
|
||||
#else
|
||||
const std::pair<std::string, storage::Property> &prop_pair) {
|
||||
#endif
|
||||
return storage.Create<PropertyLookup>(expr,
|
||||
storage.GetPropertyIx(prop_pair.first));
|
||||
}
|
||||
@ -572,13 +539,8 @@ auto GetMerge(AstStorage &storage, Pattern *pattern, OnMatch on_match,
|
||||
#define MAP(...) \
|
||||
storage.Create<query::MapLiteral>( \
|
||||
std::unordered_map<query::PropertyIx, query::Expression *>{__VA_ARGS__})
|
||||
#ifdef MG_SINGLE_NODE_V2
|
||||
#define PROPERTY_PAIR(property_name) \
|
||||
std::make_pair(property_name, dba.NameToProperty(property_name))
|
||||
#else
|
||||
#define PROPERTY_PAIR(property_name) \
|
||||
std::make_pair(property_name, dba.Property(property_name))
|
||||
#endif
|
||||
#define PROPERTY_LOOKUP(...) \
|
||||
query::test_common::GetPropertyLookup(storage, dba, __VA_ARGS__)
|
||||
#define PARAMETER_LOOKUP(token_position) \
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "database/single_node/graph_db_accessor.hpp"
|
||||
#include "query/context.hpp"
|
||||
#include "query/frontend/ast/ast.hpp"
|
||||
#include "query/frontend/opencypher/parser.hpp"
|
||||
@ -15,7 +14,7 @@
|
||||
#include "query/interpret/eval.hpp"
|
||||
#include "query/interpret/frame.hpp"
|
||||
#include "query/path.hpp"
|
||||
#include "storage/common/types/types.hpp"
|
||||
#include "storage/v2/storage.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
#include "query_common.hpp"
|
||||
@ -29,8 +28,9 @@ namespace {
|
||||
|
||||
class ExpressionEvaluatorTest : public ::testing::Test {
|
||||
protected:
|
||||
database::GraphDb db;
|
||||
database::GraphDbAccessor dba{db.Access()};
|
||||
storage::Storage db;
|
||||
storage::Storage::Accessor storage_dba{db.Access()};
|
||||
query::DbAccessor dba{&storage_dba};
|
||||
|
||||
AstStorage storage;
|
||||
utils::MonotonicBufferResource mem{1024};
|
||||
@ -38,9 +38,7 @@ class ExpressionEvaluatorTest : public ::testing::Test {
|
||||
SymbolTable symbol_table;
|
||||
|
||||
Frame frame{128};
|
||||
query::DbAccessor execution_dba{&dba};
|
||||
ExpressionEvaluator eval{&frame, symbol_table, ctx, &execution_dba,
|
||||
storage::View::OLD};
|
||||
ExpressionEvaluator eval{&frame, symbol_table, ctx, &dba, storage::View::OLD};
|
||||
|
||||
Identifier *CreateIdentifierWithValue(std::string name,
|
||||
const TypedValue &value) {
|
||||
@ -53,8 +51,8 @@ class ExpressionEvaluatorTest : public ::testing::Test {
|
||||
|
||||
template <class TExpression>
|
||||
auto Eval(TExpression *expr) {
|
||||
ctx.properties = NamesToProperties(storage.properties_, &execution_dba);
|
||||
ctx.labels = NamesToLabels(storage.labels_, &execution_dba);
|
||||
ctx.properties = NamesToProperties(storage.properties_, &dba);
|
||||
ctx.labels = NamesToLabels(storage.labels_, &dba);
|
||||
auto value = expr->Accept(eval);
|
||||
EXPECT_EQ(value.GetMemoryResource(), &mem)
|
||||
<< "ExpressionEvaluator must use the MemoryResource from "
|
||||
@ -416,17 +414,17 @@ TEST_F(ExpressionEvaluatorTest, MapIndexing) {
|
||||
}
|
||||
|
||||
TEST_F(ExpressionEvaluatorTest, VertexAndEdgeIndexing) {
|
||||
auto edge_type = dba.EdgeType("edge_type");
|
||||
auto prop = dba.Property("prop");
|
||||
auto edge_type = dba.NameToEdgeType("edge_type");
|
||||
auto prop = dba.NameToProperty("prop");
|
||||
auto v1 = dba.InsertVertex();
|
||||
auto e11 = dba.InsertEdge(v1, v1, edge_type);
|
||||
v1.PropsSet(prop, PropertyValue(42));
|
||||
e11.PropsSet(prop, PropertyValue(43));
|
||||
auto e11 = dba.InsertEdge(&v1, &v1, edge_type);
|
||||
ASSERT_TRUE(e11.HasValue());
|
||||
ASSERT_TRUE(v1.SetProperty(prop, PropertyValue(42)).HasValue());
|
||||
ASSERT_TRUE(e11->SetProperty(prop, PropertyValue(43)).HasValue());
|
||||
dba.AdvanceCommand();
|
||||
|
||||
auto *vertex_id =
|
||||
CreateIdentifierWithValue("v1", TypedValue(query::VertexAccessor(v1)));
|
||||
auto *edge_id =
|
||||
CreateIdentifierWithValue("e11", TypedValue(query::EdgeAccessor(e11)));
|
||||
auto *vertex_id = CreateIdentifierWithValue("v1", TypedValue(v1));
|
||||
auto *edge_id = CreateIdentifierWithValue("e11", TypedValue(*e11));
|
||||
{
|
||||
// Legal indexing.
|
||||
auto *op1 = storage.Create<SubscriptOperator>(
|
||||
@ -633,13 +631,14 @@ TEST_F(ExpressionEvaluatorTest, IsNullOperator) {
|
||||
|
||||
TEST_F(ExpressionEvaluatorTest, LabelsTest) {
|
||||
auto v1 = dba.InsertVertex();
|
||||
v1.add_label(dba.Label("ANIMAL"));
|
||||
v1.add_label(dba.Label("DOG"));
|
||||
v1.add_label(dba.Label("NICE_DOG"));
|
||||
ASSERT_TRUE(v1.AddLabel(dba.NameToLabel("ANIMAL")).HasValue());
|
||||
ASSERT_TRUE(v1.AddLabel(dba.NameToLabel("DOG")).HasValue());
|
||||
ASSERT_TRUE(v1.AddLabel(dba.NameToLabel("NICE_DOG")).HasValue());
|
||||
dba.AdvanceCommand();
|
||||
auto *identifier = storage.Create<Identifier>("n");
|
||||
auto node_symbol = symbol_table.CreateSymbol("n", true);
|
||||
identifier->MapTo(node_symbol);
|
||||
frame[node_symbol] = TypedValue(query::VertexAccessor(v1));
|
||||
frame[node_symbol] = TypedValue(v1);
|
||||
{
|
||||
auto *op = storage.Create<LabelsTest>(
|
||||
identifier, std::vector<LabelIx>{storage.GetLabelIx("DOG"),
|
||||
@ -759,8 +758,7 @@ TEST_F(ExpressionEvaluatorTest, FunctionSingle2) {
|
||||
|
||||
TEST_F(ExpressionEvaluatorTest, FunctionSingleNullList) {
|
||||
AstStorage storage;
|
||||
auto *single =
|
||||
SINGLE("x", LITERAL(PropertyValue()), WHERE(LITERAL(true)));
|
||||
auto *single = SINGLE("x", LITERAL(PropertyValue()), WHERE(LITERAL(true)));
|
||||
const auto x_sym = symbol_table.CreateSymbol("x", true);
|
||||
single->identifier_->MapTo(x_sym);
|
||||
auto value = Eval(single);
|
||||
@ -830,13 +828,12 @@ TEST_F(ExpressionEvaluatorTest, Coalesce) {
|
||||
|
||||
// coalesce(null, null)
|
||||
EXPECT_TRUE(
|
||||
Eval(COALESCE(LITERAL(TypedValue()), LITERAL(TypedValue())))
|
||||
.IsNull());
|
||||
Eval(COALESCE(LITERAL(TypedValue()), LITERAL(TypedValue()))).IsNull());
|
||||
|
||||
// coalesce(null, 2, 3)
|
||||
EXPECT_EQ(Eval(COALESCE(LITERAL(TypedValue()), LITERAL(2), LITERAL(3)))
|
||||
.ValueInt(),
|
||||
2);
|
||||
EXPECT_EQ(
|
||||
Eval(COALESCE(LITERAL(TypedValue()), LITERAL(2), LITERAL(3))).ValueInt(),
|
||||
2);
|
||||
|
||||
// coalesce(null, 2, assert(false), 3)
|
||||
EXPECT_EQ(Eval(COALESCE(LITERAL(TypedValue()), LITERAL(2),
|
||||
@ -850,23 +847,23 @@ TEST_F(ExpressionEvaluatorTest, Coalesce) {
|
||||
QueryRuntimeException);
|
||||
|
||||
// coalesce([null, null])
|
||||
EXPECT_FALSE(Eval(COALESCE(LITERAL(TypedValue(std::vector<TypedValue>{
|
||||
TypedValue(), TypedValue()}))))
|
||||
EXPECT_FALSE(Eval(COALESCE(LITERAL(TypedValue(
|
||||
std::vector<TypedValue>{TypedValue(), TypedValue()}))))
|
||||
.IsNull());
|
||||
}
|
||||
|
||||
TEST_F(ExpressionEvaluatorTest, RegexMatchInvalidArguments) {
|
||||
EXPECT_TRUE(Eval(storage.Create<RegexMatch>(LITERAL(TypedValue()),
|
||||
LITERAL("regex")))
|
||||
.IsNull());
|
||||
EXPECT_TRUE(
|
||||
Eval(storage.Create<RegexMatch>(LITERAL(TypedValue()), LITERAL("regex")))
|
||||
.IsNull());
|
||||
EXPECT_TRUE(
|
||||
Eval(storage.Create<RegexMatch>(LITERAL(3), LITERAL("regex"))).IsNull());
|
||||
EXPECT_TRUE(Eval(storage.Create<RegexMatch>(LIST(LITERAL("string")),
|
||||
LITERAL("regex")))
|
||||
.IsNull());
|
||||
EXPECT_TRUE(Eval(storage.Create<RegexMatch>(LITERAL("string"),
|
||||
LITERAL(TypedValue())))
|
||||
.IsNull());
|
||||
EXPECT_TRUE(
|
||||
Eval(storage.Create<RegexMatch>(LITERAL("string"), LITERAL(TypedValue())))
|
||||
.IsNull());
|
||||
EXPECT_THROW(Eval(storage.Create<RegexMatch>(LITERAL("string"), LITERAL(42))),
|
||||
QueryRuntimeException);
|
||||
EXPECT_THROW(Eval(storage.Create<RegexMatch>(LITERAL("string"),
|
||||
@ -901,9 +898,9 @@ TEST_F(ExpressionEvaluatorTest, RegexMatch) {
|
||||
class ExpressionEvaluatorPropertyLookup : public ExpressionEvaluatorTest {
|
||||
protected:
|
||||
std::pair<std::string, storage::Property> prop_age =
|
||||
std::make_pair("age", dba.Property("age"));
|
||||
std::make_pair("age", dba.NameToProperty("age"));
|
||||
std::pair<std::string, storage::Property> prop_height =
|
||||
std::make_pair("height", dba.Property("height"));
|
||||
std::make_pair("height", dba.NameToProperty("height"));
|
||||
Identifier *identifier = storage.Create<Identifier>("element");
|
||||
Symbol symbol = symbol_table.CreateSymbol("element", true);
|
||||
|
||||
@ -918,8 +915,9 @@ class ExpressionEvaluatorPropertyLookup : public ExpressionEvaluatorTest {
|
||||
|
||||
TEST_F(ExpressionEvaluatorPropertyLookup, Vertex) {
|
||||
auto v1 = dba.InsertVertex();
|
||||
v1.PropsSet(prop_age.second, PropertyValue(10));
|
||||
frame[symbol] = TypedValue(query::VertexAccessor(v1));
|
||||
ASSERT_TRUE(v1.SetProperty(prop_age.second, PropertyValue(10)).HasValue());
|
||||
dba.AdvanceCommand();
|
||||
frame[symbol] = TypedValue(v1);
|
||||
EXPECT_EQ(Value(prop_age).ValueInt(), 10);
|
||||
EXPECT_TRUE(Value(prop_height).IsNull());
|
||||
}
|
||||
@ -927,9 +925,11 @@ TEST_F(ExpressionEvaluatorPropertyLookup, Vertex) {
|
||||
TEST_F(ExpressionEvaluatorPropertyLookup, Edge) {
|
||||
auto v1 = dba.InsertVertex();
|
||||
auto v2 = dba.InsertVertex();
|
||||
auto e12 = dba.InsertEdge(v1, v2, dba.EdgeType("edge_type"));
|
||||
e12.PropsSet(prop_age.second, PropertyValue(10));
|
||||
frame[symbol] = TypedValue(query::EdgeAccessor(e12));
|
||||
auto e12 = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("edge_type"));
|
||||
ASSERT_TRUE(e12.HasValue());
|
||||
ASSERT_TRUE(e12->SetProperty(prop_age.second, PropertyValue(10)).HasValue());
|
||||
dba.AdvanceCommand();
|
||||
frame[symbol] = TypedValue(*e12);
|
||||
EXPECT_EQ(Value(prop_age).ValueInt(), 10);
|
||||
EXPECT_TRUE(Value(prop_height).IsNull());
|
||||
}
|
||||
@ -1000,13 +1000,14 @@ TEST_F(FunctionTest, EndNode) {
|
||||
ASSERT_THROW(EvaluateFunction("ENDNODE"), QueryRuntimeException);
|
||||
ASSERT_TRUE(EvaluateFunction("ENDNODE", TypedValue()).IsNull());
|
||||
auto v1 = dba.InsertVertex();
|
||||
v1.add_label(dba.Label("label1"));
|
||||
ASSERT_TRUE(v1.AddLabel(dba.NameToLabel("label1")).HasValue());
|
||||
auto v2 = dba.InsertVertex();
|
||||
v2.add_label(dba.Label("label2"));
|
||||
query::EdgeAccessor e(dba.InsertEdge(v1, v2, dba.EdgeType("t")));
|
||||
ASSERT_TRUE(*EvaluateFunction("ENDNODE", e)
|
||||
ASSERT_TRUE(v2.AddLabel(dba.NameToLabel("label2")).HasValue());
|
||||
auto e = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("t"));
|
||||
ASSERT_TRUE(e.HasValue());
|
||||
ASSERT_TRUE(*EvaluateFunction("ENDNODE", *e)
|
||||
.ValueVertex()
|
||||
.HasLabel(storage::View::NEW, dba.Label("label2")));
|
||||
.HasLabel(storage::View::NEW, dba.NameToLabel("label2")));
|
||||
ASSERT_THROW(EvaluateFunction("ENDNODE", 2), QueryRuntimeException);
|
||||
}
|
||||
|
||||
@ -1024,12 +1025,18 @@ TEST_F(FunctionTest, Properties) {
|
||||
ASSERT_THROW(EvaluateFunction("PROPERTIES"), QueryRuntimeException);
|
||||
ASSERT_TRUE(EvaluateFunction("PROPERTIES", TypedValue()).IsNull());
|
||||
auto v1 = dba.InsertVertex();
|
||||
v1.PropsSet(dba.Property("height"), PropertyValue(5));
|
||||
v1.PropsSet(dba.Property("age"), PropertyValue(10));
|
||||
ASSERT_TRUE(v1.SetProperty(dba.NameToProperty("height"), PropertyValue(5))
|
||||
.HasValue());
|
||||
ASSERT_TRUE(
|
||||
v1.SetProperty(dba.NameToProperty("age"), PropertyValue(10)).HasValue());
|
||||
auto v2 = dba.InsertVertex();
|
||||
auto e = dba.InsertEdge(v1, v2, dba.EdgeType("type1"));
|
||||
e.PropsSet(dba.Property("height"), PropertyValue(3));
|
||||
e.PropsSet(dba.Property("age"), PropertyValue(15));
|
||||
auto e = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("type1"));
|
||||
ASSERT_TRUE(e.HasValue());
|
||||
ASSERT_TRUE(e->SetProperty(dba.NameToProperty("height"), PropertyValue(3))
|
||||
.HasValue());
|
||||
ASSERT_TRUE(
|
||||
e->SetProperty(dba.NameToProperty("age"), PropertyValue(15)).HasValue());
|
||||
dba.AdvanceCommand();
|
||||
|
||||
auto prop_values_to_int = [](TypedValue t) {
|
||||
std::unordered_map<std::string, int> properties;
|
||||
@ -1039,12 +1046,10 @@ TEST_F(FunctionTest, Properties) {
|
||||
return properties;
|
||||
};
|
||||
|
||||
ASSERT_THAT(prop_values_to_int(
|
||||
EvaluateFunction("PROPERTIES", query::VertexAccessor(v1))),
|
||||
ASSERT_THAT(prop_values_to_int(EvaluateFunction("PROPERTIES", v1)),
|
||||
UnorderedElementsAre(testing::Pair("height", 5),
|
||||
testing::Pair("age", 10)));
|
||||
ASSERT_THAT(prop_values_to_int(
|
||||
EvaluateFunction("PROPERTIES", query::EdgeAccessor(e))),
|
||||
ASSERT_THAT(prop_values_to_int(EvaluateFunction("PROPERTIES", *e)),
|
||||
UnorderedElementsAre(testing::Pair("height", 3),
|
||||
testing::Pair("age", 15)));
|
||||
ASSERT_THROW(EvaluateFunction("PROPERTIES", 2), QueryRuntimeException);
|
||||
@ -1075,12 +1080,13 @@ TEST_F(FunctionTest, Size) {
|
||||
3);
|
||||
ASSERT_THROW(EvaluateFunction("SIZE", 5), QueryRuntimeException);
|
||||
|
||||
query::VertexAccessor v0(dba.InsertVertex());
|
||||
auto v0 = dba.InsertVertex();
|
||||
query::Path path(v0);
|
||||
EXPECT_EQ(EvaluateFunction("SIZE", path).ValueInt(), 0);
|
||||
query::VertexAccessor v1(dba.InsertVertex());
|
||||
path.Expand(query::EdgeAccessor(
|
||||
dba.InsertEdge(v0.impl_, v1.impl_, dba.EdgeType("type"))));
|
||||
auto v1 = dba.InsertVertex();
|
||||
auto edge = dba.InsertEdge(&v0, &v1, dba.NameToEdgeType("type"));
|
||||
ASSERT_TRUE(edge.HasValue());
|
||||
path.Expand(*edge);
|
||||
path.Expand(v1);
|
||||
EXPECT_EQ(EvaluateFunction("SIZE", path).ValueInt(), 1);
|
||||
}
|
||||
@ -1089,13 +1095,14 @@ TEST_F(FunctionTest, StartNode) {
|
||||
ASSERT_THROW(EvaluateFunction("STARTNODE"), QueryRuntimeException);
|
||||
ASSERT_TRUE(EvaluateFunction("STARTNODE", TypedValue()).IsNull());
|
||||
auto v1 = dba.InsertVertex();
|
||||
v1.add_label(dba.Label("label1"));
|
||||
ASSERT_TRUE(v1.AddLabel(dba.NameToLabel("label1")).HasValue());
|
||||
auto v2 = dba.InsertVertex();
|
||||
v2.add_label(dba.Label("label2"));
|
||||
auto e = dba.InsertEdge(v1, v2, dba.EdgeType("t"));
|
||||
ASSERT_TRUE(*EvaluateFunction("STARTNODE", query::EdgeAccessor(e))
|
||||
ASSERT_TRUE(v2.AddLabel(dba.NameToLabel("label2")).HasValue());
|
||||
auto e = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("t"));
|
||||
ASSERT_TRUE(e.HasValue());
|
||||
ASSERT_TRUE(*EvaluateFunction("STARTNODE", *e)
|
||||
.ValueVertex()
|
||||
.HasLabel(storage::View::NEW, dba.Label("label1")));
|
||||
.HasLabel(storage::View::NEW, dba.NameToLabel("label1")));
|
||||
ASSERT_THROW(EvaluateFunction("STARTNODE", 2), QueryRuntimeException);
|
||||
}
|
||||
|
||||
@ -1105,48 +1112,49 @@ TEST_F(FunctionTest, Degree) {
|
||||
auto v1 = dba.InsertVertex();
|
||||
auto v2 = dba.InsertVertex();
|
||||
auto v3 = dba.InsertVertex();
|
||||
auto e12 = dba.InsertEdge(v1, v2, dba.EdgeType("t"));
|
||||
dba.InsertEdge(v3, v2, dba.EdgeType("t"));
|
||||
ASSERT_EQ(EvaluateFunction("DEGREE", query::VertexAccessor(v1)).ValueInt(),
|
||||
1);
|
||||
ASSERT_EQ(EvaluateFunction("DEGREE", query::VertexAccessor(v2)).ValueInt(),
|
||||
2);
|
||||
ASSERT_EQ(EvaluateFunction("DEGREE", query::VertexAccessor(v3)).ValueInt(),
|
||||
1);
|
||||
auto e12 = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("t"));
|
||||
ASSERT_TRUE(e12.HasValue());
|
||||
ASSERT_TRUE(dba.InsertEdge(&v3, &v2, dba.NameToEdgeType("t")).HasValue());
|
||||
dba.AdvanceCommand();
|
||||
ASSERT_EQ(EvaluateFunction("DEGREE", v1).ValueInt(), 1);
|
||||
ASSERT_EQ(EvaluateFunction("DEGREE", v2).ValueInt(), 2);
|
||||
ASSERT_EQ(EvaluateFunction("DEGREE", v3).ValueInt(), 1);
|
||||
ASSERT_THROW(EvaluateFunction("DEGREE", 2), QueryRuntimeException);
|
||||
ASSERT_THROW(EvaluateFunction("DEGREE", query::EdgeAccessor(e12)),
|
||||
QueryRuntimeException);
|
||||
ASSERT_THROW(EvaluateFunction("DEGREE", *e12), QueryRuntimeException);
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, InDegree) {
|
||||
ASSERT_THROW(EvaluateFunction("INDEGREE"), QueryRuntimeException);
|
||||
ASSERT_TRUE(EvaluateFunction("INDEGREE", TypedValue()).IsNull());
|
||||
query::VertexAccessor v1(dba.InsertVertex());
|
||||
query::VertexAccessor v2(dba.InsertVertex());
|
||||
query::VertexAccessor v3(dba.InsertVertex());
|
||||
query::EdgeAccessor e12(dba.InsertEdge(v1.impl_, v2.impl_, dba.EdgeType("t")));
|
||||
dba.InsertEdge(v3.impl_, v2.impl_, dba.EdgeType("t"));
|
||||
auto v1 = dba.InsertVertex();
|
||||
auto v2 = dba.InsertVertex();
|
||||
auto v3 = dba.InsertVertex();
|
||||
auto e12 = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("t"));
|
||||
ASSERT_TRUE(e12.HasValue());
|
||||
ASSERT_TRUE(dba.InsertEdge(&v3, &v2, dba.NameToEdgeType("t")).HasValue());
|
||||
dba.AdvanceCommand();
|
||||
ASSERT_EQ(EvaluateFunction("INDEGREE", v1).ValueInt(), 0);
|
||||
ASSERT_EQ(EvaluateFunction("INDEGREE", v2).ValueInt(), 2);
|
||||
ASSERT_EQ(EvaluateFunction("INDEGREE", v3).ValueInt(), 0);
|
||||
ASSERT_THROW(EvaluateFunction("INDEGREE", 2), QueryRuntimeException);
|
||||
ASSERT_THROW(EvaluateFunction("INDEGREE", e12), QueryRuntimeException);
|
||||
ASSERT_THROW(EvaluateFunction("INDEGREE", *e12), QueryRuntimeException);
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, OutDegree) {
|
||||
ASSERT_THROW(EvaluateFunction("OUTDEGREE"), QueryRuntimeException);
|
||||
ASSERT_TRUE(EvaluateFunction("OUTDEGREE", TypedValue()).IsNull());
|
||||
query::VertexAccessor v1(dba.InsertVertex());
|
||||
query::VertexAccessor v2(dba.InsertVertex());
|
||||
query::VertexAccessor v3(dba.InsertVertex());
|
||||
query::EdgeAccessor e12(
|
||||
dba.InsertEdge(v1.impl_, v2.impl_, dba.EdgeType("t")));
|
||||
dba.InsertEdge(v3.impl_, v2.impl_, dba.EdgeType("t"));
|
||||
auto v1 = dba.InsertVertex();
|
||||
auto v2 = dba.InsertVertex();
|
||||
auto v3 = dba.InsertVertex();
|
||||
auto e12 = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("t"));
|
||||
ASSERT_TRUE(e12.HasValue());
|
||||
ASSERT_TRUE(dba.InsertEdge(&v3, &v2, dba.NameToEdgeType("t")).HasValue());
|
||||
dba.AdvanceCommand();
|
||||
ASSERT_EQ(EvaluateFunction("OUTDEGREE", v1).ValueInt(), 1);
|
||||
ASSERT_EQ(EvaluateFunction("OUTDEGREE", v2).ValueInt(), 0);
|
||||
ASSERT_EQ(EvaluateFunction("OUTDEGREE", v3).ValueInt(), 1);
|
||||
ASSERT_THROW(EvaluateFunction("OUTDEGREE", 2), QueryRuntimeException);
|
||||
ASSERT_THROW(EvaluateFunction("OUTDEGREE", e12), QueryRuntimeException);
|
||||
ASSERT_THROW(EvaluateFunction("OUTDEGREE", *e12), QueryRuntimeException);
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, ToBoolean) {
|
||||
@ -1189,11 +1197,12 @@ TEST_F(FunctionTest, Type) {
|
||||
ASSERT_THROW(EvaluateFunction("TYPE"), QueryRuntimeException);
|
||||
ASSERT_TRUE(EvaluateFunction("TYPE", TypedValue()).IsNull());
|
||||
auto v1 = dba.InsertVertex();
|
||||
v1.add_label(dba.Label("label1"));
|
||||
ASSERT_TRUE(v1.AddLabel(dba.NameToLabel("label1")).HasValue());
|
||||
auto v2 = dba.InsertVertex();
|
||||
v2.add_label(dba.Label("label2"));
|
||||
query::EdgeAccessor e(dba.InsertEdge(v1, v2, dba.EdgeType("type1")));
|
||||
ASSERT_EQ(EvaluateFunction("TYPE", e).ValueString(), "type1");
|
||||
ASSERT_TRUE(v2.AddLabel(dba.NameToLabel("label2")).HasValue());
|
||||
auto e = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("type1"));
|
||||
ASSERT_TRUE(e.HasValue());
|
||||
ASSERT_EQ(EvaluateFunction("TYPE", *e).ValueString(), "type1");
|
||||
ASSERT_THROW(EvaluateFunction("TYPE", 2), QueryRuntimeException);
|
||||
}
|
||||
|
||||
@ -1201,11 +1210,11 @@ TEST_F(FunctionTest, Labels) {
|
||||
ASSERT_THROW(EvaluateFunction("LABELS"), QueryRuntimeException);
|
||||
ASSERT_TRUE(EvaluateFunction("LABELS", TypedValue()).IsNull());
|
||||
auto v = dba.InsertVertex();
|
||||
v.add_label(dba.Label("label1"));
|
||||
v.add_label(dba.Label("label2"));
|
||||
ASSERT_TRUE(v.AddLabel(dba.NameToLabel("label1")).HasValue());
|
||||
ASSERT_TRUE(v.AddLabel(dba.NameToLabel("label2")).HasValue());
|
||||
dba.AdvanceCommand();
|
||||
std::vector<std::string> labels;
|
||||
auto _labels =
|
||||
EvaluateFunction("LABELS", query::VertexAccessor(v)).ValueList();
|
||||
auto _labels = EvaluateFunction("LABELS", v).ValueList();
|
||||
labels.reserve(_labels.size());
|
||||
for (auto label : _labels) {
|
||||
labels.emplace_back(label.ValueString());
|
||||
@ -1224,25 +1233,26 @@ TEST_F(FunctionTest, NodesRelationships) {
|
||||
auto v1 = dba.InsertVertex();
|
||||
auto v2 = dba.InsertVertex();
|
||||
auto v3 = dba.InsertVertex();
|
||||
auto e1 = dba.InsertEdge(v1, v2, dba.EdgeType("Type"));
|
||||
auto e2 = dba.InsertEdge(v2, v3, dba.EdgeType("Type"));
|
||||
query::Path path{query::VertexAccessor(v1), query::EdgeAccessor(e1),
|
||||
query::VertexAccessor(v2), query::EdgeAccessor(e2),
|
||||
query::VertexAccessor(v3)};
|
||||
auto e1 = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("Type"));
|
||||
ASSERT_TRUE(e1.HasValue());
|
||||
auto e2 = dba.InsertEdge(&v2, &v3, dba.NameToEdgeType("Type"));
|
||||
ASSERT_TRUE(e2.HasValue());
|
||||
query::Path path{v1, *e1, v2, *e2, v3};
|
||||
dba.AdvanceCommand();
|
||||
|
||||
auto _nodes = EvaluateFunction("NODES", path).ValueList();
|
||||
std::vector<::VertexAccessor> nodes;
|
||||
std::vector<query::VertexAccessor> nodes;
|
||||
for (const auto &node : _nodes) {
|
||||
nodes.push_back(node.ValueVertex().impl_);
|
||||
nodes.push_back(node.ValueVertex());
|
||||
}
|
||||
EXPECT_THAT(nodes, ElementsAre(v1, v2, v3));
|
||||
|
||||
auto _edges = EvaluateFunction("RELATIONSHIPS", path).ValueList();
|
||||
std::vector<::EdgeAccessor> edges;
|
||||
std::vector<query::EdgeAccessor> edges;
|
||||
for (const auto &edge : _edges) {
|
||||
edges.push_back(edge.ValueEdge().impl_);
|
||||
edges.push_back(edge.ValueEdge());
|
||||
}
|
||||
EXPECT_THAT(edges, ElementsAre(e1, e2));
|
||||
EXPECT_THAT(edges, ElementsAre(*e1, *e2));
|
||||
}
|
||||
|
||||
EXPECT_THROW(EvaluateFunction("NODES", 2), QueryRuntimeException);
|
||||
@ -1274,12 +1284,18 @@ TEST_F(FunctionTest, Keys) {
|
||||
ASSERT_THROW(EvaluateFunction("KEYS"), QueryRuntimeException);
|
||||
ASSERT_TRUE(EvaluateFunction("KEYS", TypedValue()).IsNull());
|
||||
auto v1 = dba.InsertVertex();
|
||||
v1.PropsSet(dba.Property("height"), PropertyValue(5));
|
||||
v1.PropsSet(dba.Property("age"), PropertyValue(10));
|
||||
ASSERT_TRUE(v1.SetProperty(dba.NameToProperty("height"), PropertyValue(5))
|
||||
.HasValue());
|
||||
ASSERT_TRUE(
|
||||
v1.SetProperty(dba.NameToProperty("age"), PropertyValue(10)).HasValue());
|
||||
auto v2 = dba.InsertVertex();
|
||||
auto e = dba.InsertEdge(v1, v2, dba.EdgeType("type1"));
|
||||
e.PropsSet(dba.Property("width"), PropertyValue(3));
|
||||
e.PropsSet(dba.Property("age"), PropertyValue(15));
|
||||
auto e = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("type1"));
|
||||
ASSERT_TRUE(e.HasValue());
|
||||
ASSERT_TRUE(
|
||||
e->SetProperty(dba.NameToProperty("width"), PropertyValue(3)).HasValue());
|
||||
ASSERT_TRUE(
|
||||
e->SetProperty(dba.NameToProperty("age"), PropertyValue(15)).HasValue());
|
||||
dba.AdvanceCommand();
|
||||
|
||||
auto prop_keys_to_string = [](TypedValue t) {
|
||||
std::vector<std::string> keys;
|
||||
@ -1288,12 +1304,10 @@ TEST_F(FunctionTest, Keys) {
|
||||
}
|
||||
return keys;
|
||||
};
|
||||
ASSERT_THAT(
|
||||
prop_keys_to_string(EvaluateFunction("KEYS", query::VertexAccessor(v1))),
|
||||
UnorderedElementsAre("height", "age"));
|
||||
ASSERT_THAT(
|
||||
prop_keys_to_string(EvaluateFunction("KEYS", query::EdgeAccessor(e))),
|
||||
UnorderedElementsAre("width", "age"));
|
||||
ASSERT_THAT(prop_keys_to_string(EvaluateFunction("KEYS", v1)),
|
||||
UnorderedElementsAre("height", "age"));
|
||||
ASSERT_THAT(prop_keys_to_string(EvaluateFunction("KEYS", *e)),
|
||||
UnorderedElementsAre("width", "age"));
|
||||
ASSERT_THROW(EvaluateFunction("KEYS", 2), QueryRuntimeException);
|
||||
}
|
||||
|
||||
@ -1511,33 +1525,19 @@ TEST_F(FunctionTest, Counter) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, Id) {
|
||||
query::VertexAccessor va(dba.InsertVertex());
|
||||
query::EdgeAccessor ea(
|
||||
dba.InsertEdge(va.impl_, va.impl_, dba.EdgeType("edge")));
|
||||
query::VertexAccessor vb(dba.InsertVertex());
|
||||
auto va = dba.InsertVertex();
|
||||
auto ea = dba.InsertEdge(&va, &va, dba.NameToEdgeType("edge"));
|
||||
ASSERT_TRUE(ea.HasValue());
|
||||
auto vb = dba.InsertVertex();
|
||||
dba.AdvanceCommand();
|
||||
EXPECT_EQ(EvaluateFunction("ID", va).ValueInt(), 0);
|
||||
EXPECT_EQ(EvaluateFunction("ID", ea).ValueInt(), 0);
|
||||
EXPECT_EQ(EvaluateFunction("ID", *ea).ValueInt(), 0);
|
||||
EXPECT_EQ(EvaluateFunction("ID", vb).ValueInt(), 1);
|
||||
EXPECT_THROW(EvaluateFunction("ID"), QueryRuntimeException);
|
||||
EXPECT_THROW(EvaluateFunction("ID", 0), QueryRuntimeException);
|
||||
EXPECT_THROW(EvaluateFunction("ID", va, ea), QueryRuntimeException);
|
||||
EXPECT_THROW(EvaluateFunction("ID", va, *ea), QueryRuntimeException);
|
||||
}
|
||||
|
||||
/* TODO: FIXME
|
||||
TEST_F(FunctionTest, WorkerIdException) {
|
||||
auto va = dba.InsertVertex();
|
||||
EXPECT_THROW(EvaluateFunction("WORKERID"), QueryRuntimeException);
|
||||
EXPECT_THROW(EvaluateFunction("WORKERID", va, va), QueryRuntimeException);
|
||||
}
|
||||
*/
|
||||
|
||||
/* TODO: FIXME
|
||||
TEST_F(FunctionTest, WorkerIdSingleNode) {
|
||||
auto va = dba.InsertVertex();
|
||||
EXPECT_EQ(EvaluateFunction("WORKERID", va).ValueInt(), 0);
|
||||
}
|
||||
*/
|
||||
|
||||
TEST_F(FunctionTest, ToStringNull) {
|
||||
EXPECT_TRUE(EvaluateFunction("TOSTRING", TypedValue()).IsNull());
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "database/single_node/graph_db.hpp"
|
||||
#include "query/context.hpp"
|
||||
#include "query/exceptions.hpp"
|
||||
#include "query/plan/operator.hpp"
|
||||
@ -26,15 +25,16 @@ TEST(QueryPlan, Accumulate) {
|
||||
// with accumulation we expect them to be [[2, 2], [2, 2]]
|
||||
|
||||
auto check = [&](bool accumulate) {
|
||||
database::GraphDb db;
|
||||
auto dba = db.Access();
|
||||
auto prop = dba.Property("x");
|
||||
storage::Storage db;
|
||||
auto storage_dba = db.Access();
|
||||
query::DbAccessor dba(&storage_dba);
|
||||
auto prop = dba.NameToProperty("x");
|
||||
|
||||
auto v1 = dba.InsertVertex();
|
||||
v1.PropsSet(prop, PropertyValue(0));
|
||||
ASSERT_TRUE(v1.SetProperty(prop, PropertyValue(0)).HasValue());
|
||||
auto v2 = dba.InsertVertex();
|
||||
v2.PropsSet(prop, PropertyValue(0));
|
||||
dba.InsertEdge(v1, v2, dba.EdgeType("T"));
|
||||
ASSERT_TRUE(v2.SetProperty(prop, PropertyValue(0)).HasValue());
|
||||
ASSERT_TRUE(dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("T")).HasValue());
|
||||
dba.AdvanceCommand();
|
||||
|
||||
AstStorage storage;
|
||||
@ -64,8 +64,7 @@ TEST(QueryPlan, Accumulate) {
|
||||
auto m_p_ne =
|
||||
NEXPR("m.p", m_p)->MapTo(symbol_table.CreateSymbol("m_p_ne", true));
|
||||
auto produce = MakeProduce(last_op, n_p_ne, m_p_ne);
|
||||
query::DbAccessor execution_dba(&dba);
|
||||
auto context = MakeContext(storage, symbol_table, &execution_dba);
|
||||
auto context = MakeContext(storage, symbol_table, &dba);
|
||||
auto results = CollectProduce(*produce, &context);
|
||||
std::vector<int> results_data;
|
||||
for (const auto &row : results)
|
||||
@ -85,8 +84,9 @@ TEST(QueryPlan, AccumulateAdvance) {
|
||||
// we simulate 'CREATE (n) WITH n AS n MATCH (m) RETURN m'
|
||||
// to get correct results we need to advance the command
|
||||
auto check = [&](bool advance) {
|
||||
database::GraphDb db;
|
||||
auto dba = db.Access();
|
||||
storage::Storage db;
|
||||
auto storage_dba = db.Access();
|
||||
query::DbAccessor dba(&storage_dba);
|
||||
AstStorage storage;
|
||||
SymbolTable symbol_table;
|
||||
NodeCreationInfo node;
|
||||
@ -95,8 +95,7 @@ TEST(QueryPlan, AccumulateAdvance) {
|
||||
auto accumulate = std::make_shared<Accumulate>(
|
||||
create, std::vector<Symbol>{node.symbol}, advance);
|
||||
auto match = MakeScanAll(storage, symbol_table, "m", accumulate);
|
||||
query::DbAccessor execution_dba(&dba);
|
||||
auto context = MakeContext(storage, symbol_table, &execution_dba);
|
||||
auto context = MakeContext(storage, symbol_table, &dba);
|
||||
EXPECT_EQ(advance ? 1 : 0, PullAll(*match.op_, &context));
|
||||
};
|
||||
check(false);
|
||||
@ -145,9 +144,10 @@ std::shared_ptr<Produce> MakeAggregationProduce(
|
||||
/** Test fixture for all the aggregation ops in one return. */
|
||||
class QueryPlanAggregateOps : public ::testing::Test {
|
||||
protected:
|
||||
database::GraphDb db;
|
||||
database::GraphDbAccessor dba{db.Access()};
|
||||
storage::Property prop = dba.Property("prop");
|
||||
storage::Storage db;
|
||||
storage::Storage::Accessor storage_dba{db.Access()};
|
||||
query::DbAccessor dba{&storage_dba};
|
||||
storage::Property prop = db.NameToProperty("prop");
|
||||
|
||||
AstStorage storage;
|
||||
SymbolTable symbol_table;
|
||||
@ -156,9 +156,12 @@ class QueryPlanAggregateOps : public ::testing::Test {
|
||||
// setup is several nodes most of which have an int property set
|
||||
// we will take the sum, avg, min, max and count
|
||||
// we won't group by anything
|
||||
dba.InsertVertex().PropsSet(prop, PropertyValue(5));
|
||||
dba.InsertVertex().PropsSet(prop, PropertyValue(7));
|
||||
dba.InsertVertex().PropsSet(prop, PropertyValue(12));
|
||||
ASSERT_TRUE(
|
||||
dba.InsertVertex().SetProperty(prop, PropertyValue(5)).HasValue());
|
||||
ASSERT_TRUE(
|
||||
dba.InsertVertex().SetProperty(prop, PropertyValue(7)).HasValue());
|
||||
ASSERT_TRUE(
|
||||
dba.InsertVertex().SetProperty(prop, PropertyValue(12)).HasValue());
|
||||
// a missing property (null) gets ignored by all aggregations except
|
||||
// COUNT(*)
|
||||
dba.InsertVertex();
|
||||
@ -183,8 +186,7 @@ class QueryPlanAggregateOps : public ::testing::Test {
|
||||
auto produce =
|
||||
MakeAggregationProduce(n.op_, symbol_table, storage,
|
||||
aggregation_expressions, ops, group_bys, {});
|
||||
query::DbAccessor execution_dba(&dba);
|
||||
auto context = MakeContext(storage, symbol_table, &execution_dba);
|
||||
auto context = MakeContext(storage, symbol_table, &dba);
|
||||
return CollectProduce(*produce, &context);
|
||||
}
|
||||
};
|
||||
@ -285,8 +287,9 @@ TEST(QueryPlan, AggregateGroupByValues) {
|
||||
// Tests that distinct groups are aggregated properly for values of all types.
|
||||
// Also test the "remember" part of the Aggregation API as final results are
|
||||
// obtained via a property lookup of a remembered node.
|
||||
database::GraphDb db;
|
||||
auto dba = db.Access();
|
||||
storage::Storage db;
|
||||
auto storage_dba = db.Access();
|
||||
query::DbAccessor dba(&storage_dba);
|
||||
|
||||
// a vector of PropertyValue to be set as property values on vertices
|
||||
// most of them should result in a distinct group (commented where not)
|
||||
@ -313,9 +316,11 @@ TEST(QueryPlan, AggregateGroupByValues) {
|
||||
std::vector<PropertyValue>{PropertyValue(1), PropertyValue(2.0)});
|
||||
|
||||
// generate a lot of vertices and set props on them
|
||||
auto prop = dba.Property("prop");
|
||||
auto prop = dba.NameToProperty("prop");
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
dba.InsertVertex().PropsSet(prop, group_by_vals[i % group_by_vals.size()]);
|
||||
ASSERT_TRUE(dba.InsertVertex()
|
||||
.SetProperty(prop, group_by_vals[i % group_by_vals.size()])
|
||||
.HasValue());
|
||||
dba.AdvanceCommand();
|
||||
|
||||
AstStorage storage;
|
||||
@ -329,8 +334,7 @@ TEST(QueryPlan, AggregateGroupByValues) {
|
||||
MakeAggregationProduce(n.op_, symbol_table, storage, {n_p},
|
||||
{Aggregation::Op::COUNT}, {n_p}, {n.sym_});
|
||||
|
||||
query::DbAccessor execution_dba(&dba);
|
||||
auto context = MakeContext(storage, symbol_table, &execution_dba);
|
||||
auto context = MakeContext(storage, symbol_table, &dba);
|
||||
auto results = CollectProduce(*produce, &context);
|
||||
ASSERT_EQ(results.size(), group_by_vals.size() - 2);
|
||||
std::unordered_set<TypedValue, TypedValue::Hash, TypedValue::BoolEqual>
|
||||
@ -352,17 +356,21 @@ TEST(QueryPlan, AggregateMultipleGroupBy) {
|
||||
// in this test we have 3 different properties that have different values
|
||||
// for different records and assert that we get the correct combination
|
||||
// of values in our groups
|
||||
database::GraphDb db;
|
||||
auto dba = db.Access();
|
||||
storage::Storage db;
|
||||
auto storage_dba = db.Access();
|
||||
query::DbAccessor dba(&storage_dba);
|
||||
|
||||
auto prop1 = dba.Property("prop1");
|
||||
auto prop2 = dba.Property("prop2");
|
||||
auto prop3 = dba.Property("prop3");
|
||||
auto prop1 = dba.NameToProperty("prop1");
|
||||
auto prop2 = dba.NameToProperty("prop2");
|
||||
auto prop3 = dba.NameToProperty("prop3");
|
||||
for (int i = 0; i < 2 * 3 * 5; ++i) {
|
||||
auto v = dba.InsertVertex();
|
||||
v.PropsSet(prop1, PropertyValue(static_cast<bool>(i % 2)));
|
||||
v.PropsSet(prop2, PropertyValue(i % 3));
|
||||
v.PropsSet(prop3, PropertyValue("value" + std::to_string(i % 5)));
|
||||
ASSERT_TRUE(v.SetProperty(prop1, PropertyValue(static_cast<bool>(i % 2)))
|
||||
.HasValue());
|
||||
ASSERT_TRUE(v.SetProperty(prop2, PropertyValue(i % 3)).HasValue());
|
||||
ASSERT_TRUE(
|
||||
v.SetProperty(prop3, PropertyValue("value" + std::to_string(i % 5)))
|
||||
.HasValue());
|
||||
}
|
||||
dba.AdvanceCommand();
|
||||
|
||||
@ -379,23 +387,22 @@ TEST(QueryPlan, AggregateMultipleGroupBy) {
|
||||
{Aggregation::Op::COUNT},
|
||||
{n_p1, n_p2, n_p3}, {n.sym_});
|
||||
|
||||
query::DbAccessor execution_dba(&dba);
|
||||
auto context = MakeContext(storage, symbol_table, &execution_dba);
|
||||
auto context = MakeContext(storage, symbol_table, &dba);
|
||||
auto results = CollectProduce(*produce, &context);
|
||||
EXPECT_EQ(results.size(), 2 * 3 * 5);
|
||||
}
|
||||
|
||||
TEST(QueryPlan, AggregateNoInput) {
|
||||
database::GraphDb db;
|
||||
auto dba = db.Access();
|
||||
storage::Storage db;
|
||||
auto storage_dba = db.Access();
|
||||
query::DbAccessor dba(&storage_dba);
|
||||
AstStorage storage;
|
||||
SymbolTable symbol_table;
|
||||
|
||||
auto two = LITERAL(2);
|
||||
auto produce = MakeAggregationProduce(nullptr, symbol_table, storage, {two},
|
||||
{Aggregation::Op::COUNT}, {}, {});
|
||||
query::DbAccessor execution_dba(&dba);
|
||||
auto context = MakeContext(storage, symbol_table, &execution_dba);
|
||||
auto context = MakeContext(storage, symbol_table, &dba);
|
||||
auto results = CollectProduce(*produce, &context);
|
||||
EXPECT_EQ(1, results.size());
|
||||
EXPECT_EQ(1, results[0].size());
|
||||
@ -412,9 +419,10 @@ TEST(QueryPlan, AggregateCountEdgeCases) {
|
||||
// - 2 vertices in database, property set on one
|
||||
// - 2 vertices in database, property set on both
|
||||
|
||||
database::GraphDb db;
|
||||
auto dba = db.Access();
|
||||
auto prop = dba.Property("prop");
|
||||
storage::Storage db;
|
||||
auto storage_dba = db.Access();
|
||||
query::DbAccessor dba(&storage_dba);
|
||||
auto prop = dba.NameToProperty("prop");
|
||||
|
||||
AstStorage storage;
|
||||
SymbolTable symbol_table;
|
||||
@ -427,8 +435,7 @@ TEST(QueryPlan, AggregateCountEdgeCases) {
|
||||
auto count = [&]() {
|
||||
auto produce = MakeAggregationProduce(n.op_, symbol_table, storage, {n_p},
|
||||
{Aggregation::Op::COUNT}, {}, {});
|
||||
query::DbAccessor execution_dba(&dba);
|
||||
auto context = MakeContext(storage, symbol_table, &execution_dba);
|
||||
auto context = MakeContext(storage, symbol_table, &dba);
|
||||
auto results = CollectProduce(*produce, &context);
|
||||
if (results.size() == 0) return -1L;
|
||||
EXPECT_EQ(1, results.size());
|
||||
@ -446,7 +453,8 @@ TEST(QueryPlan, AggregateCountEdgeCases) {
|
||||
EXPECT_EQ(0, count());
|
||||
|
||||
// one vertex, property set
|
||||
for (auto va : dba.Vertices(false)) va.PropsSet(prop, PropertyValue(42));
|
||||
for (auto va : dba.Vertices(storage::View::OLD))
|
||||
ASSERT_TRUE(va.SetProperty(prop, PropertyValue(42)).HasValue());
|
||||
dba.AdvanceCommand();
|
||||
EXPECT_EQ(1, count());
|
||||
|
||||
@ -456,7 +464,8 @@ TEST(QueryPlan, AggregateCountEdgeCases) {
|
||||
EXPECT_EQ(1, count());
|
||||
|
||||
// two vertices, both with property set
|
||||
for (auto va : dba.Vertices(false)) va.PropsSet(prop, PropertyValue(42));
|
||||
for (auto va : dba.Vertices(storage::View::OLD))
|
||||
ASSERT_TRUE(va.SetProperty(prop, PropertyValue(42)).HasValue());
|
||||
dba.AdvanceCommand();
|
||||
EXPECT_EQ(2, count());
|
||||
}
|
||||
@ -465,14 +474,15 @@ TEST(QueryPlan, AggregateFirstValueTypes) {
|
||||
// testing exceptions that get emitted by the first-value
|
||||
// type check
|
||||
|
||||
database::GraphDb db;
|
||||
auto dba = db.Access();
|
||||
storage::Storage db;
|
||||
auto storage_dba = db.Access();
|
||||
query::DbAccessor dba(&storage_dba);
|
||||
|
||||
auto v1 = dba.InsertVertex();
|
||||
auto prop_string = dba.Property("string");
|
||||
v1.PropsSet(prop_string, PropertyValue("johhny"));
|
||||
auto prop_int = dba.Property("int");
|
||||
v1.PropsSet(prop_int, PropertyValue(12));
|
||||
auto prop_string = dba.NameToProperty("string");
|
||||
ASSERT_TRUE(v1.SetProperty(prop_string, PropertyValue("johhny")).HasValue());
|
||||
auto prop_int = dba.NameToProperty("int");
|
||||
ASSERT_TRUE(v1.SetProperty(prop_int, PropertyValue(12)).HasValue());
|
||||
dba.AdvanceCommand();
|
||||
|
||||
AstStorage storage;
|
||||
@ -486,8 +496,7 @@ TEST(QueryPlan, AggregateFirstValueTypes) {
|
||||
auto aggregate = [&](Expression *expression, Aggregation::Op aggr_op) {
|
||||
auto produce = MakeAggregationProduce(n.op_, symbol_table, storage,
|
||||
{expression}, {aggr_op}, {}, {});
|
||||
query::DbAccessor execution_dba(&dba);
|
||||
auto context = MakeContext(storage, symbol_table, &execution_dba);
|
||||
auto context = MakeContext(storage, symbol_table, &dba);
|
||||
CollectProduce(*produce, &context);
|
||||
};
|
||||
|
||||
@ -522,15 +531,19 @@ TEST(QueryPlan, AggregateTypes) {
|
||||
// does not check all combinations that can result in an exception
|
||||
// (that logic is defined and tested by TypedValue)
|
||||
|
||||
database::GraphDb db;
|
||||
auto dba = db.Access();
|
||||
storage::Storage db;
|
||||
auto storage_dba = db.Access();
|
||||
query::DbAccessor dba(&storage_dba);
|
||||
|
||||
auto p1 = dba.Property("p1"); // has only string props
|
||||
dba.InsertVertex().PropsSet(p1, PropertyValue("string"));
|
||||
dba.InsertVertex().PropsSet(p1, PropertyValue("str2"));
|
||||
auto p2 = dba.Property("p2"); // combines int and bool
|
||||
dba.InsertVertex().PropsSet(p2, PropertyValue(42));
|
||||
dba.InsertVertex().PropsSet(p2, PropertyValue(true));
|
||||
auto p1 = dba.NameToProperty("p1"); // has only string props
|
||||
ASSERT_TRUE(
|
||||
dba.InsertVertex().SetProperty(p1, PropertyValue("string")).HasValue());
|
||||
ASSERT_TRUE(
|
||||
dba.InsertVertex().SetProperty(p1, PropertyValue("str2")).HasValue());
|
||||
auto p2 = dba.NameToProperty("p2"); // combines int and bool
|
||||
ASSERT_TRUE(dba.InsertVertex().SetProperty(p2, PropertyValue(42)).HasValue());
|
||||
ASSERT_TRUE(
|
||||
dba.InsertVertex().SetProperty(p2, PropertyValue(true)).HasValue());
|
||||
dba.AdvanceCommand();
|
||||
|
||||
AstStorage storage;
|
||||
@ -543,8 +556,7 @@ TEST(QueryPlan, AggregateTypes) {
|
||||
auto aggregate = [&](Expression *expression, Aggregation::Op aggr_op) {
|
||||
auto produce = MakeAggregationProduce(n.op_, symbol_table, storage,
|
||||
{expression}, {aggr_op}, {}, {});
|
||||
query::DbAccessor execution_dba(&dba);
|
||||
auto context = MakeContext(storage, symbol_table, &execution_dba);
|
||||
auto context = MakeContext(storage, symbol_table, &dba);
|
||||
CollectProduce(*produce, &context);
|
||||
};
|
||||
|
||||
@ -578,8 +590,9 @@ TEST(QueryPlan, AggregateTypes) {
|
||||
}
|
||||
|
||||
TEST(QueryPlan, Unwind) {
|
||||
database::GraphDb db;
|
||||
auto dba = db.Access();
|
||||
storage::Storage db;
|
||||
auto storage_dba = db.Access();
|
||||
query::DbAccessor dba(&storage_dba);
|
||||
AstStorage storage;
|
||||
SymbolTable symbol_table;
|
||||
|
||||
@ -602,8 +615,7 @@ TEST(QueryPlan, Unwind) {
|
||||
->MapTo(symbol_table.CreateSymbol("y_ne", true));
|
||||
auto produce = MakeProduce(unwind_1, x_ne, y_ne);
|
||||
|
||||
query::DbAccessor execution_dba(&dba);
|
||||
auto context = MakeContext(storage, symbol_table, &execution_dba);
|
||||
auto context = MakeContext(storage, symbol_table, &dba);
|
||||
auto results = CollectProduce(*produce, &context);
|
||||
ASSERT_EQ(4, results.size());
|
||||
const std::vector<int> expected_x_card{3, 3, 3, 1};
|
||||
|
@ -6,15 +6,11 @@
|
||||
|
||||
#include "query/common.hpp"
|
||||
#include "query/context.hpp"
|
||||
#include "query/db_accessor.hpp"
|
||||
#include "query/frontend/semantic/symbol_table.hpp"
|
||||
#include "query/interpret/frame.hpp"
|
||||
#include "query/plan/operator.hpp"
|
||||
|
||||
// TODO (mferencevic): Remove once all cpp tests are migrated to v2.
|
||||
#ifdef MG_SINGLE_NODE_V2
|
||||
#include "query/db_accessor.hpp"
|
||||
#include "storage/v2/storage.hpp"
|
||||
#endif
|
||||
|
||||
#include "query_common.hpp"
|
||||
|
||||
@ -202,7 +198,6 @@ UnwindTuple MakeUnwind(SymbolTable &symbol_table,
|
||||
return UnwindTuple{sym, op};
|
||||
}
|
||||
|
||||
#ifdef MG_SINGLE_NODE_V2
|
||||
template <typename TIterable>
|
||||
auto CountIterable(TIterable &&iterable) {
|
||||
uint64_t count = 0;
|
||||
@ -221,9 +216,3 @@ inline uint64_t CountEdges(query::DbAccessor *dba, storage::View view) {
|
||||
}
|
||||
return count;
|
||||
}
|
||||
#else
|
||||
template <typename TIterable>
|
||||
auto CountIterable(TIterable iterable) {
|
||||
return std::distance(iterable.begin(), iterable.end());
|
||||
}
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user