Skip to content
Snippets Groups Projects
Commit a6349f61 authored by Bouma,C.J. (Chris)'s avatar Bouma,C.J. (Chris)
Browse files

Fixed query bug

Wrong things being passed, should work now woo!
parent 38aa4f64
No related branches found
No related tags found
No related merge requests found
......@@ -6,21 +6,22 @@
"exchange": "requests-exchange",
"exchangeType": "direct",
"messages": [
{
"routingKey": "aql-query-request",
"headers": {
"sessionID": "test-session",
"clientID": "c24l4vd2ngurnrncjdi0"
"clientID": "c28ha5d2ngurnrncjgkg"
},
"data":"This is not a valid query"
"data":"{\"DatabaseName\":\"test\",\"Return\":{\"Entities\":[0,1],\"Relations\":[0]},\"Entities\":[{\"Type\":\"airports\",\"Constraints\":[{\"Attribute\":\"city\",\"Value\":\"New York\",\"DataType\":\"text\",\"MatchType\":\"exact\"}]},{\"Type\":\"airports\",\"Constraints\":[{\"Attribute\":\"city\",\"Value\":\"San Francisco\",\"DataType\":\"text\",\"MatchType\":\"exact\"},{\"Attribute\":\"vip\",\"Value\":\"true\",\"DataType\":\"bool\",\"MatchType\":\"exact\"}]}],\"Relations\":[{\"Type\":\"flights\",\"Depth\":{\"min\":1,\"max\":1},\"EntityFrom\":0,\"EntityTo\":1,\"Constraints\":[{\"Attribute\":\"Month\",\"Value\":\"1\",\"DataType\":\"number\",\"MatchType\":\"exact\"},{\"Attribute\":\"Day\",\"Value\":\"15\",\"DataType\":\"number\",\"MatchType\":\"exact\"}]}], \"limit\": 1000}"
},
{
"routingKey": "aql-query-request",
"headers": {
"sessionID": "test-session",
"clientID": "c24l4vd2ngurnrncjdi0"
"clientID": "c28ha5d2ngurnrncjgkg"
},
"data":"{\"DatabaseName\":\"test\",\"Return\":{\"Entities\":[0,1],\"Relations\":[0]},\"Entities\":[{\"Type\":\"airports\",\"Constraints\":[{\"Attribute\":\"city\",\"Value\":\"New York\",\"DataType\":\"text\",\"MatchType\":\"exact\"}]},{\"Type\":\"airports\",\"Constraints\":[{\"Attribute\":\"city\",\"Value\":\"San Francisco\",\"DataType\":\"text\",\"MatchType\":\"exact\"},{\"Attribute\":\"vip\",\"Value\":\"true\",\"DataType\":\"bool\",\"MatchType\":\"exact\"}]}],\"Relations\":[{\"Type\":\"flights\",\"Depth\":{\"min\":1,\"max\":1},\"EntityFrom\":0,\"EntityTo\":1,\"Constraints\":[{\"Attribute\":\"Month\",\"Value\":\"1\",\"DataType\":\"number\",\"MatchType\":\"exact\"},{\"Attribute\":\"Day\",\"Value\":\"15\",\"DataType\":\"number\",\"MatchType\":\"exact\"}]}], \"limit\": 1000}"
"data":"This is not a valid query"
}
]
}
......
......@@ -75,32 +75,39 @@ func (s *Service) SendAQLQuery(query string, username string, password string, h
break
} else if err != nil {
// handle other errors
fmt.Println(err)
return nil, err
}
// If the result is only numerical, break out of the loop
num, isNum = doc.(float64)
if isNum {
// Switch on the type of return, to filter out the case of a single number
switch doc.(type) {
case float64:
num = doc.(float64)
isNum = true
break
case map[string]interface{}:
pdoc := doc.(map[string]interface{})
parseResult(pdoc, &listContainer)
break
default:
fmt.Println("Incompatible result type")
break
}
parseResult(doc, &listContainer)
}
if !isNum {
// Return nodes and edges
queryResult["nodes"] = listContainer.NodeList
queryResult["edges"] = listContainer.EdgeList
//writeJSON(queryResult)
//file, err := json.MarshalIndent(queryResult, "", " ")
jsonQ, err := json.Marshal(queryResult)
return &jsonQ, err
} else {
// Return just a number
numQ, err := json.Marshal(num)
return &numQ, err
}
numQ, err := json.Marshal(num)
return &numQ, err
}
/* parseResult takes the result of the query and translates this to two lists: a nodelist and an edgelist, stored in a listcontainer
......@@ -110,11 +117,11 @@ listContainer is a struct containing the nodelist and edgelist that will be retu
Return: Nothing because the result is stored in the listContainer
*/
func parseResult(incomingDoc interface{}, listContainer *entity.ListContainer) {
func parseResult(doc map[string]interface{}, listContainer *entity.ListContainer) {
doc := incomingDoc.(map[string][]interface{})
vertices := doc["vertices"]
edges := doc["edges"]
//doc, ok := incomingDoc.(map[string][]interface{})
vertices := doc["vertices"].([]interface{})
edges := doc["edges"].([]interface{})
for _, vertex := range vertices {
vertexDoc := vertex.(map[string]interface{})
......
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