Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Feature/server func #310

Open
wants to merge 79 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
f1d7c92
Starting to prototype flatMap method and conformance testing
kellrott Apr 12, 2024
6d8a8b0
Adding preliminary flatMap method and conformance test
kellrott Apr 12, 2024
79bf933
Adding a missing file
kellrott Apr 12, 2024
52d5a1c
Adding context variable to go client traversal
kellrott Apr 11, 2024
c7f434b
Adds jobC to gripql client
matthewpeterkort May 14, 2024
5868c2e
update to golangv1.21.12
matthewpeterkort Jul 12, 2024
bdd4e42
adds broken grip deps for reproducing error
matthewpeterkort Jul 15, 2024
73e8771
update to 1.22.5
matthewpeterkort Jul 15, 2024
6b28e4a
protoc, lint updates
matthewpeterkort Jul 15, 2024
46a73c8
Fix code, tests to work with updated cast package
matthewpeterkort Jul 16, 2024
c5dbf58
fixes
matthewpeterkort Jul 16, 2024
5291779
fix Mongo test
matthewpeterkort Jul 17, 2024
7eb97da
fix
matthewpeterkort Jul 17, 2024
d707b00
bugfix
matthewpeterkort Jul 17, 2024
32caaa2
Address feedback
matthewpeterkort Jul 18, 2024
4ae966b
Adding bulk delete
matthewpeterkort Aug 2, 2024
d885dba
Adding server functions
matthewpeterkort Aug 2, 2024
94c958e
package up
matthewpeterkort Aug 5, 2024
445bb68
debug statements
matthewpeterkort Aug 5, 2024
42d7b57
Make bulk del a unary operation
matthewpeterkort Aug 6, 2024
dd48657
fix bulk delete
matthewpeterkort Aug 6, 2024
c2762a8
adds test
matthewpeterkort Aug 6, 2024
b396c3b
Adding pivot method to query engine
kellrott Jun 15, 2024
92ee8e4
Adding test files
kellrott Jun 15, 2024
dd46f97
Working on support for mongo engine compiler
kellrott Jun 15, 2024
0b97c4b
Switching pivot to key/value storage based system
kellrott Jun 20, 2024
56814e5
Working on the docs
kellrott Jul 19, 2024
d73b7b3
Adding `_id` field to pivot outputs
kellrott Jul 30, 2024
cc40758
Fixing _id output
kellrott Jul 30, 2024
7ef8820
update test
matthewpeterkort Aug 7, 2024
c269697
fix proto
matthewpeterkort Aug 7, 2024
70d023f
Optimize Mongo bulk delete
matthewpeterkort Aug 8, 2024
99f91e9
fix protoc body
matthewpeterkort Aug 12, 2024
4d17217
fix mongo test
matthewpeterkort Aug 12, 2024
82a18af
add suggested args
matthewpeterkort Aug 12, 2024
53b6a98
Adds support for sqlite
matthewpeterkort Sep 17, 2024
9b23795
update test workflow
matthewpeterkort Sep 17, 2024
1624103
fix action test names
matthewpeterkort Sep 17, 2024
a83b189
Start JSON schema loader into grip graph
matthewpeterkort Oct 22, 2024
2e52d3f
Add support for extensions
matthewpeterkort Oct 22, 2024
03a12d5
cleanup vertex generation
matthewpeterkort Oct 23, 2024
f5c4fff
Add edge generation
matthewpeterkort Oct 23, 2024
831d8ba
Adds schema load command
matthewpeterkort Nov 1, 2024
f5ba25b
start implement json load
matthewpeterkort Nov 1, 2024
5046b40
working json loader
matthewpeterkort Nov 13, 2024
2ae1fa7
cleanup, add support for graph and project-id customization
matthewpeterkort Nov 14, 2024
7afa49b
Adds tests, new schema load method
matthewpeterkort Nov 15, 2024
435ffaa
trim down test data size
matthewpeterkort Nov 15, 2024
641c1de
bug fix
matthewpeterkort Nov 15, 2024
65b0deb
bug fix
matthewpeterkort Nov 15, 2024
356605c
cleanup
matthewpeterkort Nov 15, 2024
67ba348
fix schema dataset
matthewpeterkort Nov 15, 2024
be4353e
fix logs
matthewpeterkort Nov 15, 2024
44a0a68
Bug fix auth test
matthewpeterkort Nov 18, 2024
40fe427
Adds more tests
matthewpeterkort Nov 18, 2024
a84068d
Add server err message response
matthewpeterkort Nov 19, 2024
d977498
fix tests
matthewpeterkort Nov 19, 2024
452b568
Remove elasticSearch from grip
matthewpeterkort Nov 20, 2024
d035b9e
Bugfix protobuf definition
matthewpeterkort Nov 20, 2024
3a127fa
bugfix, rename cmd
matthewpeterkort Nov 22, 2024
c78ee2b
factor out project_id into an optional extra arg
matthewpeterkort Nov 30, 2024
dbd4ad2
fix docs hostname and schema import name
matthewpeterkort Dec 3, 2024
5eb9fb5
fix double slash in paths
matthewpeterkort Dec 4, 2024
c6147ee
remove extra file
matthewpeterkort Dec 4, 2024
811485e
Flesh out jsonschema to graphql schema command
matthewpeterkort Dec 10, 2024
1d64c3f
fixup graphql schema generation
matthewpeterkort Dec 11, 2024
183ba62
fix up cmd args to work with jsonschemagraph changes
matthewpeterkort Dec 11, 2024
2cf518c
Make go.mod versions compatible with grip plugin versions and move gr…
matthewpeterkort Dec 12, 2024
5879083
Add support for yaml schemas, change AddSchema to an upsert operation
matthewpeterkort Jan 2, 2025
4349dfb
clean up / improve tests
matthewpeterkort Jan 2, 2025
288b643
cleanup
matthewpeterkort Jan 2, 2025
c01aa4b
cleanup
matthewpeterkort Jan 2, 2025
a5f6733
Add gripql query function calls
matthewpeterkort Jan 2, 2025
06e790c
Starting to prototype flatMap method and conformance testing
kellrott Apr 12, 2024
39decf0
Adding preliminary flatMap method and conformance test
kellrott Apr 12, 2024
0fa6529
Merge branch 'develop' into feature/server-func
matthewpeterkort Jan 4, 2025
928a38d
rebase fixes
matthewpeterkort Jan 4, 2025
66465ea
Add command line args to server func
matthewpeterkort Jan 5, 2025
7a9207d
Add support for console.log
matthewpeterkort Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Example:
}

