Skip to content
Snippets Groups Projects
Commit 038e64a3 authored by Kieran van Gaalen's avatar Kieran van Gaalen
Browse files

Started fixing tests for query conversion

parent d90b0e95
No related branches found
No related tags found
1 merge request!1Big merge
......@@ -20,7 +20,6 @@ ConvertQuery converts an IncomingQueryJSON object into AQL
Returns: *string, the AQL query and a possible error
*/
func (s *Service) ConvertQuery(JSONQuery *entity.IncomingQueryJSON) (*string, error) {
// Check to make sure all indexes exist
// The largest possible id for an entity
largestEntityID := len(JSONQuery.Entities) - 1
......@@ -164,9 +163,9 @@ func filterToQuery(element entity.QueryFilterStruct, JSONQuery *entity.IncomingQ
}
ret := createLetFor(thisname, filteredpill)
if element.FromType == "groupBy" {
ret += fmt.Sprintf("\tFILTER x.modifier %v %v\n", wordsToLogicalSign((element.MatchType)), element.Value)
ret += fmt.Sprintf("\tFILTER x.modifier %v %v\n", wordsToLogicalSign(element), element.Value)
} else {
ret += fmt.Sprintf("\tFILTER x.%v %v %v\n", element.Attribute, wordsToLogicalSign((element.MatchType)), element.Value)
ret += fmt.Sprintf("\tFILTER x.%v %v %v\n", element.Attribute, wordsToLogicalSign(element), element.Value)
}
ret += "\tRETURN x\n)\n"
return ret
......@@ -213,20 +212,44 @@ func tryGetFilterFrom(fromType string, fromID int, JSONQuery *entity.IncomingQue
return list
}
func wordsToLogicalSign(word string) string {
if word == "LT" {
return "<"
} else if word == "LTE" {
return "<="
} else if word == "EQ" {
return "=="
} else if word == "GTE" {
return ">="
} else if word == "NEQ" {
return "!="
} else {
return ">"
func wordsToLogicalSign(element entity.QueryFilterStruct) string {
var match string
switch element.DataType {
case "string":
switch element.MatchType {
case "NEQ":
match = "!="
case "contains":
match = "LIKE"
case "excludes":
match = "NOT LIKE"
default: //EQ
match = "=="
}
case "int":
switch element.MatchType {
case "NEQ":
match = "!="
case "GT":
match = ">"
case "LT":
match = "<"
case "GET":
match = ">="
case "LET":
match = "<="
default: //EQ
match = "=="
}
default: /*bool*/
switch element.MatchType {
case "NEQ":
match = "!="
default: //EQ
match = "=="
}
}
return match
}
func getTupleVar(element entity.QueryGroupByStruct, JSONQuery *entity.IncomingQueryJSON) string {
......@@ -274,7 +297,7 @@ func createCollect(element entity.QueryGroupByStruct) string {
}
func createFilter(filter entity.QueryFilterStruct) string {
return "\tFILTER variable_0 " + wordsToLogicalSign(filter.MatchType) + " " + filter.Value + " \n"
return "\tFILTER variable_0 " + wordsToLogicalSign(filter) + " " + filter.Value + " \n"
}
func findUnusedRelations(JSONQuery *entity.IncomingQueryJSON) []string {
......
......@@ -74,18 +74,18 @@ func TestMultipleEntityTypes(t *testing.T) {
},
"entities": [
{
"type": "kamerleden",
"name": "kamerleden",
"ID": 0
},
{
"type": "partijen",
"name": "partijen",
"ID": 1
}
],
"relations": [
{
"ID": 0
"type": "lid_van",
"ID": 0,
"name": "lid_van",
"depth": {
"min": 1,
"max": 1
......@@ -139,7 +139,7 @@ func TestMultipleEntityTypes(t *testing.T) {
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := `WITH partijenLET n0 = (FOR x IN kamerleden FILTER x.partij == "GL" RETURN x)LET r0 = (FOR x IN n0 FOR v, e, p IN 1..1 OUTBOUND x lid_van OPTIONS { uniqueEdges: "path" }FILTER v.zetels > 6 LIMIT 5000 RETURN DISTINCT p )LET nodes = first(RETURN UNION_DISTINCT(flatten(r0[**].vertices), [],[]))LET edges = first(RETURN UNION_DISTINCT(flatten(r0[**].edges), [],[]))RETURN {"vertices":nodes, "edges":edges }`
correctConvertedResult := `LET e0 = (FOR x IN kamerledenRETURN x)LET e1 = (FOR x IN partijenRETURN x)LET f0 = (FOR x IN e0FILTER x.partij == GLRETURN x)LET f1 = (FOR x IN e1FILTER x.zetels > 6RETURN x)LET r0 = (FOR x IN lid_vanFOR y in f0FOR z in f1FILTER x._from == y._id AND x._to == z._idLET nodes = APPEND([], [y, z])RETURN DISTINCT {"edges": x,"vertices": nodes})LET nodes = first(RETURN UNION_DISTINCT(flatten(r0[**].vertices),[],[]))LET edges = first(RETURN UNION_DISTINCT(flatten(r0[**].edges),[],[]))RETURN {"vertices":nodes, "edges":edges }`
//cleanedResult := strings.ReplaceAll(correctConvertedResult, "\n", "")
//cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
......@@ -167,7 +167,7 @@ func TestEntityOneAttributeQuery(t *testing.T) {
},
"entities": [
{
"type": "airports",
"name": "airports",
"ID": 0
}
],
......
......@@ -20,7 +20,7 @@ The main function that calls the appropriate functions
*/
func main() {
queryservice := aql.NewService()
jsonFile, err := os.Open("../test3.json")
jsonFile, err := os.Open("../realtest.json")
// if we os.Open returns an error then handle it
if err != nil {
log.Println(err)
......
{
"return": {
"entities": [
0
],
"relations": []
},
"entities": [
{
"name": "airports",
"ID": 0
}
],
"groupBys": [],
"relations": [],
"filters": [
{
"ID": 0,
"fromType": "entity",
"fromID": 0,
"toType": "",
"toID": -1,
"attribute": "state",
"value": "HI",
"dataType": "string",
"matchType": "exact",
"inType": "",
"inID": -1
}
],
"limit": 5000
}
\ No newline at end of file
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