Skip to content
Snippets Groups Projects
Commit 7fa32e57 authored by Geurtjens,D. (Douwe Geurtjens)'s avatar Geurtjens,D. (Douwe Geurtjens)
Browse files

ADDED: Query chaining LET bindings are now unique and re-usable, develop ready (?)

parent 18679055
No related branches found
No related tags found
1 merge request!1Big merge
......@@ -79,7 +79,11 @@ func createQuery(JSONQuery *entity.IncomingQueryJSON) *string {
nodeUnion string
relationUnion string
)
// If we've already used an entity we can set the value to true so we skip it in the result later
entityDone := make(map[int]bool)
for o := range JSONQuery.Entities {
entityDone[o] = false
}
// Loop over all relations
ret := ""
......@@ -125,16 +129,24 @@ func createQuery(JSONQuery *entity.IncomingQueryJSON) *string {
if relation.EntityFrom >= 0 {
// if there is a from-node
// create the let for this node
fromName := fmt.Sprintf("n%v", relation.EntityFrom)
ret += *createNodeLet(&JSONQuery.Entities[relation.EntityFrom], &fromName)
// IF WE'VE ALREADY SEEN THIS ENTITY WE DON'T HAVE TO REQUERY IT, WE CAN JUST REUSE THE LET BINDING
if !entityDone[relation.EntityFrom] {
fromName := fmt.Sprintf("n%v", relation.EntityFrom)
ret += *createNodeLet(&JSONQuery.Entities[relation.EntityFrom], &fromName)
entityDone[relation.EntityFrom] = true
}
ret += *createRelationLetWithFromEntity(&relation, relationName, &JSONQuery.Entities, JSONQuery.Limit)
} else if relation.EntityTo >= 0 {
fmt.Println("Joris are you a madman! How did this happen?")
// if there is only a to-node
toName := fmt.Sprintf("n%v", relation.EntityTo)
if !entityDone[relation.EntityTo] {
toName := fmt.Sprintf("n%v", relation.EntityTo)
ret += *createNodeLet(&JSONQuery.Entities[relation.EntityTo], &toName)
ret += *createNodeLet(&JSONQuery.Entities[relation.EntityTo], &toName)
entityDone[relation.EntityTo] = true
}
ret += *createRelationLetWithOnlyToEntity(&relation, relationName, &JSONQuery.Entities, JSONQuery.Limit)
// Add this relation to the list
......
......@@ -19,73 +19,8 @@ The main function that calls the appropriate functions
func main() {
queryservice := aql.NewService()
js := []byte(`{
"return": {
"entities": [
0,
1
],
"relations": [
0
]
},
"entities": [
{
"type": "parliament",
"constraints": []
},
{
"type": "commissions",
"constraints": []
}
],
"relations": [
{
"type": "part_of",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": 0,
"entityTo": 1,
"constraints": [],
"functionPointer": {
"from": -1,
"to": -1
}
}
],
"functions": [
{
"type": "groupBy",
"typeID": 0,
"groupType": "entity",
"groupID": 1,
"groupAttribute": "name",
"byType": "entity",
"byID": 0,
"byAttribute": "age",
"appliedModifier": "AVG",
"constraints": [
{
"attribute": "age",
"value": "45",
"dataType": "number",
"matchType": "GT",
"functionPointer": {
"from": -1,
"to": -1
}
}
]
}
],
"limit": 5000,
"modifiers": [],
"databaseName": "TweedeKamer"
}
js := []byte(`{"return":{"entities":[0,1],"relations":[0]},"entities":[{"type":"airports","constraints":[]},{"type":"airports","constraints":[]}],"relations":[{"type":"flights","depth":{"min":1,"max":1},"entityFrom":0,"entityTo":1,"constraints":[{"attribute":"Month","value":"1","dataType":"int","matchType":"exact"}]}],"limit":5000,"modifiers":[],"databaseName":"Flights"}
`)
var inc entity.IncomingQueryJSON
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment