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

filter chaining

parent 7c6bee0f
No related branches found
No related tags found
1 merge request!1Big merge
...@@ -115,11 +115,12 @@ func relationToQuery(element entity.QueryRelationStruct, JSONQuery *entity.Incom ...@@ -115,11 +115,12 @@ func relationToQuery(element entity.QueryRelationStruct, JSONQuery *entity.Incom
if len(filters) > 0 { if len(filters) > 0 {
for i := range filters { for i := range filters {
filter := filters[i] filter := filters[i]
fmt.Println(filter.FromID) filter2 := filter
fmt.Println(element.FromID) for filter2.FromType == "filter" {
fmt.Println(filter.FromType) filters2 := tryGetFilterTo("filter", filter.ID, JSONQuery)
fmt.Println(element.FromType) filter2 = filters2[0]
if filter.FromType == element.FromType && filter.FromID == element.FromID { }
if filter2.FromType == element.FromType && filter2.FromID == element.FromID {
ret += fmt.Sprintf("\tFOR y in f%v\n", filter.ID) ret += fmt.Sprintf("\tFOR y in f%v\n", filter.ID)
ydefined = true ydefined = true
} else { } else {
...@@ -154,7 +155,14 @@ func functionToQuery(element entity.QueryGroupByStruct, JSONQuery *entity.Incomi ...@@ -154,7 +155,14 @@ func functionToQuery(element entity.QueryGroupByStruct, JSONQuery *entity.Incomi
func filterToQuery(element entity.QueryFilterStruct, JSONQuery *entity.IncomingQueryJSON) string { func filterToQuery(element entity.QueryFilterStruct, JSONQuery *entity.IncomingQueryJSON) string {
thisname := fmt.Sprintf("f%v", element.ID) thisname := fmt.Sprintf("f%v", element.ID)
ret := createLetFor(thisname, fmt.Sprintf("%v%v", typeToPrefix(element.FromType), element.FromID)) var filteredpill string
filters := tryGetFilterTo("filter", element.ID, JSONQuery)
if len(filters) > 0 {
filteredpill = fmt.Sprintf("f%v", filters[0].ID)
} else {
filteredpill = fmt.Sprintf("%v%v", typeToPrefix(element.FromType), element.FromID)
}
ret := createLetFor(thisname, filteredpill)
if element.FromType == "groupBy" { 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.MatchType)), element.Value)
} else { } else {
...@@ -242,7 +250,7 @@ func createGroupBy(element entity.QueryGroupByStruct, JSONQuery *entity.Incoming ...@@ -242,7 +250,7 @@ func createGroupBy(element entity.QueryGroupByStruct, JSONQuery *entity.Incoming
tuplename := fmt.Sprintf("gt%v", element.ID) tuplename := fmt.Sprintf("gt%v", element.ID)
result := createLetFor(thisname, tuplename) result := createLetFor(thisname, tuplename)
result += createCollect(element) result += createCollect(element)
result += "\tRETURN {\n\t_id: c,\n\t\"modifier\": variable_0\n\t}\n)\n" result += "\tRETURN {\n\t_id: c,\n\tmodifier: variable_0\n\t}\n)\n"
return result return result
} }
... ...
......
...@@ -394,7 +394,6 @@ func FuncToAllRel(JSONQuery *entity.IncomingQueryJSON, function pdict) { ...@@ -394,7 +394,6 @@ func FuncToAllRel(JSONQuery *entity.IncomingQueryJSON, function pdict) {
} }
func AddFilters(JSONQuery *entity.IncomingQueryJSON) { func AddFilters(JSONQuery *entity.IncomingQueryJSON) {
for i, filter := range JSONQuery.Filters { for i, filter := range JSONQuery.Filters {
if _, ok := filterDone[i]; !ok { if _, ok := filterDone[i]; !ok {
p := pdict{ p := pdict{
...@@ -413,7 +412,7 @@ func AddFilters(JSONQuery *entity.IncomingQueryJSON) { ...@@ -413,7 +412,7 @@ func AddFilters(JSONQuery *entity.IncomingQueryJSON) {
func addOneFilter(filterPDict pdict, JSONQuery *entity.IncomingQueryJSON, p pdict, filterDone *map[int]bool) { func addOneFilter(filterPDict pdict, JSONQuery *entity.IncomingQueryJSON, p pdict, filterDone *map[int]bool) {
if p.typename == "filter" && (*filterDone)[p.pointer] { if p.typename == "filter" && (*filterDone)[p.pointer] {
l := FindCurrentLayer(listoflists, p) l := FindCurrentLayer(listoflists, p)
k := pdictList{} k := pdictList{filterPDict}
if len(listoflists) > l+1 && listoflists[l+1][0].typename == "filter" { if len(listoflists) > l+1 && listoflists[l+1][0].typename == "filter" {
listoflists[l+1] = append(listoflists[l+1], filterPDict) listoflists[l+1] = append(listoflists[l+1], filterPDict)
} else { } else {
... ...
......
...@@ -20,7 +20,7 @@ The main function that calls the appropriate functions ...@@ -20,7 +20,7 @@ The main function that calls the appropriate functions
*/ */
func main() { func main() {
queryservice := aql.NewService() queryservice := aql.NewService()
jsonFile, err := os.Open("../test2.json") jsonFile, err := os.Open("../test3.json")
// if we os.Open returns an error then handle it // if we os.Open returns an error then handle it
if err != nil { if err != nil {
log.Println(err) log.Println(err)
... ...
......
{
"return": {
"entities": [
0,
1
],
"relations": [
0
]
},
"entities": [
{
"ID": 0,
"name": "parliament"
},
{
"ID": 1,
"name": "parties"
}
],
"relations": [
{
"ID": 0,
"name": "member_of",
"depth": {
"min": 1,
"max": 1
},
"fromType": "entity",
"fromID": 0,
"toType": "entity",
"toID": 1
}
],
"groupBys": [],
"filters": [
{
"ID": 0,
"fromType": "entity",
"fromID": 0,
"toType": "filter",
"toID": 1,
"attribute": "age",
"value": "40",
"dataType": "number",
"matchType": "GT",
"inType": "",
"inID": 0
},
{
"ID": 1,
"fromType": "filter",
"fromID": 0,
"toType": "relation",
"toID": 0,
"attribute": "seniority",
"value": "3000",
"dataType": "number",
"matchType": "GT",
"inType": "",
"inID": 0
}
],
"limit": 5000,
"modifiers": [],
"databaseName": "Tweede Kamer Dataset"
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment