Skip to content

Commit

Permalink
Starting to add graph mapping via adding annotation graph to system, …
Browse files Browse the repository at this point in the history
…with client side API calls
  • Loading branch information
kellrott committed Jul 15, 2021
1 parent 9158a96 commit 92f033f
Show file tree
Hide file tree
Showing 21 changed files with 759 additions and 359 deletions.
2 changes: 1 addition & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ func init() {
flags.StringVar(&conf.Logger.Formatter, "log-format", conf.Logger.Formatter, "Log format [text, json]")
flags.BoolVar(&conf.Server.RequestLogging.Enable, "log-requests", conf.Server.RequestLogging.Enable, "Log all requests")

flags.StringToStringVarP(&conf.Sources, "er", "e", conf.Sources, "GRIPPER source address" )
flags.StringToStringVarP(&conf.Sources, "er", "e", conf.Sources, "GRIPPER source address")
}
58 changes: 29 additions & 29 deletions engine/core/processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -1182,37 +1182,37 @@ func (agg *aggregate) Process(ctx context.Context, man gdbi.Manager, in gdbi.InP
})

case *gripql.Aggregate_Field:
g.Go(func() error {
fa := a.GetField()
fieldCounts := map[interface{}]int{}
for t := range aChans[a.Name] {
val := jsonpath.TravelerPathLookup(t, fa.Field)
if m, ok := val.(map[string]interface{}); ok {
for k := range m {
fieldCounts[k]++
}
g.Go(func() error {
fa := a.GetField()
fieldCounts := map[interface{}]int{}
for t := range aChans[a.Name] {
val := jsonpath.TravelerPathLookup(t, fa.Field)
if m, ok := val.(map[string]interface{}); ok {
for k := range m {
fieldCounts[k]++
}
}
for term, tcount := range fieldCounts {
out <- &gdbi.Traveler{Aggregation: &gdbi.Aggregate{Name: a.Name, Key: term, Value: float64(tcount)}}
}
return nil
})

case *gripql.Aggregate_Type:
g.Go(func() error {
fa := a.GetType()
fieldTypes := map[string]int{}
for t := range aChans[a.Name] {
val := jsonpath.TravelerPathLookup(t, fa.Field)
tname := gripql.GetFieldType(val)
fieldTypes[tname]++
}
for term, tcount := range fieldTypes {
out <- &gdbi.Traveler{Aggregation: &gdbi.Aggregate{Name: a.Name, Key: term, Value: float64(tcount)}}
}
return nil
})
}
for term, tcount := range fieldCounts {
out <- &gdbi.Traveler{Aggregation: &gdbi.Aggregate{Name: a.Name, Key: term, Value: float64(tcount)}}
}
return nil
})

case *gripql.Aggregate_Type:
g.Go(func() error {
fa := a.GetType()
fieldTypes := map[string]int{}
for t := range aChans[a.Name] {
val := jsonpath.TravelerPathLookup(t, fa.Field)
tname := gripql.GetFieldType(val)
fieldTypes[tname]++
}
for term, tcount := range fieldTypes {
out <- &gdbi.Traveler{Aggregation: &gdbi.Aggregate{Name: a.Name, Key: term, Value: float64(tcount)}}
}
return nil
})

default:
log.Errorf("Error: unknown aggregation type: %T", a.Aggregation)
Expand Down
2 changes: 0 additions & 2 deletions engine/inspect/haslabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ func FindVertexHasLabelStart(pipe []*gripql.GraphStatement) ([]string, []*gripql
return labels, pipe[hasLabelLen:]
}



func FindEdgeHasLabelStart(pipe []*gripql.GraphStatement) ([]string, []*gripql.GraphStatement) {
hasLabelLen := 0
labels := []string{}
Expand Down
2 changes: 1 addition & 1 deletion grids/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/bmeg/grip/gdbi"
"github.com/bmeg/grip/gripql"
"github.com/bmeg/grip/log"
gripSchema "github.com/bmeg/grip/gripql/schema"
"github.com/bmeg/grip/log"
"google.golang.org/protobuf/types/known/structpb"
)

Expand Down
11 changes: 6 additions & 5 deletions gripper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package gripper
import (
"fmt"
"io/ioutil"
"path/filepath"

//"path/filepath"
"encoding/json"

"github.com/bmeg/grip/gripql"
"github.com/ghodss/yaml"
)
Expand All @@ -18,7 +20,7 @@ type Config struct {
type GraphConfig struct {
Vertices map[string]VertexConfig `json:"vertices"`
Edges map[string]EdgeConfig `json:"edges"`
path string
//path string
}

type VertexConfig struct {
Expand Down Expand Up @@ -64,7 +66,7 @@ func LoadConfig(path string) (*GraphConfig, error) {
if err != nil {
return nil, fmt.Errorf("failed to parse config at path %s: \n%v", path, err)
}
conf.path, _ = filepath.Abs(path)
//conf.path, _ = filepath.Abs(path)
return conf, nil
}

Expand All @@ -73,9 +75,8 @@ func ParseConfig(raw []byte, conf *GraphConfig) error {
return yaml.Unmarshal(raw, conf)
}


func GraphToConfig(graph *gripql.Graph) (*GraphConfig, error) {
out := GraphConfig{Vertices:map[string]VertexConfig{}, Edges:map[string]EdgeConfig{}}
out := GraphConfig{Vertices: map[string]VertexConfig{}, Edges: map[string]EdgeConfig{}}
for _, vert := range graph.Vertices {
d := vert.Data.AsMap()
s, _ := json.Marshal(d)
Expand Down
3 changes: 1 addition & 2 deletions gripper/driver_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ func (dc *DriverCache) FetchMatchRows(ctx context.Context, field string, value s
return out, nil
}


type DriverPreLoad struct {
tableCache map[string]*BaseRow
tableKeys []string
Expand All @@ -163,7 +162,7 @@ func (dp *DriverPreLoad) GetFields() ([]string, error) {
for _, row := range dp.tableCache {
for k, v := range row.Value {
if _, ok := v.(string); ok {
fields[k] = true
fields[k] = true
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions gripper/graphdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func NewGDB(conf Config, configPath string, sources map[string]string) (*Tabular
return &out, nil
}


func NewGDBFromGraph(graph *gripql.Graph, sources map[string]string) (*TabularGDB, error) {
out := TabularGDB{map[string]*TabularGraph{}}
if conf, err := GraphToConfig(graph); err == nil {
Expand All @@ -46,7 +45,6 @@ func NewGDBFromGraph(graph *gripql.Graph, sources map[string]string) (*TabularGD
return &out, nil
}


func (g *TabularGDB) AddGraph(string) error {
return fmt.Errorf("AddGraph not implemented")
}
Expand Down
31 changes: 14 additions & 17 deletions gripper/server.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

package gripper

import (
"net"
"context"
"fmt"
"log"
"context"
"fmt"
"log"
"net"

"strings"

"strings"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/structpb"
)

type BaseRow struct {
Expand All @@ -30,12 +30,10 @@ type SimpleTableServicer struct {
drivers map[string]Driver
}


func NewSimpleTableServer(dr map[string]Driver) *SimpleTableServicer {
return &SimpleTableServicer{drivers: dr}
}


func StartServer(port int, serv GRIPSourceServer) {
lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", port))
if err != nil {
Expand All @@ -49,7 +47,6 @@ func StartServer(port int, serv GRIPSourceServer) {
grpcServer.Serve(lis)
}


func (st *SimpleTableServicer) GetCollections(e *Empty, srv GRIPSource_GetCollectionsServer) error {
for n := range st.drivers {
srv.Send(&Collection{Name: n})
Expand All @@ -60,12 +57,12 @@ func (st *SimpleTableServicer) GetCollections(e *Empty, srv GRIPSource_GetCollec
func (st *SimpleTableServicer) GetCollectionInfo(cxt context.Context, col *Collection) (*CollectionInfo, error) {
if dr, ok := st.drivers[col.Name]; ok {
o := []string{}
fields, err := dr.GetFields()
if err != nil {
return nil, err
}
fields, err := dr.GetFields()
if err != nil {
return nil, err
}
for _, f := range fields {
o = append(o, "$." + f)
o = append(o, "$."+f)
}
return &CollectionInfo{SearchFields: o}, nil
}
Expand Down Expand Up @@ -117,7 +114,7 @@ func (st *SimpleTableServicer) GetRowsByField(req *FieldRequest, srv GRIPSource_
if dr, ok := st.drivers[req.Collection]; ok {
field := req.Field
if strings.HasPrefix(field, "$.") {
field = field[2:len(field)]
field = field[2:]
}
ch, _ := dr.FetchMatchRows(srv.Context(), field, req.Value)
for row := range ch {
Expand Down
10 changes: 10 additions & 0 deletions gripql/gripql.pb.dgw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 92f033f

Please sign in to comment.