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
73c75936
Commit
73c75936
authored
3 years ago
by
Kieran van Gaalen
Browse files
Options
Downloads
Patches
Plain Diff
Query chaining done
parent
bee9d9aa
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/convertQuery.go
+43
-11
43 additions, 11 deletions
aql/convertQuery.go
with
43 additions
and
11 deletions
aql/convertQuery.go
+
43
−
11
View file @
73c75936
...
...
@@ -59,10 +59,11 @@ createQuery generates a query based on the json file provided
Return: *string, a string containing the corresponding AQL query and an error
*/
func
createQuery
(
JSONQuery
*
entity
.
IncomingQueryJSON
)
*
string
{
query
:=
"
LET result = {
\"
vertices
\"
:[],
\"
edges
\"
:[]}
\n
"
query
:=
""
for
list
:=
range
listoflists
{
for
index
:=
range
listoflists
[
list
]
{
element
:=
listoflists
[
list
][
index
]
fmt
.
Println
(
element
.
typename
)
switch
element
.
typename
{
case
"entity"
:
entity
:=
JSONQuery
.
Entities
[
element
.
pointer
]
...
...
@@ -79,13 +80,26 @@ func createQuery(JSONQuery *entity.IncomingQueryJSON) *string {
}
}
}
unusedRelations
:=
findUnusedRelations
(
JSONQuery
)
if
len
(
unusedRelations
)
>=
0
{
query
+=
"LET nodes = first(RETURN UNION_DISTINCT("
for
i
:=
range
unusedRelations
{
query
+=
"flatten("
+
unusedRelations
[
i
]
+
"[**].vertices),"
}
query
+=
"[],[]))
\n
"
query
+=
"LET edges = first(RETURN UNION_DISTINCT("
for
i
:=
range
unusedRelations
{
query
+=
"flatten("
+
unusedRelations
[
i
]
+
"[**].edges),"
}
query
+=
"[],[]))
\n
RETURN {
\"
vertices
\"
:nodes,
\"
edges
\"
:edges }"
}
return
&
query
}
func
entityToQuery
(
element
entity
.
QueryEntityStruct
,
JSONQuery
*
entity
.
IncomingQueryJSON
)
string
{
thisname
:=
fmt
.
Sprintf
(
"e%v"
,
element
.
ID
)
ret
:=
createLetFor
(
thisname
,
element
.
Name
)
ret
+=
"
\t
RETURN x
\n
)"
ret
+=
"
\t
RETURN x
\n
)
\n
"
return
ret
}
...
...
@@ -114,10 +128,10 @@ func relationToQuery(element entity.QueryRelationStruct, JSONQuery *entity.Incom
ret
+=
fmt
.
Sprintf
(
"
\t
FOR z in %v%v
\n
"
,
typeToPrefix
(
element
.
ToType
),
element
.
ToID
)
}
ret
+=
"
\t
FILTER x._from == y._id AND x._to == z._id
\n
"
ret
+=
"
\t
LET nodes = APPEND(
result.vertices
, [y, z])
\n
"
ret
+=
"
\t
LET nodes = APPEND(
[]
, [y, z])
\n
"
ret
+=
"
\t
RETURN DISTINCT {
\n
"
ret
+=
"
\t\"
edges
\"
: x,
\n
"
ret
+=
"
\t\"
vertices
\"
: nodes
\n\t
}
\n
)"
ret
+=
"
\t\"
vertices
\"
: nodes
\n\t
}
\n
)
\n
"
return
ret
}
...
...
@@ -131,7 +145,7 @@ func filterToQuery(element entity.QueryFilterStruct, JSONQuery *entity.IncomingQ
thisname
:=
fmt
.
Sprintf
(
"f%v"
,
element
.
ID
)
ret
:=
createLetFor
(
thisname
,
fmt
.
Sprintf
(
"%v%v"
,
typeToPrefix
(
element
.
FromType
),
element
.
FromID
))
ret
+=
fmt
.
Sprintf
(
"
\t
FILTER x.%v %v %v
\n
"
,
element
.
Attribute
,
wordsToLogicalSign
((
element
.
MatchType
)),
element
.
Value
)
ret
+=
"
\t
RETURN x
\n
)"
ret
+=
"
\t
RETURN x
\n
)
\n
"
return
ret
}
...
...
@@ -196,14 +210,14 @@ func getTupleVar(element entity.QueryGroupByStruct, JSONQuery *entity.IncomingQu
result
:=
""
thisname
:=
fmt
.
Sprintf
(
"gt%v"
,
element
.
ID
)
result
+=
createLetFor
(
thisname
,
JSONQuery
.
Relations
[
element
.
RelationID
]
.
Name
)
result
+=
createSubVariable
(
"variable_0"
,
"variable_1"
,
fmt
.
Sprintf
(
"r%v"
,
element
.
RelationID
),
"_id"
,
"
r
._to"
,
element
.
ByAttribute
)
result
+=
createSubVariable
(
"variable_2"
,
"variable_3"
,
fmt
.
Sprintf
(
"%v%v"
,
typeToPrefix
(
element
.
GroupType
),
element
.
GroupID
),
"_id"
,
"
r
._to"
,
element
.
GroupAttribute
)
result
+=
createSubVariable
(
"variable_0"
,
"variable_1"
,
fmt
.
Sprintf
(
"r%v
[**].vertices[1]
"
,
element
.
RelationID
),
"_id"
,
"
x
._to"
,
"_id"
)
result
+=
createSubVariable
(
"variable_2"
,
"variable_3"
,
fmt
.
Sprintf
(
"%v%v"
,
typeToPrefix
(
element
.
GroupType
),
element
.
GroupID
),
"_id"
,
"
x
._to"
,
element
.
GroupAttribute
)
result
+=
"
\t
RETURN {
\n\t\t\"
variable_0
\"
: variable_1,
\n\t\t\"
variable_1
\"
: variable_3
\n\t
}
\n
)
\n
"
return
result
}
func
createSubVariable
(
variableName
string
,
variableName2
string
,
forName
string
,
filter1
string
,
filter2
string
,
returnValue
string
)
string
{
result
:=
"
\t
LET "
+
variableName
+
" = (
\n\t
FOR y IN "
+
forName
+
"
\n
"
result
:=
"
\t
LET "
+
variableName
+
" = (
\n\
t\
t
FOR y IN "
+
forName
+
"
\n
"
return
result
+
"
\t\t
FILTER y."
+
filter1
+
" == "
+
filter2
+
"
\n\t\t
RETURN y."
+
returnValue
+
"
\n\t
) "
+
"
\n\t
LET "
+
variableName2
+
" = "
+
variableName
+
"[0]
\n
"
}
...
...
@@ -220,18 +234,36 @@ func createGroupBy(element entity.QueryGroupByStruct, JSONQuery *entity.Incoming
}
}
if
final
{
result
+=
fmt
.
Sprintf
(
"
\t
RETURN {
\n\t
name: c,
\n\t
%v: variable_0
\n\t
}
\n
)"
,
element
.
GroupAttribute
)
result
+=
fmt
.
Sprintf
(
"
\t
RETURN {
\n\t
name: c,
\n\t
%v: variable_0
\n\t
}
\n
)
\n
"
,
element
.
GroupAttribute
)
}
else
{
result
+=
"
\t
RETURN c
\n
)"
result
+=
"
\t
RETURN c
\n
)
\n
"
}
return
result
}
func
createCollect
(
element
entity
.
QueryGroupByStruct
)
string
{
return
"
\t
COLLECT c = x.variable_0 INTO groups = x.variable_1
\n\t
\t
"
+
return
"
\t
COLLECT c = x.variable_0 INTO groups = x.variable_1
\n\t
"
+
"LET variable_0 = "
+
element
.
AppliedModifier
+
"(groups)
\n
"
}
func
createFilter
(
filter
entity
.
QueryFilterStruct
)
string
{
return
"
\t
FILTER variable_0 "
+
wordsToLogicalSign
(
filter
.
MatchType
)
+
" "
+
filter
.
Value
+
"
\n
"
}
func
findUnusedRelations
(
JSONQuery
*
entity
.
IncomingQueryJSON
)
[]
string
{
var
unused
[]
string
for
i
:=
range
JSONQuery
.
Relations
{
relationUnused
:=
true
relation
:=
JSONQuery
.
Relations
[
i
]
for
j
:=
range
JSONQuery
.
GroupBys
{
groupBy
:=
JSONQuery
.
GroupBys
[
j
]
if
groupBy
.
RelationID
==
relation
.
ID
{
relationUnused
=
false
}
}
if
relationUnused
{
unused
=
append
(
unused
,
fmt
.
Sprintf
(
"r%v"
,
relation
.
ID
))
}
}
return
unused
}
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