dressipi sprint 1 work in progress, labels function support, delete all

This commit is contained in:
Marko Budiselic 2016-10-11 02:43:41 +02:00
parent f5cf9c72d2
commit 51b17c2402
21 changed files with 115 additions and 48 deletions

2
.gitignore vendored
View File

@ -20,4 +20,4 @@ release/memgraph_*
release/libs/
release/barrier/
release/barrier_*
build/compiled/

1
build/.gitignore vendored
View File

@ -1,3 +1,2 @@
/*
!.gitignore
!/compiled

View File

@ -17,5 +17,6 @@ enum class ClauseAction : uint32_t
ReturnRelationship,
ReturnPack,
ReturnProjection,
ReturnCount
ReturnCount,
ReturnLabels
};

View File

@ -1,5 +1,7 @@
#pragma once
// TODO: refactor build state machine instead of ifs
#include "query_engine/code_generator/handlers/create.hpp"
#include "query_engine/code_generator/handlers/delete.hpp"
#include "query_engine/code_generator/handlers/match.hpp"

View File

@ -11,7 +11,7 @@ auto delete_query_action =
for (auto const &kv : action_data.actions) {
auto entity = kv.first;
if (kv.second == ClauseAction::DeleteNode) {
code += code_line("// DELETE Node({})", entity);
code += code_line(detach_delete_all_nodes);
}
if (kv.second == ClauseAction::DeleteRelationship) {
code += code_line("// DELETE Relationship({})", entity);

View File

@ -80,6 +80,10 @@ auto return_query_action =
code += code_line(code::count, name);
}
}
if (kv.second == ClauseAction::ReturnLabels)
{
// TODO: similar to above
}
}
return code;

View File

@ -126,3 +126,8 @@ const std::string print_properties =
const std::string print_property =
"cout_property(\"{0}\", {0}.property(\"{1}\"));";
}
// DELETE
const std::string detach_delete_all_nodes =
"t.vertex_access().fill().isolated().for_all("
" [&](auto a) {{ a.remove(); }});";

View File

@ -38,6 +38,7 @@ struct Rem;
// functions
struct CountFunction;
struct LabelsFunction;
struct RelationshipSpecs;
struct RelationshipTypeList;
@ -86,7 +87,7 @@ struct AstVisitor
PatternList, Match, ReadQuery, Start, Where, WriteQuery, Create,
Return, Distinct, Delete, DeleteQuery, UpdateQuery, Set, SetKey,
ReadWriteQuery, IdentifierList, WithList, WithClause, WithQuery, Long,
CountFunction,
CountFunction, LabelsFunction,
InternalIdExpr, SetValue, SetElement, SetList>
{
};

View File

@ -11,4 +11,12 @@ struct CountFunction : public FunctionExpr<std::string, CountFunction>
{
}
};
struct LabelsFunction : public FunctionExpr<std::string, LabelsFunction>
{
LabelsFunction(const std::string &argument) : FunctionExpr("labels", argument)
{
}
};
}

View File

@ -501,6 +501,10 @@ function_expr(E) ::= COUNT LP IDN(A) RP. {
E = ast->create<ast::CountFunction>(A->value);
}
function_expr(E) ::= LABELS LP IDN(A) RP. {
E = ast->create<ast::LabelsFunction>(A->value);
}
%type expr {ast::Expr*}
expr(E) ::= value_expr(V). {

View File

@ -300,6 +300,12 @@ public:
entry << count.name << "(" << count.argument << ")";
}
void visit(ast::LabelsFunction& labels) override
{
auto entry = printer.advance("Labels ");
entry << labels.name << "(" << labels.argument << ")";
}
void visit(ast::PropertyList& prop_list) override
{
auto entry = printer.advance("Property List");

View File

@ -60,6 +60,7 @@ public:
// functions
rule("(?i:COUNT)", TK_COUNT);
rule("(?i:LABELS)", TK_LABELS);
// string literal TODO single quote escape
rule("'(.*?)'", TK_STR);

View File

@ -158,6 +158,10 @@ public:
{
}
void visit(ast::LabelsFunction& labels) override
{
}
void visit(ast::PropertyList& prop_list) override
{
accept(prop_list.value);

View File

@ -1,35 +0,0 @@
import time
from neo4j.v1 import GraphDatabase, basic_auth, types
from concurrent.futures import ProcessPoolExecutor
# create session
driver = GraphDatabase.driver("bolt://localhost",
auth=basic_auth("neo4j", "neo4j"),
encrypted=0)
session = driver.session()
queries_no = 10
queries = ["CREATE (n {prop: 10}) RETURN n"] * queries_no
def create_query(index):
'''
Task (process or thread)
Runs create query agains the database.
:param index: int -> number of task
:returns: (int, float) -> (task index, elapsed time)
'''
start = time.time()
for query in queries:
for record in session.run(query):
pass
end = time.time()
return time
with ProcessPoolExecutor(processes=4) as executor:
results = []
print(results)
# print(1.0 * queries_no / (end - start))

View File

@ -1,27 +1,30 @@
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <chrono>
#include <future>
#include <iostream>
#include <random>
#include <thread>
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "data_structures/bitset/dynamic_bitset.hpp"
#include "data_structures/concurrent/concurrent_list.hpp"
#include "data_structures/concurrent/concurrent_map.hpp"
#include "data_structures/concurrent/concurrent_multimap.hpp"
#include "data_structures/concurrent/concurrent_multiset.hpp"
#include "data_structures/concurrent/concurrent_set.hpp"
#include "data_structures/concurrent/skiplist.hpp"
#include "data_structures/concurrent/concurrent_list.hpp"
#include "data_structures/static_array.hpp"
#include "utils/assert.hpp"
#include "logging/default.hpp"
#include "logging/streams/stdout.hpp"
#include "utils/assert.hpp"
#include "utils/sysinfo/memory.hpp"
// NOTE: this file is highly coupled to data_structures
// TODO: REFACTOR
// Sets max number of threads that will be used in concurrent tests.
constexpr int max_no_threads=8;
constexpr int max_no_threads = 8;
using std::cout;
using std::endl;
@ -300,8 +303,9 @@ void memory_check(size_t no_threads, std::function<void()> f)
permanent_assert(leaked <= 0, "Memory leak check");
}
//Initializes loging faccilityes
void init_log(){
// Initializes loging faccilityes
void init_log()
{
logging::init_async();
logging::log->pipe(std::make_unique<Stdout>());
}

View File

@ -0,0 +1,59 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from neo4j.v1 import GraphDatabase, basic_auth, types
# initialize driver and create session
# default username and password are used
driver = GraphDatabase.driver("bolt://localhost",
auth=basic_auth("neo4j", "neo4j"),
encrypted=0)
session = driver.session()
# all test queries and expected results
# one element in queries is called test entry
# it contains test query +
# touple(number of expected results, expected properties)
# TODO: create custom data structures
queries = [
("CREATE (n:Garment {garment_id: 1234, garment_category_id: 1}) RETURN n",
(1, [{"garment_id": 1234, "garment_category_id": 1}])),
("CREATE(p:Profile {profile_id: 111, partner_id: 55}) RETURN p",
(1, [{"profile_id": 111, "partner_id": 55}])),
# ("MATCH (p:Profile) RETURN p",
# (1, [{"profile_id": 111, "partner_id": 55}])),
("MATCH (n) DELETE n",
(0, []))
];
# iterate through all queries and execute them agains the database
for query, result in queries:
# extract count and properties from test entries
count, test_properties = result
records = [record for record in session.run(query)]
# check count
assert len(records) == count, \
"Number of results for %s isn't good;" \
" expected: %s, got %s" % (query, count, len(records))
# in case that result should contain just one result
# test properties
# TODO: test others
if count == 1:
# extract properties from record
record = records[0]
record_name, = record
received_properties = {key: value
for (key, value) in record[record_name].items()}
# get expected properties
expected_properties = test_properties[0]
# check properties
assert expected_properties == received_properties, \
"Received properties for %s are not good; expected: %s, " \
"got %s" % (query, expected_properties, received_properties)
print("Dressipi integration test passed OK")

View File

@ -0,0 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import crud