Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
grammar create node bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Roi Lipman committed Nov 27, 2016
1 parent 1e64cd2 commit 39e3300
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 170 deletions.
8 changes: 7 additions & 1 deletion Demo/social/social_demo.py
Expand Up @@ -68,7 +68,8 @@ def AddPersonToGraph(person, pipe):
pipe.hmset(key, {prop: person[prop]})

for country in person["visited"]:
pipe.execute_command("GRAPH.ADDEDGE", graph, person["name"], "visited", country)
pipe.hmset(country, {"name": country})
pipe.execute_command("GRAPH.ADDEDGE", graph, person["name"], "visited", country)

for friend in person["friendsWith"]:
pipe.execute_command("GRAPH.ADDEDGE", graph, person["name"], "friend", friend["name"])
Expand Down Expand Up @@ -111,6 +112,11 @@ def main():
WHERE fof.status = single
RETURN fof.name""";
ExecuteQuery(query)

print "Friends who've been to places I've visited"
query = """MATCH (ME:"Roi Lipman")-[visited]->(country)<-[visited]-(f)<-[friend]-(:"Roi Lipman")
RETURN f.name, country.name""";
ExecuteQuery(query)

if __name__ == '__main__':
main()
8 changes: 7 additions & 1 deletion Demo/social/social_demo_debug.py
Expand Up @@ -60,7 +60,8 @@ def AddPersonToGraph(person, pipe):
pipe.hmset(key, {prop: person[prop]})

for country in person["visited"]:
pipe.execute_command("GRAPH.ADDEDGE", graph, person["name"], "visited", country)
pipe.hmset(country, {"name": country})
pipe.execute_command("GRAPH.ADDEDGE", graph, person["name"], "visited", country)

for friend in person["friendsWith"]:
pipe.execute_command("GRAPH.ADDEDGE", graph, person["name"], "friend", friend["name"])
Expand Down Expand Up @@ -100,6 +101,11 @@ def main():
WHERE fof.status = single
RETURN fof.name""";
ExecuteQuery(query)

print "Friends who've been to places I've visited"
query = """MATCH (ME:"Roi Lipman")-[visited]->(country)<-[visited]-(f)<-[friend]-(:"Roi Lipman")
RETURN f.name, country.name""";
ExecuteQuery(query)

if __name__ == '__main__':
main()
1 change: 0 additions & 1 deletion Demo/social/visits.csv
Expand Up @@ -4,7 +4,6 @@ Roi Lipman,Tokyo
Alon Fital,Prague
Alon Fital,USA
Alon Fital,Greece
Alon Fital,USA
Ori Laslo,Canada
Ori Laslo,USA
Ori Laslo,China
Expand Down
7 changes: 7 additions & 0 deletions src/graph/graph.c
Expand Up @@ -26,6 +26,13 @@ Node* Graph_AddNode(Graph* g, const char* alias, const char* id) {
if(n == NULL) {
n = NewNode(alias, id);
Vector_Push(g->nodes, n);
} else {
// Update node ID in case it is missing
if(n->id != NULL && strlen(n->id) == 0 && strlen(id) > 0) {
free(n->id);
n->id = (char*)malloc(sizeof(char) * (strlen(id) + 1));
strcpy(n->id, id);
}
}

return n;
Expand Down
5 changes: 2 additions & 3 deletions src/graph/node.c
Expand Up @@ -11,15 +11,14 @@ Node* NewNode(const char* alias, const char* id) {

if(id != NULL) {
node->id = (char*)malloc(sizeof(char) * (strlen(id) + 1));
strcpy(node->id, id);
}

if(alias != NULL) {
node->alias = (char*)malloc(sizeof(char) * (strlen(alias) + 1));
strcpy(node->alias, alias);
}

strcpy(node->id, id);
strcpy(node->alias, alias);

return node;
}

Expand Down
2 changes: 0 additions & 2 deletions src/module.c
Expand Up @@ -208,7 +208,6 @@ char* BuildQueryResponse(RedisModuleCtx *ctx, const ReturnNode* returnNode, cons
Node* n = Graph_GetNodeByAlias(g, var->alias);
// Alias maps to subject or object?
char* elementID = n->id;

RedisModuleString* keyStr =
RedisModule_CreateString(ctx, elementID, strlen(elementID));

Expand Down Expand Up @@ -254,7 +253,6 @@ char* BuildQueryResponse(RedisModuleCtx *ctx, const ReturnNode* returnNode, cons
strItem[strlen(strItem)-1] = NULL;

// TODO: Clean up

return strItem;
}

Expand Down

0 comments on commit 39e3300

Please sign in to comment.