log.Debugf("Query: %s\n", query.String())

res, err := conn.Traversal(context.Background(), query)
if err != nil {
log.Errorf("Traversal error: %s", err)
Expand Down
42 changes: 42 additions & 0 deletions conformance/tests/ot_serverfunc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
def test_flatmap(man):
attr_len_func = """
function attr_len(x, args) {
x["skin_colors_len"] = x["skin_colors"].length;
x["hair_colors_len"] = x["hair_colors"].length;
x["eye_colors_len"] = x["eye_colors"].length;
return [x]
}
"""

errors = []

G = man.setGraph("swapi")

count = 0
q = G.query().V().hasLabel("Species").flatMap("attr_len", attr_len_func, {})
for row in q:
count += 1
if row["data"]["skin_colors_len"] != len(row["data"]["skin_colors"]):
errors.append("count function not correct")
if count != 5:
errors.append("Incorrect row count returned: %d != 5" % (count))
return errors


def test_command_line_args(man):
func = """
function AddObj(x, args) {
for (var k in args){
x[k]= args[k]
}
return [x]
}
"""

errors = []
G = man.setGraph("swapi")
q = G.query().V().hasLabel("Species").flatMap("AddObj", func, {"OtherSpecies":["Sullustan", "RathStar", "Bith"]})
for row in q:
if "OtherSpecies" not in row['data'] or not all(species in row['data']["OtherSpecies"] for species in ["Sullustan", "RathStar", "Bith"]):
errors.append("Appended items '{'OtherSpecies':['Sullustan', 'RathStar', 'Bith']}' Not Present in row")
return errors
85 changes: 85 additions & 0 deletions engine/core/processors_func.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package core

import (
"context"

"github.com/bmeg/grip/gdbi"
"github.com/bmeg/grip/log"
"github.com/dop251/goja"
)

// LookupVerts starts query by looking on vertices
type FlatMap struct {
Source string
Func_name string
Args map[string]any
}

// Process LookupVerts
func (fm *FlatMap) Process(ctx context.Context, man gdbi.Manager, in gdbi.InPipe, out gdbi.OutPipe) context.Context {

vm := goja.New()

// Add support for console.log for debugging purposes
console := vm.NewObject()
_ = console.Set("log", func(call goja.FunctionCall) goja.Value {
args := make([]any, len(call.Arguments))
for i, arg := range call.Arguments {
args[i] = arg.Export()
}
log.Infof("JS log: %v", args...)
return goja.Undefined()
})
_ = vm.Set("console", console)

_, err := vm.RunString(fm.Source)
if err != nil {
log.Errorf("User function compile error: %s", err)
}

jobj := vm.Get(fm.Func_name)
if jobj == nil {
log.Errorf("User Function not found: %s", fm.Func_name)
}

jfunc, ok := goja.AssertFunction(jobj)
if !ok {
log.Errorf("Defined object not function: %#v", jobj)
}
go func() {
defer close(out)
for t := range in {
if t.IsSignal() {
out <- t
continue
}
if jfunc != nil {
src := t.GetCurrent().Get()
data := src.ToDict()
dataObj := vm.ToValue(data)

argsObj := vm.ToValue(fm.Args)

fout, err := jfunc(goja.Null(), dataObj, argsObj)

if err == nil {
o := fout.Export()
if oList, ok := o.([]any); ok {
for _, od := range oList {
if om, ok := od.(map[string]any); ok {
d := gdbi.DataElement{}
d.FromDict(om)
d.ID = src.ID
d.Label = src.Label
out <- t.AddCurrent(&d)
}
}
}
} else {
log.Errorf("Function error: %s", err)
}
}
}
}()
return ctx
}
4 changes: 4 additions & 0 deletions engine/core/statement_compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ func (sc *DefaultStmtCompiler) Aggregate(stmt *gripql.GraphStatement_Aggregate,
return &aggregate{stmt.Aggregate.Aggregations}, nil
}

func (sc *DefaultStmtCompiler) FlatMap(stmt *gripql.GraphStatement_FlatMap, ps *gdbi.State) (gdbi.Processor, error) {
return &FlatMap{Source: stmt.FlatMap.Source, Func_name: stmt.FlatMap.Function, Args: stmt.FlatMap.Args.AsMap()}, nil
}

func (sc *DefaultStmtCompiler) Custom(gs *gripql.GraphStatement, ps *gdbi.State) (gdbi.Processor, error) {

switch stmt := gs.GetStatement().(type) {
Expand Down
2 changes: 2 additions & 0 deletions gdbi/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,7 @@ type StatementCompiler interface {
Fields(gs *gripql.GraphStatement_Fields, ps *State) (Processor, error)
Aggregate(gs *gripql.GraphStatement_Aggregate, ps *State) (Processor, error)

FlatMap(gs *gripql.GraphStatement_FlatMap, ps *State) (Processor, error)

Custom(gs *gripql.GraphStatement, ps *State) (Processor, error)
}
3 changes: 3 additions & 0 deletions gdbi/statement_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ func StatementProcessor(
case *gripql.GraphStatement_Unwind:
return sc.Unwind(stmt, ps)

case *gripql.GraphStatement_FlatMap:
return sc.FlatMap(stmt, ps)

case *gripql.GraphStatement_Fields:
if ps.LastType != VertexData && ps.LastType != EdgeData {
return nil, fmt.Errorf(`"fields" statement is only valid for edge or vertex types not: %s`, ps.LastType.String())
Expand Down
Loading
Loading