Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Q
query-conversion
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GraphPolaris
query-conversion
Commits
65cd170f
Commit
65cd170f
authored
3 years ago
by
Lelieveld,J.R.J. (Joris)
Browse files
Options
Downloads
Patches
Plain Diff
Fixed the with statements and added a test
parent
0a33817a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aql/convertQuery.go
+29
-5
29 additions, 5 deletions
aql/convertQuery.go
aql/convertQuery_test.go
+74
-0
74 additions, 0 deletions
aql/convertQuery_test.go
with
103 additions
and
5 deletions
aql/convertQuery.go
+
29
−
5
View file @
65cd170f
...
@@ -7,6 +7,8 @@ import (
...
@@ -7,6 +7,8 @@ import (
"git.science.uu.nl/datastrophe/query-conversion/entity"
"git.science.uu.nl/datastrophe/query-conversion/entity"
)
)
// Version 1.13
/*
/*
ConvertQuery converts an IncomingQueryJSON object into AQL
ConvertQuery converts an IncomingQueryJSON object into AQL
JSONQuery: *entity.IncomingQueryJSON, the query to be converted to AQL
JSONQuery: *entity.IncomingQueryJSON, the query to be converted to AQL
...
@@ -69,6 +71,33 @@ func createQuery(JSONQuery *entity.IncomingQueryJSON) *string {
...
@@ -69,6 +71,33 @@ func createQuery(JSONQuery *entity.IncomingQueryJSON) *string {
// Loop over all relations
// Loop over all relations
ret
:=
""
ret
:=
""
// Add a WITH statement for entityTo
includedTypes
:=
make
(
map
[
string
]
bool
)
allTypes
:=
make
(
map
[
string
]
bool
)
for
_
,
relation
:=
range
JSONQuery
.
Relations
{
if
relation
.
EntityFrom
>=
0
{
includedTypes
[
JSONQuery
.
Entities
[
relation
.
EntityFrom
]
.
Type
]
=
true
allTypes
[
JSONQuery
.
Entities
[
relation
.
EntityFrom
]
.
Type
]
=
true
// If the type is in the entityTo it is a valid type but not yet included
if
relation
.
EntityTo
>=
0
{
allTypes
[
JSONQuery
.
Entities
[
relation
.
EntityTo
]
.
Type
]
=
true
}
}
if
relation
.
EntityFrom
==
-
1
&&
relation
.
EntityTo
>=
0
{
includedTypes
[
JSONQuery
.
Entities
[
relation
.
EntityTo
]
.
Type
]
=
true
allTypes
[
JSONQuery
.
Entities
[
relation
.
EntityTo
]
.
Type
]
=
true
}
}
// Include all types that are not yet included
for
k
:=
range
allTypes
{
if
!
includedTypes
[
k
]
{
ret
+=
fmt
.
Sprintf
(
"WITH %v
\n
"
,
k
)
}
}
for
i
,
relation
:=
range
JSONQuery
.
Relations
{
for
i
,
relation
:=
range
JSONQuery
.
Relations
{
relationName
:=
fmt
.
Sprintf
(
"r%v"
,
i
)
relationName
:=
fmt
.
Sprintf
(
"r%v"
,
i
)
...
@@ -250,11 +279,6 @@ func createRelationLetWithFromEntity(relation *entity.QueryRelationStruct, name
...
@@ -250,11 +279,6 @@ func createRelationLetWithFromEntity(relation *entity.QueryRelationStruct, name
// If there is a to-node, generate the filter statement
// If there is a to-node, generate the filter statement
toConstraints
:=
(
*
entities
)[
relation
.
EntityTo
]
.
Constraints
toConstraints
:=
(
*
entities
)[
relation
.
EntityTo
]
.
Constraints
vFilterStmnt
+=
*
createConstraintStatements
(
&
toConstraints
,
"v"
,
false
)
vFilterStmnt
+=
*
createConstraintStatements
(
&
toConstraints
,
"v"
,
false
)
// Add a WITH statement if the collection of entityTo is not yet included
if
(
*
entities
)[(
*
relation
)
.
EntityFrom
]
.
Type
!=
(
*
entities
)[(
*
relation
)
.
EntityTo
]
.
Type
{
header
=
fmt
.
Sprintf
(
"%v
\n\t
WITH %v"
,
header
,
(
*
entities
)[(
*
relation
)
.
EntityTo
]
.
Type
)
}
}
}
relationFilterStmnt
:=
*
createConstraintStatements
(
&
relation
.
Constraints
,
"p"
,
true
)
relationFilterStmnt
:=
*
createConstraintStatements
(
&
relation
.
Constraints
,
"p"
,
true
)
...
...
This diff is collapsed.
Click to expand it.
aql/convertQuery_test.go
+
74
−
0
View file @
65cd170f
...
@@ -41,6 +41,80 @@ LET edges = first(RETURN UNION_DISTINCT([],[]))
...
@@ -41,6 +41,80 @@ LET edges = first(RETURN UNION_DISTINCT([],[]))
RETURN {"vertices":nodes, "edges":edges }`
RETURN {"vertices":nodes, "edges":edges }`
assert
.
Equal
(
t
,
correctConvertedResult
,
*
convertedResult
)
assert
.
Equal
(
t
,
correctConvertedResult
,
*
convertedResult
)
}
}
func
TestMultipleEntityTypes
(
t
*
testing
.
T
)
{
// Setup for test
// Create query conversion service
service
:=
NewService
()
query
:=
[]
byte
(
`{
"databaseName": "test",
"return": {
"entities": [
0,
1
],
"relations": [
0
]
},
"entities": [
{
"type": "kamerleden",
"constraints": [
{
"attribute": "partij",
"value": "GL",
"dataType": "text",
"matchType": "exact"
}
]
},
{
"type": "partijen",
"constraints": [
{
"attribute": "zetels",
"value": "6",
"dataType": "number",
"matchType": "GT"
}
]
}
],
"relations": [
{
"type": "lid_van",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": 0,
"entityTo": 1,
"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
\n
LET n0 = (
\n\t
FOR x IN kamerleden
\n\t
FILTER x.partij ==
\"
GL
\"
\n\t
RETURN x
\n
)
\n
LET r0 = (
\n\t
FOR x IN n0
\n\t
FOR v, e, p IN 1..1 OUTBOUND x lid_van
\n\t
OPTIONS { uniqueEdges:
\"
path
\"
}
\n\t
FILTER v.zetels > 6
\n\t
LIMIT 5000
\n
RETURN DISTINCT p )
\n\n
LET nodes = first(RETURN UNION_DISTINCT(flatten(r0[**].vertices), [],[]))
\n
LET edges = first(RETURN UNION_DISTINCT(flatten(r0[**].edges), [],[]))
\n
RETURN {
\"
vertices
\"
:nodes,
\"
edges
\"
:edges }"
cleanedResult
:=
strings
.
ReplaceAll
(
correctConvertedResult
,
"
\n
"
,
""
)
cleanedResult
=
strings
.
ReplaceAll
(
cleanedResult
,
"
\t
"
,
""
)
convertedCleanedResult
:=
strings
.
ReplaceAll
(
*
convertedResult
,
"
\n
"
,
""
)
convertedCleanedResult
=
strings
.
ReplaceAll
(
convertedCleanedResult
,
"
\t
"
,
""
)
assert
.
Equal
(
t
,
convertedCleanedResult
,
cleanedResult
)
}
func
TestEntityOneAttributeQuery
(
t
*
testing
.
T
)
{
func
TestEntityOneAttributeQuery
(
t
*
testing
.
T
)
{
// Setup for test
// Setup for test
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment