work on cypher compiler, only cypher query example files were added
This commit is contained in:
parent
df08750a43
commit
2998527462
@ -25,4 +25,14 @@ public:
|
||||
{
|
||||
return res.send("GET /db/data/relationship");
|
||||
}
|
||||
|
||||
void put(sp::Request& req, sp::Response& res)
|
||||
{
|
||||
return res.send("PUT /db/data/relationship");
|
||||
}
|
||||
|
||||
void del(sp::Request& req, sp::Response& res)
|
||||
{
|
||||
return res.send("DELETE /db/data/relationship");
|
||||
}
|
||||
};
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "debug/tree_print.hpp"
|
||||
#include "codegen/cppgen.hpp"
|
||||
#include "utils/command_line/arguments.hpp"
|
||||
#include "utils/string/filereader.hpp"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
@ -18,15 +19,28 @@ using std::endl;
|
||||
// * INPUT ARGUMENTS *
|
||||
// -q -> query
|
||||
// -v -> visitor
|
||||
// -f -> file
|
||||
|
||||
std::string extract_query(const vector_str& arguments)
|
||||
{
|
||||
if (contain_argument(arguments, "-q"))
|
||||
return get_argument(arguments, "-q", "CREATE (n {a:1, b:2}) RETURN n");
|
||||
auto default_file = "query/read/match/match-where.cypher";
|
||||
auto file = get_argument(arguments, "-f", default_file);
|
||||
// TODO: error handling
|
||||
return read_file(file.c_str());
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// arguments parsing
|
||||
auto arguments = all_arguments(argc, argv);
|
||||
auto cypher_query = get_argument(arguments, "-q", "CREATE (n {name: 'Domko', age: 24}) return n");
|
||||
auto traverser = get_argument(arguments, "-t", "code");
|
||||
|
||||
// query extraction
|
||||
auto cypher_query = extract_query(arguments);
|
||||
|
||||
// traversers
|
||||
auto traverser = get_argument(arguments, "-t", "code");
|
||||
auto print_traverser = Traverser::sptr(new PrintVisitor(cout));
|
||||
auto cppgen_traverser = Traverser::sptr(new CppGen());
|
||||
std::map<std::string, Traverser::sptr> traversers = {
|
||||
|
1
cypher/query/read/match/match-n-m.cypher
Normal file
1
cypher/query/read/match/match-n-m.cypher
Normal file
@ -0,0 +1 @@
|
||||
MATCH (n)-->(m)
|
1
cypher/query/read/match/match-optional.cypher
Normal file
1
cypher/query/read/match/match-optional.cypher
Normal file
@ -0,0 +1 @@
|
||||
OPTIONAL MATCH (n)-[r]->(m)
|
1
cypher/query/read/match/match-path.cypher
Normal file
1
cypher/query/read/match/match-path.cypher
Normal file
@ -0,0 +1 @@
|
||||
MATCH p = (n)-->(m)
|
1
cypher/query/read/match/match-property.cypher
Normal file
1
cypher/query/read/match/match-property.cypher
Normal file
@ -0,0 +1 @@
|
||||
MATCH (n {name:'Alice'})-->(m)
|
1
cypher/query/read/match/match-where.cypher
Normal file
1
cypher/query/read/match/match-where.cypher
Normal file
@ -0,0 +1 @@
|
||||
MATCH (n:Person)-[:KNOWS]->(m:Person) WHERE n.name="Alice"
|
1
cypher/query/read/where/where.cypher
Normal file
1
cypher/query/read/where/where.cypher
Normal file
@ -0,0 +1 @@
|
||||
WHERE n.property <> {value}
|
@ -0,0 +1 @@
|
||||
MATCH (user)-[:FRIEND]-(friend) WITH user, count(friend) AS friends ORDER BY friends DESC SKIP 1 LIMIT 3 RETURN user
|
1
cypher/query/read/with/match-with-where.cypher
Normal file
1
cypher/query/read/with/match-with-where.cypher
Normal file
@ -0,0 +1 @@
|
||||
MATCH (user)-[:FRIEND]-(friend) WHERE user.name = {name} WITH user, count(friend) AS friends WHERE friends > 10 RETURN user
|
1
cypher/query/write/create-return.cypher
Normal file
1
cypher/query/write/create-return.cypher
Normal file
@ -0,0 +1 @@
|
||||
CREATE (n {name: 'Domko', age: 24}) RETURN n
|
1
cypher/query/write/create.cypher
Normal file
1
cypher/query/write/create.cypher
Normal file
@ -0,0 +1 @@
|
||||
CREATE (n {name: {value}})
|
@ -223,18 +223,15 @@ private:
|
||||
if(!record)
|
||||
return false;
|
||||
|
||||
// TODO-buda: what is this?
|
||||
lock_and_validate(record, t);
|
||||
return remove(record, t), true;
|
||||
}
|
||||
|
||||
// TODO-buda: this whole part is questionable
|
||||
bool remove(T* record, tx::Transaction& t)
|
||||
{
|
||||
assert(record != nullptr);
|
||||
lock_and_validate(record, t);
|
||||
record->mark_deleted(t);
|
||||
// TODO-buda: is this ok, at least for now?
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "model/properties/jsonwriter.hpp"
|
||||
#include "model/edge_model.hpp"
|
||||
#include "mvcc/record.hpp"
|
||||
|
||||
class Edge;
|
||||
#include "model/edge_model.hpp"
|
||||
#include "model/properties/jsonwriter.hpp"
|
||||
|
||||
class Edge : public mvcc::Record<Edge>
|
||||
{
|
||||
public:
|
||||
class Accessor;
|
||||
|
||||
Edge() = default;
|
||||
Edge(const EdgeModel& data) : data(data) {}
|
||||
Edge(EdgeModel&& data) : data(std::move(data)) {}
|
||||
|
12
storage/edge_accessor.hpp
Normal file
12
storage/edge_accessor.hpp
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/edge.hpp"
|
||||
#include "storage/record_accessor.hpp"
|
||||
|
||||
class Edges;
|
||||
|
||||
class Edge::Accessor : public RecordAccessor<Edge, Edges, Edge::Accessor>
|
||||
{
|
||||
public:
|
||||
using RecordAccessor::RecordAccessor;
|
||||
};
|
@ -1,12 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "edge.hpp"
|
||||
#include "common.hpp"
|
||||
#include "edge_accessor.hpp"
|
||||
|
||||
class Edges
|
||||
{
|
||||
public:
|
||||
// TODO: implementation
|
||||
Edge::Accessor find(tx::Transaction& t, const Id& id)
|
||||
{
|
||||
throw std::runtime_error("not implemented");
|
||||
}
|
||||
|
||||
Edge::Accessor insert(tx::Transaction& t)
|
||||
{
|
||||
throw std::runtime_error("not implemented");
|
||||
}
|
||||
|
||||
private:
|
||||
SkipList<uint64_t, EdgeRecord> edges;
|
||||
|
@ -20,15 +20,23 @@ decltype(auto) all_arguments(int argc, char *argv[])
|
||||
return args;
|
||||
}
|
||||
|
||||
bool contain_argument(const vector_str& all, const string& flag)
|
||||
{
|
||||
// TODO: optimize this implementation
|
||||
auto it = std::find(all.begin(), all.end(), flag);
|
||||
if (it == all.end())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
decltype(auto) get_argument(const vector_str& all,
|
||||
const std::string& flag,
|
||||
const std::string& default_value)
|
||||
{
|
||||
// TODO: optimize this implementation
|
||||
auto it = std::find(all.begin(), all.end(), flag);
|
||||
if (it == all.end()) {
|
||||
if (it == all.end())
|
||||
return default_value;
|
||||
}
|
||||
auto pos = std::distance(all.begin(), it);
|
||||
return all[pos + 1];
|
||||
}
|
||||
|
15
utils/string/filereader.hpp
Normal file
15
utils/string/filereader.hpp
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <streambuf>
|
||||
#include <string>
|
||||
#include <cerrno>
|
||||
|
||||
std::string read_file(const char *filename)
|
||||
{
|
||||
std::ifstream in(filename, std::ios::in | std::ios::binary);
|
||||
if (in)
|
||||
return std::string(std::istreambuf_iterator<char>(in),
|
||||
std::istreambuf_iterator<char>());
|
||||
throw(errno);
|
||||
}
|
Loading…
Reference in New Issue
Block a user