Repository: cayleygraph/cayley
Pull request #760 (2019-01-07 21:09:19)

pull for issue 758, label context ignored for saveOpt
I also noticed saveR, had the same issue so I put a test case and fix for that as well.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/cayleygraph/cayley/760)
<!-- Reviewable:end -->


3pCode: Syntax changes made.

Patch:
diff --git a/graph/path/morphism_apply_functions.go b/graph/path/morphism_apply_functions.go
index 7375cbd..ec58868 100644
--- a/graph/path/morphism_apply_functions.go
+++ b/graph/path/morphism_apply_functions.go
@@ -338,7 +338,7 @@ func saveReverseMorphism(via interface{}, tag string) morphism {
 	return morphism{
 		Reversal: func(ctx *pathContext) (morphism, *pathContext) { return saveReverseMorphism(via, tag), ctx },
 		Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) {
-			return shape.SaveVia(in, buildVia(via), tag, true, false), ctx
+			return shape.SaveViaLabels(in, buildVia(via), ctx.labelSet, tag, true, false), ctx
 		},
 		tags: []string{tag},
 	}
@@ -348,7 +348,7 @@ func saveOptionalMorphism(via interface{}, tag string) morphism {
 	return morphism{
 		Reversal: func(ctx *pathContext) (morphism, *pathContext) { return saveOptionalMorphism(via, tag), ctx },
 		Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) {
-			return shape.SaveVia(in, buildVia(via), tag, false, true), ctx
+			return shape.SaveViaLabels(in, buildVia(via), ctx.labelSet, tag, false, true), ctx
 		},
 		tags: []string{tag},
 	}
@@ -358,7 +358,7 @@ func saveOptionalReverseMorphism(via interface{}, tag string) morphism {
 	return morphism{
 		Reversal: func(ctx *pathContext) (morphism, *pathContext) { return saveOptionalReverseMorphism(via, tag), ctx },
 		Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) {
-			return shape.SaveVia(in, buildVia(via), tag, true, true), ctx
+			return shape.SaveViaLabels(in, buildVia(via), ctx.labelSet, tag, true, true), ctx
 		},
 		tags: []string{tag},
 	}


Test patch:
diff --git a/data/testdata_multigraph.nq b/data/testdata_multigraph.nq
new file mode 100644
index 0000000..627635c
--- /dev/null
+++ b/data/testdata_multigraph.nq
@@ -0,0 +1,16 @@
+<alice> <follows> <bob> .
+<bob> <follows> <fred> .
+<bob> <status> "cool_person" .
+<charlie> <follows> <bob> .
+<charlie> <follows> <dani> .
+<dani> <follows> <bob> .
+<dani> <follows> <greg> .
+<dani> <status> "cool_person" .
+<emily> <follows> <fred> .
+<fred> <follows> <greg> .
+<greg> <status> "cool_person" .
+<predicates> <are> <follows> .
+<predicates> <are> <status> .
+<emily> <status> "smart_person" <smart_graph> .
+<greg> <status> "smart_person" <smart_graph> .
+<fred> <status> "smart_person" <other_graph> .
diff --git a/query/gizmo/gizmo_test.go b/query/gizmo/gizmo_test.go
index 2846910..ffe8399 100644
--- a/query/gizmo/gizmo_test.go
+++ b/query/gizmo/gizmo_test.go
@@ -61,12 +61,15 @@ func intVal(v int) string {
 	return quad.Int(v).String()
 }
 
+const multiGraphTestFile = "../../data/testdata_multigraph.nq"
+
 var testQueries = []struct {
 	message string
 	data    []quad.Quad
 	query   string
 	limit   int
 	tag     string
+	file 	string
 	expect  []string
 	err     bool // TODO(dennwc): define error types for Gizmo and handle them
 }{
@@ -597,6 +600,24 @@ var testQueries = []struct {
 		data:   issue718Graph(),
 		expect: issue718Nodes(),
 	},
+	{
+		message: "issue #758. Verify saveOpt respects label context",
+		query: `
+			g.V("<greg>").LabelContext("<smart_graph>").SaveOpt("<status>", "statusTag").All()
+		`,
+		tag:    "statusTag",
+		file: multiGraphTestFile,
+		expect: []string{"smart_person"},
+	},
+	{
+		message: "issue #758. Verify saveR respects label context.",
+		query: `
+			g.V("smart_person").LabelContext("<other_graph>").SaveR("<status>", "who").All()
+		`,
+		tag:    "who",
+		file: multiGraphTestFile,
+		expect: []string{"<fred>"},
+	},
 }
 
 func runQueryGetTag(rec func(), g []quad.Quad, qu string, tag string, limit int) ([]string, error) {
@@ -630,7 +651,10 @@ func runQueryGetTag(rec func(), g []quad.Quad, qu string, tag string, limit int)
 }
 
 func TestGizmo(t *testing.T) {
+
 	simpleGraph := testutil.LoadGraph(t, "../../data/testdata.nq")
+	multiGraph := testutil.LoadGraph(t, multiGraphTestFile)
+
 	for _, test := range testQueries {
 		test := test
 		t.Run(test.message, func(t *testing.T) {
@@ -644,6 +668,10 @@ func TestGizmo(t *testing.T) {
 				test.tag = TopResultTag
 			}
 			quads := simpleGraph
+			if (test.file == multiGraphTestFile){
+				quads = multiGraph
+			}
+			
 			if test.data != nil {
 				quads = test.data
 			}
@@ -736,3 +764,6 @@ func issue718Nodes() []string {
 	}
 	return nodes
 }
+
+
+