Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Q
query-service
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
Releases
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
Microservices
query-service
Commits
4621c186
Commit
4621c186
authored
3 years ago
by
thijsheijden
Browse files
Options
Downloads
Patches
Plain Diff
Added check to make sure entityFrom and entityTo can be less than -1
parent
fefab2e2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
internal/usecases/convertquery/aql.go
+4
-10
4 additions, 10 deletions
internal/usecases/convertquery/aql.go
internal/usecases/convertquery/aql_test.go
+48
-0
48 additions, 0 deletions
internal/usecases/convertquery/aql_test.go
with
52 additions
and
10 deletions
internal/usecases/convertquery/aql.go
+
4
−
10
View file @
4621c186
...
...
@@ -92,25 +92,19 @@ func createQuery(jsonQuery *entity.QueryParsedJSON) *string {
for
i
,
relation
:=
range
jsonQuery
.
Relations
{
relationName
:=
fmt
.
Sprintf
(
"r%v"
,
i
)
if
relation
.
EntityFrom
!
=
-
1
{
if
relation
.
EntityFrom
>
=
0
{
// if there is a from-node
// create the let for this node
fromName
:=
fmt
.
Sprintf
(
"n%v"
,
relation
.
EntityFrom
)
// Check if this entity index exists
if
entity
:=
&
jsonQuery
.
Entities
[
relation
.
EntityFrom
];
entity
!=
nil
{
ret
+=
*
createNodeLet
(
entity
,
&
fromName
)
}
ret
+=
*
createNodeLet
(
&
jsonQuery
.
Entities
[
relation
.
EntityFrom
],
&
fromName
)
ret
+=
*
createRelationLetWithFromEntity
(
&
relation
,
relationName
,
&
jsonQuery
.
Entities
,
jsonQuery
.
Limit
)
}
else
if
relation
.
EntityTo
!
=
-
1
{
}
else
if
relation
.
EntityTo
>
=
0
{
// if there is only a to-node
toName
:=
fmt
.
Sprintf
(
"n%v"
,
relation
.
EntityTo
)
// Check if this entity index exists
if
entity
:=
&
jsonQuery
.
Entities
[
relation
.
EntityTo
];
entity
!=
nil
{
ret
+=
*
createNodeLet
(
entity
,
&
toName
)
}
ret
+=
*
createNodeLet
(
&
jsonQuery
.
Entities
[
relation
.
EntityTo
],
&
toName
)
ret
+=
*
createRelationLetWithOnlyToEntity
(
&
relation
,
relationName
,
&
jsonQuery
.
Entities
,
jsonQuery
.
Limit
)
// Add this relation to the list
...
...
This diff is collapsed.
Click to expand it.
internal/usecases/convertquery/aql_test.go
+
48
−
0
View file @
4621c186
...
...
@@ -550,3 +550,51 @@ func TestNoRelationsField(t *testing.T) {
cleanedResult
=
strings
.
ReplaceAll
(
cleanedResult
,
"
\t
"
,
""
)
assert
.
Equal
(
t
,
correctConvertedResult
,
cleanedResult
)
}
func
TestEntityFromLowerThanNegativeOneInRelation
(
t
*
testing
.
T
)
{
// Setup for test
// Create query conversion service
service
:=
NewService
()
query
:=
[]
byte
(
`{
"return": {
"entities": [
0
],
"relations": [
0
]
},
"entities": [
{
"type": "airports",
"constraints": [
{
"attribute": "city",
"value": "San Francisco",
"dataType": "text",
"matchType": "exact"
}
]
}
],
"relations": [
{
"type": "flights",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": -4,
"entityTo": 0,
"constraints": []
}
],
"limit": 5000
}`
)
_
,
err
:=
service
.
ConvertQuery
(
&
query
)
// Assert that there is no error
assert
.
NoError
(
t
,
err
)
}
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