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
228b5975
Commit
228b5975
authored
3 years ago
by
Kieran van Gaalen
Browse files
Options
Downloads
Patches
Plain Diff
Actual querystruct changes and added tabs
parent
7de47fce
No related branches found
No related tags found
1 merge request
!1
Big merge
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aql/convertQuery2.go
+58
-13
58 additions, 13 deletions
aql/convertQuery2.go
entity/queryStruct.go
+11
-9
11 additions, 9 deletions
entity/queryStruct.go
with
69 additions
and
22 deletions
aql/convertQuery2.go
+
58
−
13
View file @
228b5975
...
@@ -65,47 +65,92 @@ func createQuery(JSONQuery *entity.IncomingQueryJSON) *string {
...
@@ -65,47 +65,92 @@ func createQuery(JSONQuery *entity.IncomingQueryJSON) *string {
switch
element
.
typename
{
switch
element
.
typename
{
case
"entity"
:
case
"entity"
:
entity
:=
JSONQuery
.
Entities
[
element
.
pointer
]
entity
:=
JSONQuery
.
Entities
[
element
.
pointer
]
query
+=
entityToQuery
(
entity
)
query
+=
entityToQuery
(
entity
,
JSONQuery
)
case
"relation"
:
case
"relation"
:
relation
:=
JSONQuery
.
Relations
[
element
.
pointer
]
relation
:=
JSONQuery
.
Relations
[
element
.
pointer
]
query
+=
relationToQuery
(
relation
)
query
+=
relationToQuery
(
relation
,
JSONQuery
)
case
"function"
:
case
"function"
:
function
:=
JSONQuery
.
GroupBys
[
element
.
pointer
]
function
:=
JSONQuery
.
GroupBys
[
element
.
pointer
]
query
+=
functionToQuery
(
function
)
query
+=
functionToQuery
(
function
,
JSONQuery
)
case
"filter"
:
case
"filter"
:
filter
:=
JSONQuery
.
Filters
[
element
.
pointer
]
filter
:=
JSONQuery
.
Filters
[
element
.
pointer
]
query
+=
filterToQuery
(
filter
)
query
+=
filterToQuery
(
filter
,
JSONQuery
)
}
}
}
}
}
}
return
&
query
}
}
func
entityToQuery
(
element
entity
.
QueryEntityStruct
)
string
{
func
entityToQuery
(
element
entity
.
QueryEntityStruct
,
JSONQuery
*
entity
.
IncomingQueryJSON
)
string
{
thisname
:=
fmt
.
Sprintf
(
"e%v"
,
element
.
ID
)
thisname
:=
fmt
.
Sprintf
(
"e%v"
,
element
.
ID
)
ret
:=
createLetFor
(
thisname
,
element
.
Name
)
ret
:=
createLetFor
(
thisname
,
element
.
Name
)
ret
+=
"RETURN x
\n
)"
ret
+=
"
\t
RETURN x
\n
)"
return
ret
return
ret
}
}
func
relationToQuery
(
element
entity
.
QueryRelationStruct
)
string
{
func
relationToQuery
(
element
entity
.
QueryRelationStruct
,
JSONQuery
*
entity
.
IncomingQueryJSON
)
string
{
thisname
:=
fmt
.
Sprintf
(
"
e
%v"
,
element
.
ID
)
thisname
:=
fmt
.
Sprintf
(
"
r
%v"
,
element
.
ID
)
ret
:=
createLetFor
(
thisname
,
element
.
Name
)
ret
:=
createLetFor
(
thisname
,
element
.
Name
)
ret
+=
fmt
.
Sprintf
(
"
\t
FOR y in %v%v
\n
"
)
return
ret
return
ret
}
}
func
functionToQuery
(
element
entity
.
QueryGroupByStruct
)
string
{
func
functionToQuery
(
element
entity
.
QueryGroupByStruct
,
JSONQuery
*
entity
.
IncomingQueryJSON
)
string
{
thisname
:=
fmt
.
Sprintf
(
"
e
%v"
,
element
.
ID
)
thisname
:=
fmt
.
Sprintf
(
"
g
%v"
,
element
.
ID
)
element
element
ret
:=
createLetFor
(
thisname
)
ret
:=
createLetFor
(
thisname
)
return
ret
return
ret
}
}
func
filterToQuery
(
element
entity
.
QueryFilterStruct
)
string
{
func
filterToQuery
(
element
entity
.
QueryFilterStruct
,
JSONQuery
*
entity
.
IncomingQueryJSON
)
string
{
thisname
:=
fmt
.
Sprintf
(
"e%v"
,
element
.
ID
)
thisname
:=
fmt
.
Sprintf
(
"f%v"
,
element
.
ID
)
ret
:=
createLetFor
(
thisname
,
fmt
.
Sprintf
(
"e%v"
,
element
.
FilteredID
))
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
)"
return
ret
return
ret
}
}
func
createLetFor
(
variableName
string
,
enumerableName
string
)
string
{
func
createLetFor
(
variableName
string
,
enumerableName
string
)
string
{
return
"LET "
+
variableName
+
" = (
\n\t
FOR x IN "
+
enumerableName
+
"
\n
"
return
"LET "
+
variableName
+
" = (
\n\t
FOR x IN "
+
enumerableName
+
"
\n
"
}
}
func
typeToPrefix
(
pillType
string
)
string
{
switch
pillType
{
case
"entity"
:
return
"e"
case
"relation"
:
return
"r"
case
"function"
:
return
"g"
case
"filter"
:
return
"f"
default
:
return
""
}
}
func
tryGetFilter
(
toType
string
,
toID
int
,
JSONQuery
*
entity
.
IncomingQueryJSON
)
*
entity
.
QueryFilterStruct
{
for
i
:=
range
JSONQuery
.
Filters
{
filter
:=
JSONQuery
.
Filters
[
i
]
if
filter
.
ToType
==
toType
&&
filter
.
ToID
==
toID
{
return
&
filter
}
}
return
nil
}
func
wordsToLogicalSign
(
word
string
)
string
{
if
word
==
"LT"
{
return
"<"
}
else
if
word
==
"LTE"
{
return
"<="
}
else
if
word
==
"EQ"
{
return
"=="
}
else
if
word
==
"GTE"
{
return
">="
}
else
if
word
==
"NEQ"
{
return
"!="
}
else
{
return
">"
}
}
This diff is collapsed.
Click to expand it.
entity/queryStruct.go
+
11
−
9
View file @
228b5975
...
@@ -51,15 +51,17 @@ type QueryGroupByStruct struct {
...
@@ -51,15 +51,17 @@ type QueryGroupByStruct struct {
}
}
type
QueryFilterStruct
struct
{
type
QueryFilterStruct
struct
{
ID
int
ID
int
FilteredType
string
FromType
string
FilteredID
int
FromID
int
Attribute
string
ToType
string
DataType
string
ToID
int
MatchType
string
Attribute
string
Value
string
DataType
string
InType
string
MatchType
string
InID
int
Value
string
InType
string
InID
int
}
}
// QueryModifierStruct encapsulates a single modifier with its corresponding constraints
// QueryModifierStruct encapsulates a single modifier with its corresponding constraints
...
...
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