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

Merge branch '676-Query-Nesting-Development' of...

Merge branch '676-Query-Nesting-Development' of https://git.science.uu.nl/GravenvanPolaris/query-conversion into 676-Query-Nesting-Development
parents 73c75936 ff0cac99
No related branches found
No related tags found
1 merge request!1Big merge
......@@ -37,6 +37,7 @@ var reldone map[int]bool
var entdone map[int]bool
var funcdone map[int]bool
var relfuncdone map[int]bool
var filterDone map[int]bool
func search(JSONQuery *entity.IncomingQueryJSON, index int) {
listoflists = []pdictList{}
......@@ -44,7 +45,7 @@ func search(JSONQuery *entity.IncomingQueryJSON, index int) {
entdone = make(map[int]bool)
funcdone = make(map[int]bool)
relfuncdone = make(map[int]bool)
filterDone = make(map[int]bool)
var s pdictList
//printSlice(s)
//layercounter = 0
......@@ -215,7 +216,7 @@ func RelToAllFunc(JSONQuery *entity.IncomingQueryJSON, rel pdict) {
if _, ok := funcdone[i]; !ok {
if JSONQuery.GroupBys[i].RelationID == rel.pointer {
relfunc := pdict{
typename: "function",
typename: "groupBy",
pointer: i,
}
funcappliedtosubquery = append(funcappliedtosubquery, relfunc)
......@@ -224,7 +225,7 @@ func RelToAllFunc(JSONQuery *entity.IncomingQueryJSON, rel pdict) {
if JSONQuery.Relations[rel.pointer].FromID == i && JSONQuery.Relations[rel.pointer].FromType == "groupBy" {
fromfunc := pdict{
typename: "function",
typename: "groupBy",
pointer: i,
}
functowhichrelapplies = append(functowhichrelapplies, fromfunc)
......@@ -232,7 +233,7 @@ func RelToAllFunc(JSONQuery *entity.IncomingQueryJSON, rel pdict) {
} else if JSONQuery.Relations[rel.pointer].ToID == i && JSONQuery.Relations[rel.pointer].ToType == "groupBy" {
tofunc := pdict{
typename: "function",
typename: "groupBy",
pointer: i,
}
functowhichrelapplies = append(functowhichrelapplies, tofunc)
......@@ -393,9 +394,9 @@ func FuncToAllRel(JSONQuery *entity.IncomingQueryJSON, function pdict) {
}
func AddFilters(JSONQuery *entity.IncomingQueryJSON) {
filterDone := make([]bool, len(JSONQuery.Filters))
for i, filter := range JSONQuery.Filters {
if !filterDone[i] {
if _, ok := filterDone[i]; !ok {
p := pdict{
typename: filter.FromType,
pointer: filter.FromID,
......@@ -409,7 +410,7 @@ func AddFilters(JSONQuery *entity.IncomingQueryJSON) {
}
}
func addOneFilter(filterPDict pdict, JSONQuery *entity.IncomingQueryJSON, p pdict, filterDone *[]bool) {
func addOneFilter(filterPDict pdict, JSONQuery *entity.IncomingQueryJSON, p pdict, filterDone *map[int]bool) {
if p.typename == "filter" && (*filterDone)[p.pointer] {
l := FindCurrentLayer(listoflists, p)
k := pdictList{}
......
......@@ -173,9 +173,6 @@ func TestHierarchyRandomStart(t *testing.T) {
sort.Sort(k)
sortedListOfLists[i] = k
}
fmt.Println(listoflists)
fmt.Println(sortedListOfLists)
//for i, x := range listoflists
assert.Equal(t, fmt.Sprint(correctResult), fmt.Sprint(sortedListOfLists))
}
......@@ -188,75 +185,127 @@ func TestHierarchyWithGroupby(t *testing.T) {
"return": {
"entities": [
0,
1
1,
2,
3
],
"relations": [
0
],
"groupBys": []
0,
1,
2
]
},
"entities": [
{
"name": "parties",
"ID": 1
"ID": 0,
"name": "parliament"
},
{
"name": "parliament",
"ID": 0
"ID": 1,
"name": "commissions"
},
{
"ID": 2,
"name": "parliament"
},
{
"ID": 3,
"name": "resolutions"
}
],
"relations": [
{
"ID": 0,
"name": "member_of",
"type": "part_of",
"depth": {
"min": 1,
"max": 1
},
"fromType": "entity",
"fromID": 0,
"fromId": 0,
"toType": "entity",
"toID": 1
},
{
"type": "part_of",
"depth": {
"min": 1,
"max": 1
},
"fromType": "groupBy",
"fromID": 0,
"toType": "entity",
"toID": 2
},
{
"type": "submits",
"depth": {
"min": 1,
"max": 1
},
"fromType": "entity",
"fromID": 2,
"toType": "entity",
"toID": 3
}
],
"groupBys": [
{
"ID": 0,
"groupType": "entity",
"groupID": 0,
"groupAttribute": "age",
"byType": "entity",
"byID": 1,
"byAttribute": "name",
"appliedModifier": "AVG",
"relationID": 0,
"constraints": [
{
"attribute": "age",
"value": "45",
"dataType": "number",
"matchType": "GT",
"functionPointer": {
"from": -1,
"to": -1
}
}
]
}
],
"groupBys": [],
"filters": [
{
"ID": 0,
"filteredType": "entity",
"filteredID": 0,
"fromType": "groupBy",
"fromID": 0,
"toType": "relation",
"toID": 1,
"attribute": "age",
"dataType": "int",
"matchType": "NEQ",
"value": "40",
"value": "45",
"dataType": "number",
"matchType": "GT",
"inType": "",
"inID": 0
},
{
"ID": 1,
"filteredType": "relation",
"filteredID": 0,
"attribute": "isChairman",
"dataType": "bool",
"matchType": "exact",
"value": "true",
"inType": "",
"inID": 0
"inID": -1
}
],
"limit": 5000
"limit": 5000,
"modifiers": [],
"databaseName": "TweedeKamer"
}
`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
correctResult := make([]pdictList, 4)
correctResult := make([]pdictList, 5)
correctResult[0] = pdictList{{typename: "entity", pointer: 0}, {typename: "entity", pointer: 1}}
correctResult[1] = pdictList{{typename: "filter", pointer: 0}}
correctResult[2] = pdictList{{typename: "relation", pointer: 0}}
correctResult[3] = pdictList{{typename: "filter", pointer: 1}}
correctResult[1] = pdictList{{typename: "relation", pointer: 0}}
correctResult[2] = pdictList{{typename: "entity", pointer: 2}, {typename: "entity", pointer: 3}, {typename: "groupBy", pointer: 0}}
correctResult[3] = pdictList{{typename: "filter", pointer: 0}}
correctResult[4] = pdictList{{typename: "relation", pointer: 1}, {typename: "relation", pointer: 2}}
for i := range JSONQuery.Entities {
search(&JSONQuery, i)
......@@ -267,9 +316,6 @@ func TestHierarchyWithGroupby(t *testing.T) {
sort.Sort(k)
sortedListOfLists[i] = k
}
fmt.Println(listoflists)
fmt.Println(sortedListOfLists)
//for i, x := range listoflists
assert.Equal(t, fmt.Sprint(correctResult), fmt.Sprint(sortedListOfLists))
}
......
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