Skip to content
Snippets Groups Projects
Commit e15a0ed0 authored by Bouma,C.J. (Chris)'s avatar Bouma,C.J. (Chris)
Browse files

Small push

In case you want to edit stuff
parent e08d00dd
No related branches found
No related tags found
No related merge requests found
package main
import (
<<<<<<< Updated upstream
"query-service/internal/adapters/brokeradapter"
"query-service/internal/drivers/brokerdriver"
"query-service/internal/drivers/keyvaluedriver"
......@@ -10,6 +11,9 @@ import (
"query-service/internal/usecases/databaseinfo"
"query-service/internal/usecases/produce"
"query-service/internal/usecases/request"
=======
"query-service/internal/usecases/convertquery"
>>>>>>> Stashed changes
"query-service/pkg/logger"
)
......@@ -18,32 +22,44 @@ func main() {
logger.Start()
// MARK: Create relevant services
redisService := keyvaluedriver.NewRedisDriver()
// redisService := keyvaluedriver.NewRedisDriver()
<<<<<<< Updated upstream
// Create new rpc driver
rpcDriver := rpcdriver.New()
// MARK: Create alice RabbitMQ services
brokerGateway := brokeradapter.CreateGateway()
aliceBroker := brokerdriver.CreateAliceBroker(brokerGateway)
=======
// // MARK: Create alice RabbitMQ services
// brokerGateway := brokeradapter.CreateGateway()
// aliceBroker := brokerdriver.CreateAliceBroker(brokerGateway)
>>>>>>> Stashed changes
// 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
convertQueryService := convertquery.NewService()
requestSenderService := request.NewService()
// requestSenderService := request.NewService()
<<<<<<< Updated upstream
databaseInfoService := databaseinfo.NewService(rpcDriver)
consumeService := consume.NewService(aliceBroker, produceService, convertQueryService, requestSenderService, databaseInfoService)
=======
// consumeService := consume.NewService(aliceBroker, produceService, convertQueryService, requestSenderService)
>>>>>>> Stashed changes
// // MARK: Start services
// redisService.Start()
// produceService.Start()
// MARK: Start services
redisService.Start()
produceService.Start()
//go consumeService.Start()
go consumeService.Start()
convertQueryService.ConvertQuery(test.json)
select {}
}
......@@ -2,10 +2,17 @@ package entity
// QueryParsedJSON is used for JSON conversion of the incoming byte array
type QueryParsedJSON struct {
<<<<<<< Updated upstream
DatabaseName string
Return QueryReturnStruct
Entities []QueryEntityStruct
Relations []QueryRelationStruct
=======
Return QueryReturnStruct
Entities []QueryEntityStruct
Relations []QueryRelationStruct
Modifiers []QueryModifierStruct
>>>>>>> Stashed changes
// Limit is for limiting the amount of paths AQL will return in a relation let statement
Limit int
......@@ -15,6 +22,7 @@ type QueryParsedJSON struct {
type QueryReturnStruct struct {
Entities []int
Relations []int
Modifiers []int
}
// QueryEntityStruct encapsulates a single entity with its corresponding constraints
......@@ -32,6 +40,14 @@ type QueryRelationStruct struct {
Constraints []QueryConstraintStruct
}
// QueryModifierStruct encapsulates a single modifier with its corresponding constraints
type QueryModifierStruct struct {
Type string
SelectedType string
ID int
AttributeIndex int
}
// QuerySearchDepthStruct holds the range of traversals for the relation
type QuerySearchDepthStruct struct {
Min int
......
......@@ -26,6 +26,8 @@ func (s *Service) ConvertQuery(jsonMsg *[]byte) (*string, *string, error) {
numEntities := len(jsonStruct.Entities) - 1
// How many relations there are
numRelations := len(jsonStruct.Relations) - 1
// How many modifiers there are
numModifiers := len(jsonStruct.Modifiers) - 1
// Make sure no entity should be returned that is outside the range of that list
for _, e := range jsonStruct.Return.Entities {
......@@ -49,6 +51,14 @@ func (s *Service) ConvertQuery(jsonMsg *[]byte) (*string, *string, error) {
}
}
// Make sure no modifier should be returned that is outside the range of that list
for _, m := range jsonStruct.Return.Modifiers {
// If this modifier references an modifier that is outside the range
if m > numModifiers || m < 0 {
return nil, errors.New("non-existing modifier referenced")
}
}
result := createQuery(jsonStruct)
return result, &jsonStruct.DatabaseName, nil
}
......@@ -74,6 +84,38 @@ Parameters: jsonQuery is a parsedJSON struct holding all the data needed to form
Return: a string containing the corresponding AQL query and an error
*/
/*
LET n0 = (FOR x IN airports FILTER x.city == "New York" RETURN x)
LET nodes = first(RETURN UNION_DISTINCT(n0,[],[]))
LET edges = first(RETURN UNION_DISTINCT([],[]))
RETURN {"vertices":nodes, "edges":edges }
LET n0 = (FOR x IN airports FILTER x.city == "New York" RETURN x)
RETURN LENGTH(n0)
LET n0 = (FOR x IN airports FILTER x.city == "New York" RETURN x)
LET r0 = (FOR x IN n0 FOR v, e, p IN 1..1 OUTBOUND x flights OPTIONS { uniqueEdges: "path" }FILTER p.edges[*].Day ALL == 8
LIMIT 5000 RETURN DISTINCT p )
LET nodes = first(RETURN UNION_DISTINCT(flatten(r0[**].vertices), [],[]))
LET edges = first(RETURN UNION_DISTINCT(flatten(r0[**].edges), [],[]))
RETURN {"vertices":nodes, "edges":edges }
LET n0 = (FOR x IN airports FILTER x.city == "New York" RETURN x)
LET r0 = (FOR x IN n0 FOR v, e, p IN 1..1 OUTBOUND x flights OPTIONS { uniqueEdges: "path" }FILTER p.edges[*].Day ALL == 8
RETURN DISTINCT p )
RETURN COUNT(UNIQUE(r0[**].vertices[0]))
*/
func createQuery(jsonQuery *entity.QueryParsedJSON) *string {
// GROTE SIDENOTE:
// Vrij zeker dat een query waar alléén edges worden opgevraagd (#4)
......@@ -117,6 +159,24 @@ func createQuery(jsonQuery *entity.QueryParsedJSON) *string {
relationsToReturn = append(relationsToReturn, relationName)
}
if len(jsonQuery.Return.Modifiers) > 0 {
switch jsonQuery.Modifiers[0].Type {
case "COUNT":
if len(jsonQuery.Return.Relations) > 0 {
ret += "RETURN COUNT(UNIQUE(r0[**].vertices[0]))"
} else {
ret += "RETURN LENGTH(n0)"
}
case "AVG":
ret += ""
case "SUM":
ret += ""
default:
ret += ""
}
return &ret
}
// Add node let statements for nodes that are not yet returned
// Create a set from all the entity-from's and entity-to's, to check if they are returned
nodeSet := make(map[int]bool)
......
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