Skip to content
Snippets Groups Projects
Commit 25a77a45 authored by Heijden,T.A.J. van der (Thijs)'s avatar Heijden,T.A.J. van der (Thijs)
Browse files

Merge branch 'Develop' into 'main'

Develop

See merge request datastrophe/query-conversion!8
parents 85249a98 6beac690
No related branches found
No related tags found
2 merge requests!2Groupby overhaul,!1Big merge
...@@ -96,12 +96,20 @@ func createQuery(JSONQuery *entity.IncomingQueryJSON) *string { ...@@ -96,12 +96,20 @@ func createQuery(JSONQuery *entity.IncomingQueryJSON) *string {
} }
// Include all types that are not yet included // Include all types that are not yet included
first := true
for k := range allTypes { for k := range allTypes {
if !includedTypes[k] { if !includedTypes[k] {
ret += fmt.Sprintf("WITH %v\n", k) if first {
ret += fmt.Sprintf("WITH %v", k)
first = false
} else {
ret += fmt.Sprintf(", %v", k)
}
} }
} }
if !first {
ret += "\n"
}
for i, relation := range JSONQuery.Relations { for i, relation := range JSONQuery.Relations {
......
...@@ -1053,6 +1053,90 @@ func TestNoRelationsField(t *testing.T) { ...@@ -1053,6 +1053,90 @@ func TestNoRelationsField(t *testing.T) {
assert.Equal(t, correctConvertedResult, cleanedResult) assert.Equal(t, correctConvertedResult, cleanedResult)
} }
/*
Tests a query with double WITH
t: *testing.T, makes go recognise this as a test
*/
func TestDoubleWITH(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"databaseName": "test",
"return": {
"entities": [
0,
1,
2,
3
],
"relations": [
0,
1
]
},
"entities": [
{
"type": "kamerleden",
"constraints": []
},
{
"type": "partijen",
"constraints": []
}
,
{
"type": "kamerleden",
"constraints": []
},
{
"type": "commissies",
"constraints": []
}
],
"relations": [
{
"type": "lid_van",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": 0,
"entityTo": 1,
"constraints": []
},
{
"type": "onderdeel_van",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": 2,
"entityTo": 3,
"constraints": []
}
],
"limit": 5000,
"modifiers": []
}`)
// Unmarshall the incoming message into an IncomingJSONQuery object
var JSONQuery entity.IncomingQueryJSON
json.Unmarshal(query, &JSONQuery)
convertedResult, err := service.ConvertQuery(&JSONQuery)
// Assert that there is no error
assert.NoError(t, err)
// Assert that the result and the expected result are the same
correctConvertedResult := "WITH partijen, commissiesLET n0 = (FOR x IN kamerleden RETURN x)LET r0 = (FOR x IN n0 FOR v, e, p IN 1..1 OUTBOUND x lid_van OPTIONS { uniqueEdges: \"path\" }LIMIT 5000 RETURN DISTINCT p )LET n2 = (FOR x IN kamerleden RETURN x)LET r1 = (FOR x IN n2 FOR v, e, p IN 1..1 OUTBOUND x onderdeel_van OPTIONS { uniqueEdges: \"path\" }LIMIT 5000 RETURN DISTINCT p )LET nodes = first(RETURN UNION_DISTINCT(flatten(r0[**].vertices), flatten(r1[**].vertices), [],[]))LET edges = first(RETURN UNION_DISTINCT(flatten(r0[**].edges), flatten(r1[**].edges), [],[]))RETURN {\"vertices\":nodes, \"edges\":edges }"
cleanedResult := strings.ReplaceAll(*convertedResult, "\n", "")
cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
assert.Equal(t, correctConvertedResult, cleanedResult)
}
/* /*
Tests an entity with a lower than -1 in a relation Tests an entity with a lower than -1 in a relation
t: *testing.T, makes go recognise this as a test t: *testing.T, makes go recognise this as a test
......
File added
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"encoding/json" "encoding/json"
"log" "log"
"git.science.uu.nl/datastrophe/query-conversion/cypher" "git.science.uu.nl/datastrophe/query-conversion/aql"
"git.science.uu.nl/datastrophe/query-conversion/entity" "git.science.uu.nl/datastrophe/query-conversion/entity"
) )
...@@ -17,29 +17,66 @@ import ( ...@@ -17,29 +17,66 @@ import (
The main function that calls the appropriate functions The main function that calls the appropriate functions
*/ */
func main() { func main() {
queryservice := cypher.NewService() queryservice := aql.NewService()
js := []byte(`{ js := []byte(`{
"return": { "databaseName": "test",
"entities": [ "return": {
0 "entities": [
] 0,
}, 1,
"entities": [ 2,
{ 3
"type": "airports", ],
"constraints": [ "relations": [
{ 0,
"attribute": "city", 1
"value": "San Francisco", ]
"dataType": "string", },
"matchType": "exact" "entities": [
} {
] "type": "kamerleden",
} "constraints": []
], },
"limit": 5000 {
}`) "type": "partijen",
"constraints": []
}
,
{
"type": "kamerleden",
"constraints": []
},
{
"type": "commissies",
"constraints": []
}
],
"relations": [
{
"type": "lid_van",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": 0,
"entityTo": 1,
"constraints": []
},
{
"type": "onderdeel_van",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": 2,
"entityTo": 3,
"constraints": []
}
],
"limit": 5000,
"modifiers": []
}`)
var inc entity.IncomingQueryJSON var inc entity.IncomingQueryJSON
json.Unmarshal(js, &inc) json.Unmarshal(js, &inc)
......
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