Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
database-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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GraphPolaris
Microservices
database-service
Commits
46a5bdb9
Commit
46a5bdb9
authored
Apr 6, 2021
by
sivan
Browse files
Options
Downloads
Patches
Plain Diff
fix aql conversion json format
parent
286ca322
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/query-service/main.go
+11
-8
11 additions, 8 deletions
cmd/query-service/main.go
internal/aql/aql.go
+119
-44
119 additions, 44 deletions
internal/aql/aql.go
with
130 additions
and
52 deletions
cmd/query-service/main.go
+
11
−
8
View file @
46a5bdb9
...
...
@@ -6,7 +6,6 @@ import (
"log"
"query-service/internal/aql"
"query-service/internal/errorhandler"
"query-service/internal/messagequeue"
"query-service/internal/redisclient"
"query-service/internal/request"
...
...
@@ -18,17 +17,21 @@ import (
var
producer
alice
.
Producer
func
main
()
{
exchangeID
:=
"query-requests"
routingKey
:=
"aql-user-request"
//
exchangeID := "query-requests"
//
routingKey := "aql-user-request"
broker
:=
messagequeue
.
Create
()
messagequeue
.
StartConsumer
(
broker
,
&
exchangeID
,
&
routingKey
,
onMessageReceived
)
//
broker := messagequeue.Create()
//
messagequeue.StartConsumer(broker, &exchangeID, &routingKey, onMessageReceived)
producer
=
messagequeue
.
StartProducer
(
broker
)
//
producer = messagequeue.StartProducer(broker)
redisclient
.
Start
()
// redisclient.Start()
msg
:=
[]
byte
(
`{"Return":{"Entities":[0],"Relations":[0]},"Entities":[{"Type":"Airport","Constraints":[{"Attribute":"month","Value":"8","DataType":"text","MatchType":"exact"}]}],"Relations":[{"Type":"Flight","Depth":{"min":1,"max":3},"EntityFrom":0,"EntityTo":-1,"Constraints":[]}]}`
)
aqlQuery
,
_
:=
aql
.
ConvertJSONToAQL
(
&
msg
)
select
{}
fmt
.
Println
(
*
aqlQuery
)
// select {}
}
...
...
...
...
This diff is collapsed.
Click to expand it.
internal/aql/aql.go
+
119
−
44
View file @
46a5bdb9
...
...
@@ -6,6 +6,80 @@ import (
"strconv"
)
/*
// Query format for exporting to JSON
export type JSONFormat = {
Return: {
Entities: number[];
Relations: number[];
};
Entities: Entity[];
Relations: Relation[];
};
type Entity = {
Type: string;
Constraints: Constraint[];
};
type Relation = {
Type: string;
EntityFrom: number;
EntityTo: number;
Depth: { min: number; max: number };
Constraints: Constraint[];
};
type Constraint = {
Attribute: string;
Value: string;
// Constraint datatypes
// text MatchTypes: exact/contains/startswith/endswith
// number MatchTypes: GT/LT/EQ
// bool MatchTypes: EQ/NEQ
DataType: string;
MatchType: string;
};
{
"Return":{
"Entities":[
0
],
"Relations":[
0
]
},
"Entities":[
{
"Type":"Airport",
"Constraints":[
{
"Attribute":"month",
"Value":"8",
"DataType":"text",
"MatchType":"exact"
}
]
}
],
"Relations":[
{
"Type":"Flight",
"Depth":{
"min":1,
"max":3
},
"EntityFrom":0,
"EntityTo":-1,
"Constraints":[
]
}
]
}
&{{[0] [0]} [] [{Flight 0 -1 {1 3} []}]}
*/
// Constraint datatypes
// text MatchTypes: exact/contains/startswith/endswith
// number MatchTypes: GT/LT/EQ
...
...
@@ -16,7 +90,7 @@ import (
// Struct used for JSON conversion
type
parsedJSON
struct
{
Return
returnStruct
Nodes
[]
node
Struct
Entities
[]
entity
Struct
Relations
[]
relationStruct
}
...
...
@@ -25,16 +99,16 @@ type returnStruct struct {
Relations
[]
int
}
type
node
Struct
struct
{
Node
Type
string
Constraints
map
[
string
]
constraintStruct
type
entity
Struct
struct
{
Type
string
Constraints
[
]
constraintStruct
}
type
relationStruct
struct
{
RelationType
string
Node
From
int
NodeTo
int
Type
string
Entity
From
int
EntityTo
int
Depth
searchDepthStruct
Constraints
map
[
string
]
constraintStruct
Constraints
[
]
constraintStruct
}
type
searchDepthStruct
struct
{
Min
int
...
...
@@ -42,6 +116,7 @@ type searchDepthStruct struct {
}
type
constraintStruct
struct
{
Attribute
string
Value
string
DataType
string
MatchType
string
...
...
@@ -61,16 +136,16 @@ func ConvertJSONToAQL(jsonMsg *[]byte) (*string, error) {
//relations koppelen ze samen
//return statement
result
:=
createAllNodesQuery
(
jsonStruct
.
Return
.
Entities
,
jsonStruct
.
Nod
es
)
result
:=
createAllNodesQuery
(
jsonStruct
.
Return
.
Entities
,
jsonStruct
.
Entiti
es
)
return
result
,
nil
}
func
createAllNodesQuery
(
returnEntitiesIndices
[]
int
,
nodes
[]
node
Struct
)
*
string
{
func
createAllNodesQuery
(
returnEntitiesIndices
[]
int
,
entities
[]
entity
Struct
)
*
string
{
var
result
string
for
node
Index
:=
range
returnEntitiesIndices
{
nodeID
:=
fmt
.
Sprintf
(
"n%s"
,
strconv
.
Itoa
(
node
Index
))
for
_
,
entity
Index
:=
range
returnEntitiesIndices
{
nodeID
:=
fmt
.
Sprintf
(
"n%s"
,
strconv
.
Itoa
(
entity
Index
))
nodeQueryString
:=
*
createNodeQuery
(
&
nodes
[
node
Index
],
nodeID
)
nodeQueryString
:=
*
createNodeQuery
(
&
entities
[
entity
Index
],
nodeID
)
result
+=
fmt
.
Sprintf
(
"
\n
%s"
,
nodeQueryString
)
}
...
...
@@ -79,7 +154,7 @@ func createAllNodesQuery(returnEntitiesIndices []int, nodes []nodeStruct) *strin
}
// createNodeQuery converts the node part of the json to a subquery
func
createNodeQuery
(
node
*
node
Struct
,
name
string
)
*
string
{
func
createNodeQuery
(
node
*
entity
Struct
,
name
string
)
*
string
{
/*
LET alices = (
FOR x IN female
...
...
@@ -99,13 +174,13 @@ func createNodeQuery(node *nodeStruct, name string) *string {
*/
letStatement
:=
fmt
.
Sprintf
(
"LET %s = (
\n
"
,
name
)
forStatement
:=
fmt
.
Sprintf
(
"
\t
FOR x IN %s
\n
"
,
node
.
Node
Type
)
forStatement
:=
fmt
.
Sprintf
(
"
\t
FOR x IN %s
\n
"
,
node
.
Type
)
// Generate all constraints as FILTER statements
first
:=
true
filter
:=
"
\t
FILTER "
for
key
,
constraint
:=
range
node
.
Constraints
{
constraint
:=
createQueryConstraint
(
&
constraint
,
key
)
for
_
,
constraint
:=
range
node
.
Constraints
{
constraint
:=
createQueryConstraint
(
&
constraint
)
if
first
{
filter
+=
fmt
.
Sprintf
(
"
\t
%s "
,
*
constraint
)
...
...
@@ -130,55 +205,55 @@ func createNodeQuery(node *nodeStruct, name string) *string {
// bool MatchTypes: EQ/NEQ
// createQueryConstraint creates a sinlge line of AQL filtering/constraint
func
createQueryConstraint
(
con
*
constraintStruct
,
key
string
)
*
string
{
func
createQueryConstraint
(
con
straint
*
constraintStruct
)
*
string
{
//FILTER x.{CONSTRAINT[0]} {{CONSTRAINT[0]}.MATCHTYPE} {CONSTRAINT[0].VALUE}
// name mtch val + dataType
// name m
a
tch val
ue
+ dataType
var
(
mtch
string
val
string
m
a
tch
string
val
ue
string
line
string
)
//Wicked switches letsgo
switch
con
.
DataType
{
switch
con
straint
.
DataType
{
case
"text"
:
val
=
fmt
.
Sprintf
(
"
\"
%s
\"
"
,
con
.
Value
)
switch
con
.
MatchType
{
val
ue
=
fmt
.
Sprintf
(
"
\"
%s
\"
"
,
con
straint
.
Value
)
switch
con
straint
.
MatchType
{
case
"contains"
:
mtch
=
"IN"
m
a
tch
=
"IN"
case
"startswith"
:
mtch
=
"LIKE"
val
=
fmt
.
Sprintf
(
"
\"
%s%%
\"
"
,
con
.
Value
)
m
a
tch
=
"LIKE"
val
ue
=
fmt
.
Sprintf
(
"
\"
%s%%
\"
"
,
con
straint
.
Value
)
case
"endswith"
:
mtch
=
"LIKE"
val
=
fmt
.
Sprintf
(
"
\"
_%s
\"
"
,
con
.
Value
)
m
a
tch
=
"LIKE"
val
ue
=
fmt
.
Sprintf
(
"
\"
_%s
\"
"
,
con
straint
.
Value
)
default
:
//exact
mtch
=
"=="
m
a
tch
=
"=="
}
case
"number"
:
val
=
con
.
Value
switch
con
.
MatchType
{
val
ue
=
con
straint
.
Value
switch
con
straint
.
MatchType
{
case
"GT"
:
mtch
=
">"
m
a
tch
=
">"
case
"LT"
:
mtch
=
"<"
m
a
tch
=
"<"
case
"GET"
:
mtch
=
">="
m
a
tch
=
">="
case
"LET"
:
mtch
=
"<="
m
a
tch
=
"<="
default
:
//EQ
mtch
=
"=="
m
a
tch
=
"=="
}
default
:
/*bool*/
val
=
con
.
Value
switch
con
.
MatchType
{
val
ue
=
con
straint
.
Value
switch
con
straint
.
MatchType
{
case
"NEQ"
:
mtch
=
"!="
m
a
tch
=
"!="
default
:
//EQ
mtch
=
"=="
m
a
tch
=
"=="
}
}
line
=
fmt
.
Sprintf
(
"x.%s %s %s"
,
key
,
mtch
,
val
)
line
=
fmt
.
Sprintf
(
"x.%s %s %s"
,
constraint
.
Attribute
,
m
a
tch
,
val
ue
)
return
&
line
}
...
...
...
...
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