Skip to content
Snippets Groups Projects
Commit c046b638 authored by sivan's avatar sivan
Browse files

put constraint funcs in file

parent 1c6fe106
No related branches found
No related tags found
No related merge requests found
package main
import (
"query-service/internal/adapters/brokeradapter"
"query-service/internal/drivers/brokerdriver"
"query-service/internal/drivers/keyvaluedriver"
"query-service/internal/usecases/consume"
"fmt"
"query-service/internal/usecases/convertquery"
"query-service/internal/usecases/produce"
"query-service/internal/usecases/request"
"query-service/pkg/logger"
)
func main() {
logger.Start()
// logger.Start()
// MARK: Create relevant services
redisService := keyvaluedriver.NewRedisDriver()
// // MARK: Create relevant services
// redisService := keyvaluedriver.NewRedisDriver()
// MARK: Create alice RabbitMQ services
brokerGateway := brokeradapter.CreateGateway()
aliceBroker := brokerdriver.CreateAliceBroker(brokerGateway)
// // MARK: Create alice RabbitMQ services
// brokerGateway := brokeradapter.CreateGateway()
// aliceBroker := brokerdriver.CreateAliceBroker(brokerGateway)
// Instantiate an implementation of the produce UseCase
produceService := produce.NewService(aliceBroker, redisService)
// // Instantiate an implementation of the produce UseCase
// produceService := produce.NewService(aliceBroker, redisService)
// MARK: Create relevant services for consuming a message
// // MARK: Create relevant services for consuming a message
convertQueryService := convertquery.NewService()
requestSenderService := request.NewService()
consumeService := consume.NewService(aliceBroker, produceService, convertQueryService, requestSenderService)
// MARK: Start services
redisService.Start()
produceService.Start()
go consumeService.Start()
select {}
json := []byte(`{
"return": {
"entities": [
0
],
"relations": [
]
},
"Entities": [
{
"Type": "airports",
"Constraints": [
{
"Attribute": "city",
"Value": "New York",
"DataType": "text",
"MatchType": "exact"
}
]
}
],
"Relations": [
]
}
`)
res, _ := convertQueryService.ConvertQuery(&json)
fmt.Println(*res)
// requestSenderService := request.NewService()
// consumeService := consume.NewService(aliceBroker, produceService, convertQueryService, requestSenderService)
// // MARK: Start services
// redisService.Start()
// produceService.Start()
// go consumeService.Start()
// select {}
}
......@@ -98,9 +98,9 @@ type Constraint = {
// Struct used for JSON conversion
type parsedJSON struct {
Return returnStruct
Entities []entityStruct
Relations []relationStruct
Return returnStruct //`json:"return"`
Entities []entityStruct //`json:"entities"`
Relations []relationStruct //`json:"relations"`
}
type returnStruct struct {
......@@ -601,13 +601,14 @@ func createQuery(jsQuery *parsedJSON) *string {
// Vrij zeker dat een query waar alléén edges worden opgevraagd (#4)
// niet wordt gesupport door zowel de result parser als de frontend reciever
jsonQuery := *jsQuery
// jsonQuery := *jsQuery
// TODO:
// NODES
// EDGES (als ze er zijn)
// RETURN STATEMENT
r := "hoi"
return &r
}
func createNodeLet(node *entityStruct, name *string) *string {
......@@ -654,77 +655,6 @@ func createEdgeLet(edge *relationStruct, name *string) *string {
return &ret
}
func createConstraints(constraints *[]constraintStruct, isRelation bool) *string {
s := ""
if len(*constraints) == 0 {
return &s
}
newLineStatement := "\tFILTER"
for _, v := range *constraints {
s += fmt.Sprintf("%v %v \n", newLineStatement, *createConstraintLine(&v, isRelation))
newLineStatement = "\tAND"
}
return &s
}
func createConstraintLine(constraint *constraintStruct, isRelation bool) *string {
var (
match string
value string
line string
)
//Wicked switches letsgo
switch constraint.DataType {
case "text":
value = fmt.Sprintf("\"%s\"", constraint.Value)
switch constraint.MatchType {
case "contains":
match = "IN"
case "startswith":
match = "LIKE"
value = fmt.Sprintf("\"%s%%\"", constraint.Value)
case "endswith":
match = "LIKE"
value = fmt.Sprintf("\"_%s\"", constraint.Value)
default: //exact
match = "=="
}
case "number":
value = constraint.Value
switch constraint.MatchType {
case "GT":
match = ">"
case "LT":
match = "<"
case "GET":
match = ">="
case "LET":
match = "<="
default: //EQ
match = "=="
}
default: /*bool*/
value = constraint.Value
switch constraint.MatchType {
case "NEQ":
match = "!="
default: //EQ
match = "=="
}
}
if isRelation {
line = fmt.Sprintf("p.edges[*].%s ALL %s %s", constraint.Attribute, match, value)
} else {
line = fmt.Sprintf("x.%s %s %s", constraint.Attribute, match, value)
}
return &line
}
/*
#1
{
......
package convertquery
import "fmt"
func createConstraints(constraints *[]constraintStruct, isRelation bool) *string {
s := ""
if len(*constraints) == 0 {
return &s
}
newLineStatement := "\tFILTER"
for _, v := range *constraints {
s += fmt.Sprintf("%v %v \n", newLineStatement, *createConstraintLine(&v, isRelation))
newLineStatement = "\tAND"
}
return &s
}
func createConstraintLine(constraint *constraintStruct, isRelation bool) *string {
var (
match string
value string
line string
)
//Wicked switches letsgo
switch constraint.DataType {
case "text":
value = fmt.Sprintf("\"%s\"", constraint.Value)
switch constraint.MatchType {
case "contains":
match = "IN"
case "startswith":
match = "LIKE"
value = fmt.Sprintf("\"%s%%\"", constraint.Value)
case "endswith":
match = "LIKE"
value = fmt.Sprintf("\"_%s\"", constraint.Value)
default: //exact
match = "=="
}
case "number":
value = constraint.Value
switch constraint.MatchType {
case "GT":
match = ">"
case "LT":
match = "<"
case "GET":
match = ">="
case "LET":
match = "<="
default: //EQ
match = "=="
}
default: /*bool*/
value = constraint.Value
switch constraint.MatchType {
case "NEQ":
match = "!="
default: //EQ
match = "=="
}
}
if isRelation {
line = fmt.Sprintf("p.edges[*].%s ALL %s %s", constraint.Attribute, match, value)
} else {
line = fmt.Sprintf("x.%s %s %s", constraint.Attribute, match, value)
}
return &line
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment