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
93123b55
Commit
93123b55
authored
3 years ago
by
Kieran van Gaalen
Browse files
Options
Downloads
Patches
Plain Diff
Started implementing new query conversion
parent
4112813a
No related branches found
No related tags found
1 merge request
!1
Big merge
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aql/convertQuery2.go
+109
-0
109 additions, 0 deletions
aql/convertQuery2.go
with
109 additions
and
0 deletions
aql/convertQuery2.go
0 → 100644
+
109
−
0
View file @
93123b55
/*
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
© Copyright Utrecht University (Department of Information and Computing Sciences)
*/
package
aql
import
(
"errors"
"fmt"
"git.science.uu.nl/graphpolaris/query-conversion/entity"
)
// Version 1.13
/*
ConvertQuery converts an IncomingQueryJSON object into AQL
JSONQuery: *entity.IncomingQueryJSON, the query to be converted to AQL
Returns: *string, the AQL query and a possible error
*/
func
(
s
*
Service
)
ConvertQuery
(
JSONQuery
*
entity
.
IncomingQueryJSON
)
(
*
string
,
error
)
{
// Check to make sure all indexes exist
// The largest possible id for an entity
largestEntityID
:=
len
(
JSONQuery
.
Entities
)
-
1
// The largest possible id for a relation
largestRelationID
:=
len
(
JSONQuery
.
Relations
)
-
1
// Make sure no entity should be returned that is outside the range of that list
for
_
,
e
:=
range
JSONQuery
.
Return
.
Entities
{
// If this entity references an entity that is outside the range
if
e
>
largestEntityID
||
e
<
0
{
return
nil
,
errors
.
New
(
"non-existing entity referenced in return"
)
}
}
// Make sure that no relation mentions a non-existing entity
for
_
,
r
:=
range
JSONQuery
.
Relations
{
if
r
.
EntityFrom
>
largestEntityID
||
r
.
EntityTo
>
largestEntityID
{
return
nil
,
errors
.
New
(
"non-exisiting entity referenced in relation"
)
}
}
// Make sure no non-existing relation is tried to be returned
for
_
,
r
:=
range
JSONQuery
.
Return
.
Relations
{
if
r
>
largestRelationID
||
r
<
0
{
return
nil
,
errors
.
New
(
"non-existing relation referenced in return"
)
}
}
result
:=
createQuery
(
JSONQuery
)
return
result
,
nil
}
/*
createQuery generates a query based on the json file provided
JSONQuery: *entity.IncomingQueryJSON, this is a parsedJSON struct holding all the data needed to form a query,
Return: *string, a string containing the corresponding AQL query and an error
*/
func
createQuery
(
JSONQuery
*
entity
.
IncomingQueryJSON
)
*
string
{
query
:=
""
for
list
:=
range
listoflists
{
for
index
:=
range
listoflists
[
list
]
{
element
:=
listoflists
[
list
][
index
]
switch
element
.
typename
{
case
"entity"
:
entity
:=
JSONQuery
.
Entities
[
element
.
pointer
]
query
+=
entityToQuery
(
entity
)
case
"relation"
:
relation
:=
JSONQuery
.
Relations
[
element
.
pointer
]
query
+=
relationToQuery
(
relation
)
case
"function"
:
function
:=
JSONQuery
.
GroupBys
[
element
.
pointer
]
query
+=
functionToQuery
(
function
)
case
"filter"
:
filter
:=
JSONQuery
.
Filters
[
element
.
pointer
]
query
+=
filterToQuery
(
filter
)
}
}
}
}
func
entityToQuery
(
element
entity
.
QueryEntityStruct
)
string
{
thisname
:=
fmt
.
Sprintf
(
"e%v"
,
element
.
ID
)
ret
:=
createLetFor
(
thisname
,
element
.
Name
)
return
ret
}
func
relationToQuery
(
element
entity
.
QueryRelationStruct
)
string
{
thisname
:=
fmt
.
Sprintf
(
"e%v"
,
element
.
ID
)
ret
:=
createLetFor
(
thisname
,
element
.
Name
)
return
ret
}
func
functionToQuery
(
element
entity
.
QueryGroupByStruct
)
string
{
thisname
:=
fmt
.
Sprintf
(
"e%v"
,
element
.
ID
)
ret
:=
createLetFor
(
thisname
)
return
ret
}
func
filterToQuery
(
element
entity
.
QueryFilterStruct
)
string
{
thisname
:=
fmt
.
Sprintf
(
"e%v"
,
element
.
ID
)
ret
:=
createLetFor
(
thisname
,
fmt
.
Sprintf
(
"e%v"
,
element
.
FilteredID
))
return
ret
}
func
createLetFor
(
variableName
string
,
enumerableName
string
)
string
{
return
"LET "
+
variableName
+
" = (
\n\t
FOR x IN "
+
enumerableName
+
"
\n
"
}
This diff is collapsed.
Click to expand it.
Heijden,T.A.J. van der (Thijs)
@t.a.j.vanderheijden
mentioned in commit
82d6956b
·
3 years ago
mentioned in commit
82d6956b
mentioned in commit 82d6956b25f2a5a9942b9ef3014309c1aefed134
Toggle commit list
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