From 638f7a9e8005e216cc6e8cb314ca923d0f4e41fc Mon Sep 17 00:00:00 2001 From: Douwe <d.geurtjens@students.uu.nl> Date: Tue, 9 Nov 2021 14:26:58 +0100 Subject: [PATCH] Quick push new new format --- aql/createConstraints.go | 4 +-- aql/hierarchy.go | 60 ---------------------------------------- entity/queryStruct.go | 44 ++++++++++++++--------------- 3 files changed, 22 insertions(+), 86 deletions(-) diff --git a/aql/createConstraints.go b/aql/createConstraints.go index 946fd1c..0481bd9 100644 --- a/aql/createConstraints.go +++ b/aql/createConstraints.go @@ -13,7 +13,7 @@ isRelation is a boolean specifying if this constraint comes from a node or relat Return: a string containing a FILTER-statement with all the constraints */ -func createConstraintStatements(constraints *[]entity.QueryFilterStruct, name string, isRelation bool) *string { +func createConstraintStatements(constraints *[]entity.QueryConstraintStruct, name string, isRelation bool) *string { s := "" if len(*constraints) == 0 { return &s @@ -38,7 +38,7 @@ isRelation is a boolean specifying if this constraint comes from a node or relat Return: a string containing an boolean expression of a single constraint */ -func createConstraintBoolExpression(constraint *entity.QueryFilterStruct, name string, isRelation bool) *string { +func createConstraintBoolExpression(constraint *entity.QueryConstraintStruct, name string, isRelation bool) *string { var ( match string value string diff --git a/aql/hierarchy.go b/aql/hierarchy.go index 7b78c75..7b8acfc 100644 --- a/aql/hierarchy.go +++ b/aql/hierarchy.go @@ -43,7 +43,6 @@ func search(JSONQuery *entity.IncomingQueryJSON, index int) []entity.PdictList { } fmt.Println("") } - listoflists = addFilters(JSONQuery, listoflists) fmt.Println(listoflists) return listoflists } @@ -273,52 +272,6 @@ func funcToAllRel(JSONQuery *entity.IncomingQueryJSON, listoflists []entity.Pdic return listoflists } -func addFilters(JSONQuery *entity.IncomingQueryJSON, listoflists []entity.PdictList) []entity.PdictList { - - for i, filter := range JSONQuery.Filters { - if _, ok := filterDone[i]; !ok { - p := makePdict(filter.FromType, filter.FromID) - f := makePdict(FILTERSTRING, filter.ID) - listoflists = addOneFilter(f, JSONQuery, listoflists, p, &filterDone) - } - } - return listoflists -} - -func addOneFilter(filterPDict entity.Pdict, JSONQuery *entity.IncomingQueryJSON, listoflists []entity.PdictList, p entity.Pdict, filterDone *map[int]bool) []entity.PdictList { - if p.Typename == FILTERSTRING && (*filterDone)[p.Pointer] { - l := findCurrentLayer(listoflists, p) - k := entity.PdictList{filterPDict} - if len(listoflists) > l+1 && listoflists[l+1][0].Typename == FILTERSTRING { - listoflists[l+1] = append(listoflists[l+1], filterPDict) - } else { - listoflists = filterAppend(listoflists, l, k) - } - (*filterDone)[filterPDict.Pointer] = true - } else if p.Typename == FILTERSTRING { - pnew := makePdict(JSONQuery.Filters[p.Pointer].FromType, JSONQuery.Filters[p.Pointer].FromID) - addOneFilter(p, JSONQuery, listoflists, pnew, filterDone) - l := findCurrentLayer(listoflists, p) - k := entity.PdictList{filterPDict} - if len(listoflists) > l+1 && listoflists[l+1][0].Typename == FILTERSTRING { - listoflists[l+1] = append(listoflists[l+1], filterPDict) - } else { - listoflists = filterAppend(listoflists, l, k) - } - (*filterDone)[filterPDict.Pointer] = true - } else { - l := findCurrentLayer(listoflists, p) - k := entity.PdictList{filterPDict} - if len(listoflists) > l+1 && listoflists[l+1][0].Typename == FILTERSTRING { - listoflists[l+1] = append(listoflists[l+1], filterPDict) - } else { - listoflists = filterAppend(listoflists, l, k) - } - (*filterDone)[filterPDict.Pointer] = true - } - return listoflists -} - // A function that appends 1 level above (if index is 0 this won't work) func aboveAppend(listoflists []entity.PdictList, index int, values entity.PdictList) []entity.PdictList { if index == 0 { @@ -349,19 +302,6 @@ func belowAppend(listoflists []entity.PdictList, index int, values entity.PdictL } } -func filterAppend(listoflists []entity.PdictList, index int, values entity.PdictList) []entity.PdictList { - if len(listoflists)-1 == index { // nil or empty slice or after last element - return append(listoflists, values) - } - k := make([]entity.PdictList, len(listoflists[index+1:])) - copy(k, listoflists[index+1:]) - l := make([]entity.PdictList, len(listoflists[:index+1])) - copy(l, listoflists[:index+1]) - listoflists = append(l, values) // index < len(a) - return append(listoflists, k...) - -} - // A simple double-for loop that finds the layer in which an element resides in the hierarchy // Because we only append elements relative to another element, we can freely use this to keep track of layers func findCurrentLayer(list []entity.PdictList, element entity.Pdict) int { diff --git a/entity/queryStruct.go b/entity/queryStruct.go index 59e8d99..248b58c 100644 --- a/entity/queryStruct.go +++ b/entity/queryStruct.go @@ -7,7 +7,6 @@ type IncomingQueryJSON struct { Entities []QueryEntityStruct Relations []QueryRelationStruct GroupBys []QueryGroupByStruct - Filters []QueryFilterStruct MachineLearning []QueryMLStruct // Limit is for limiting the amount of paths AQL will return in a relation let statement Limit int @@ -24,19 +23,21 @@ type QueryReturnStruct struct { // QueryEntityStruct encapsulates a single entity with its corresponding constraints type QueryEntityStruct struct { - ID int - Name string + ID int + Name string + Constraints []QueryConstraintStruct } // QueryRelationStruct encapsulates a single relation with its corresponding constraints type QueryRelationStruct struct { - ID int - Name string - FromType string - FromID int - ToType string - ToID int - Depth QuerySearchDepthStruct + ID int + Name string + FromType string + FromID int + ToType string + ToID int + Depth QuerySearchDepthStruct + QueryConstraintStruct []QueryConstraintStruct } type QueryGroupByStruct struct { @@ -49,20 +50,21 @@ type QueryGroupByStruct struct { ByAttribute string AppliedModifier string RelationID int + Constraints []QueryConstraintStruct } -type QueryFilterStruct struct { - ID int - FromType string - FromID int - ToType string - ToID int +// QueryConstraintStruct holds the information of the constraint +// Constraint datatypes +// string MatchTypes: exact/contains/startswith/endswith +// int MatchTypes: GT/LT/EQ +// bool MatchTypes: EQ/NEQ +type QueryConstraintStruct struct { Attribute string + Value string DataType string MatchType string - Value string - InType string InID int + InType string } type QueryMLStruct struct { @@ -83,9 +85,3 @@ type QuerySearchDepthStruct struct { Min int Max int } - -// QueryConstraintStruct holds the information of the constraint -// Constraint datatypes -// string MatchTypes: exact/contains/startswith/endswith -// int MatchTypes: GT/LT/EQ/ -// bool MatchTypes: EQ/NEQ -- GitLab