cayleygraph / cayleygraph/cayley

Filter path by empty label field (FilterContext)

Open
#977 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
15.1k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

Example program:

```go
package main

import (
"fmt"

"github.com/cayleygraph/cayley"
"github.com/cayleygraph/quad"
)

func main() {
store, err := cayley.NewMemoryGraph()
if err != nil {
panic(err)
}

store.AddQuad(quad.MakeIRI("node1", "predicate", "node2", ""))
store.AddQuad(quad.MakeIRI("node1", "predicate", "node3", "myvalue"))
store.AddQuad(quad.MakeIRI("node1", "predicate", "node4", "othervalue"))

// Expected output,
p := cayley.
StartPath(store, quad.IRI("node1")).
// TODO: limit to just node2 (empty label field)
// LabelContext(""). - doesn't work, lists none
// LabelContext(quad.IRI("")). - doesn't work, lists none
// LabelContext(quad.Raw("")). - doesn't work, lists node3 and node4 (???)
// LabelContext(nil). - doesn't work, lists node3 and node4 (??)
Out(quad.IRI("predicate"))
it := p.Iterate(nil)
err = it.EachValue(nil, func(value quad.Value) error {
nativeValue := quad.NativeOf(value) // this converts RDF values to normal Go types
fmt.Println(nativeValue)
return nil
})
if err != nil {
fmt.Println(err.Error())
}
}
```

None of these successfully limit to just the quad with the empty Label:

```
// LabelContext(""). - doesn't work, lists none
// LabelContext(quad.IRI("")). - doesn't work, lists none
// LabelContext(quad.Raw("")). - doesn't work, lists node3 and node4 (???)
// LabelContext(nil). - doesn't work, lists node3 and node4 (??)
```

How can I do that?

Additionally, I don't understand why empty string "" and nil both return the values that have populated Label fields but not the one that has an empty Label field. Shouldn't it be the other way around?

Contributor guide

Open the contributing guide

Research direction

Start with the Go example and reproduce the behavior using StartPath, Out, and each LabelContext form shown. Trace LabelContext and label matching to determine how an empty label is represented and filtered. Done means the query returns only node2 and the behavior of empty string versus nil is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.