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
18679055
Commit
18679055
authored
3 years ago
by
Geurtjens,D. (Douwe Geurtjens)
Browse files
Options
Downloads
Patches
Plain Diff
ADDED: Joes's changes pushed to the proper repository
parent
1bef7859
No related branches found
No related tags found
1 merge request
!1
Big merge
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
aql/convertQuery.go
+73
-1
73 additions, 1 deletion
aql/convertQuery.go
entity/queryStruct.go
+20
-5
20 additions, 5 deletions
entity/queryStruct.go
main/main.go
+59
-49
59 additions, 49 deletions
main/main.go
with
152 additions
and
55 deletions
aql/convertQuery.go
+
73
−
1
View file @
18679055
...
@@ -8,6 +8,7 @@ package aql
...
@@ -8,6 +8,7 @@ package aql
import
(
import
(
"errors"
"errors"
"fmt"
"fmt"
"strconv"
"git.science.uu.nl/graphpolaris/query-conversion/entity"
"git.science.uu.nl/graphpolaris/query-conversion/entity"
)
)
...
@@ -49,7 +50,13 @@ func (s *Service) ConvertQuery(JSONQuery *entity.IncomingQueryJSON) (*string, er
...
@@ -49,7 +50,13 @@ func (s *Service) ConvertQuery(JSONQuery *entity.IncomingQueryJSON) (*string, er
}
}
}
}
result
:=
createQuery
(
JSONQuery
)
var
result
*
string
if
len
(
JSONQuery
.
Functions
)
==
0
{
result
=
createQuery
(
JSONQuery
)
}
else
{
result
=
createQueryWithFunctions
(
JSONQuery
)
}
return
result
,
nil
return
result
,
nil
}
}
...
@@ -336,3 +343,68 @@ func createRelationLetWithOnlyToEntity(relation *entity.QueryRelationStruct, nam
...
@@ -336,3 +343,68 @@ func createRelationLetWithOnlyToEntity(relation *entity.QueryRelationStruct, nam
ret
:=
header
+
forStatement
+
optionStmtn
+
relationFilterStmnt
+
footer
ret
:=
header
+
forStatement
+
optionStmtn
+
relationFilterStmnt
+
footer
return
&
ret
return
&
ret
}
}
type
variableNameGeneratorToken
struct
{
token
int
}
func
newVariableNameGeneratorToken
()
*
variableNameGeneratorToken
{
v
:=
variableNameGeneratorToken
{
token
:
0
}
return
&
v
}
func
variableNameGenerator
(
vngt
*
variableNameGeneratorToken
)
string
{
result
:=
"variable_"
+
strconv
.
Itoa
(
vngt
.
token
)
vngt
.
token
++
return
result
}
func
createQueryWithFunctions
(
JSONQuery
*
entity
.
IncomingQueryJSON
)
*
string
{
result
:=
""
v
:=
newVariableNameGeneratorToken
()
for
i
:=
0
;
i
<
len
(
JSONQuery
.
Functions
);
i
++
{
if
JSONQuery
.
Functions
[
i
]
.
Type
==
"groupBy"
{
a
:=
variableNameGenerator
(
v
)
b
:=
variableNameGenerator
(
v
)
c
:=
variableNameGenerator
(
v
)
d
:=
variableNameGenerator
(
v
)
e
:=
variableNameGenerator
(
v
)
f
:=
variableNameGenerator
(
v
)
g
:=
variableNameGenerator
(
v
)
h
:=
variableNameGenerator
(
v
)
result
+=
"LET "
+
a
+
" = (FOR r IN "
+
JSONQuery
.
Relations
[
i
]
.
Type
+
" LET "
+
b
+
" = (FOR c IN "
+
JSONQuery
.
Entities
[
JSONQuery
.
Functions
[
i
]
.
GroupID
]
.
Type
+
" FILTER c._id == r._to return c."
+
JSONQuery
.
Functions
[
i
]
.
GroupAttribute
+
") "
+
"LET "
+
c
+
" = "
+
b
+
"[0] LET "
+
d
+
" = ("
+
"FOR p in "
+
JSONQuery
.
Entities
[
JSONQuery
.
Functions
[
i
]
.
ByID
]
.
Type
+
" FILTER p._id == r._from return p."
+
JSONQuery
.
Functions
[
i
]
.
ByAttribute
+
") "
+
"LET "
+
e
+
" = "
+
d
+
"[0] RETURN {
\"
"
+
f
+
"
\"
: "
+
c
+
", "
+
"
\"
"
+
g
+
"
\"
: "
+
e
+
"}) "
+
"FOR r in "
+
a
+
" COLLECT c = r."
+
f
+
" INTO groups = r."
+
g
+
" "
+
"LET "
+
h
+
" = "
+
JSONQuery
.
Functions
[
i
]
.
AppliedModifier
+
"(groups) "
if
len
(
JSONQuery
.
Functions
[
i
]
.
Constraints
)
>
0
{
result
+=
"FILTER "
+
h
+
" "
+
wordsToLogicalSign
(
JSONQuery
.
Functions
[
i
]
.
Constraints
[
0
]
.
MatchType
)
+
" "
+
JSONQuery
.
Functions
[
i
]
.
Constraints
[
0
]
.
Value
+
" "
}
result
+=
"RETURN {"
+
JSONQuery
.
Functions
[
i
]
.
GroupAttribute
+
" : c, "
+
JSONQuery
.
Functions
[
i
]
.
AppliedModifier
+
"_"
+
JSONQuery
.
Functions
[
i
]
.
ByAttribute
+
" : "
+
h
+
"}"
}
}
return
&
result
}
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
{
return
">"
}
}
This diff is collapsed.
Click to expand it.
entity/queryStruct.go
+
20
−
5
View file @
18679055
...
@@ -6,6 +6,7 @@ type IncomingQueryJSON struct {
...
@@ -6,6 +6,7 @@ type IncomingQueryJSON struct {
Return
QueryReturnStruct
Return
QueryReturnStruct
Entities
[]
QueryEntityStruct
Entities
[]
QueryEntityStruct
Relations
[]
QueryRelationStruct
Relations
[]
QueryRelationStruct
Functions
[]
QueryFunctionStruct
// Limit is for limiting the amount of paths AQL will return in a relation let statement
// Limit is for limiting the amount of paths AQL will return in a relation let statement
Limit
int
Limit
int
Modifiers
[]
QueryModifierStruct
Modifiers
[]
QueryModifierStruct
...
@@ -33,6 +34,19 @@ type QueryRelationStruct struct {
...
@@ -33,6 +34,19 @@ type QueryRelationStruct struct {
Constraints
[]
QueryConstraintStruct
Constraints
[]
QueryConstraintStruct
}
}
type
QueryFunctionStruct
struct
{
Type
string
TypeID
int
GroupType
string
GroupID
int
GroupAttribute
string
ByType
string
ByID
int
ByAttribute
string
AppliedModifier
string
Constraints
[]
QueryConstraintStruct
}
// QueryModifierStruct encapsulates a single modifier with its corresponding constraints
// QueryModifierStruct encapsulates a single modifier with its corresponding constraints
type
QueryModifierStruct
struct
{
type
QueryModifierStruct
struct
{
Type
string
// SUM COUNT AVG
Type
string
// SUM COUNT AVG
...
@@ -50,11 +64,12 @@ type QuerySearchDepthStruct struct {
...
@@ -50,11 +64,12 @@ type QuerySearchDepthStruct struct {
// QueryConstraintStruct holds the information of the constraint
// QueryConstraintStruct holds the information of the constraint
// Constraint datatypes
// Constraint datatypes
// string MatchTypes: exact/contains/startswith/endswith
// string MatchTypes: exact/contains/startswith/endswith
// int MatchTypes: GT/LT/EQ
// int MatchTypes: GT/LT/EQ
/
// bool MatchTypes: EQ/NEQ
// bool MatchTypes: EQ/NEQ
type
QueryConstraintStruct
struct
{
type
QueryConstraintStruct
struct
{
Attribute
string
Attribute
string
Value
string
Value
string
DataType
string
DataType
string
MatchType
string
MatchType
string
FunctionPointer
int
}
}
This diff is collapsed.
Click to expand it.
main/main.go
+
59
−
49
View file @
18679055
...
@@ -20,63 +20,73 @@ func main() {
...
@@ -20,63 +20,73 @@ func main() {
queryservice
:=
aql
.
NewService
()
queryservice
:=
aql
.
NewService
()
js
:=
[]
byte
(
`{
js
:=
[]
byte
(
`{
"databaseName": "test",
"return": {
"return": {
"entities": [
"entities": [
0,
1,
2,
3
],
"relations": [
0,
0,
1
1
]
},
"entities": [
{
"type": "kamerleden",
"constraints": []
},
{
"type": "partijen",
"constraints": []
}
,
{
"type": "kamerleden",
"constraints": []
},
{
"type": "commissies",
"constraints": []
}
],
],
"relations": [
"relations": [
{
0
"type": "lid_van",
]
},
"entities": [
{
"type": "parliament",
"constraints": []
},
{
"type": "commissions",
"constraints": []
}
],
"relations": [
{
"type": "part_of",
"depth": {
"depth": {
"min": 1,
"min": 1,
"max": 1
"max": 1
},
},
"entityFrom": 0,
"entityFrom": 0,
"entityTo": 1,
"entityTo": 1,
"constraints": []
"constraints": [],
},
"functionPointer": {
{
"from": -1,
"type": "onderdeel_van",
"to": -1
"depth": {
}
"min": 1,
"max": 1
}
},
],
"entityFrom": 2,
"functions": [
"entityTo": 3,
{
"constraints": []
"type": "groupBy",
}
"typeID": 0,
],
"groupType": "entity",
"limit": 5000,
"groupID": 1,
"modifiers": []
"groupAttribute": "name",
}`
)
"byType": "entity",
"byID": 0,
"byAttribute": "age",
"appliedModifier": "AVG",
"constraints": [
{
"attribute": "age",
"value": "45",
"dataType": "number",
"matchType": "GT",
"functionPointer": {
"from": -1,
"to": -1
}
}
]
}
],
"limit": 5000,
"modifiers": [],
"databaseName": "TweedeKamer"
}
`
)
var
inc
entity
.
IncomingQueryJSON
var
inc
entity
.
IncomingQueryJSON
json
.
Unmarshal
(
js
,
&
inc
)
json
.
Unmarshal
(
js
,
&
inc
)
...
...
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