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

LinkedQL: Fromless Steps #908

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion query/linkedql/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ var unmarshalCases = []struct {
type TestStep struct {
Limit int `json:"limit"`
Tags []string `json:"tags"`
From PathStep `json:"from"`
From PathStep `json:"from" minCardinality:"0"`
Sub []PathStep `json:"sub"`
}

Expand Down
20 changes: 20 additions & 0 deletions query/linkedql/step_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package linkedql

import (
"github.com/cayleygraph/cayley/graph"
"github.com/cayleygraph/cayley/query/path"
"github.com/cayleygraph/quad/voc"
)

// BuildFromPath creates a path of a given from
// In case from is nil defaults to placeholder
func BuildFromPath(qs graph.QuadStore, ns *voc.Namespaces, from PathStep) (*path.Path, error) {
if from == nil {
return path.StartMorphism(), nil
}
fromPath, err := from.BuildPath(qs, ns)
if err != nil {
return nil, err
}
return fromPath, nil
}
2 changes: 1 addition & 1 deletion query/linkedql/steps/as.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (s *As) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *As) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion query/linkedql/steps/back.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (s *Back) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *Back) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions query/linkedql/steps/both.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var _ linkedql.PathStep = (*Both)(nil)

// Both corresponds to .both().
type Both struct {
From linkedql.PathStep `json:"from"`
From linkedql.PathStep `json:"from" minCardinality:"0"`
Properties *linkedql.PropertyPath `json:"properties"`
}

Expand All @@ -26,7 +26,7 @@ func (s *Both) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *Both) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion query/linkedql/steps/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (

// BuildPath implements linkedql.PathStep.
func (s *Collect) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions query/linkedql/steps/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var _ linkedql.PathStep = (*Count)(nil)

// Count corresponds to .count().
type Count struct {
From linkedql.PathStep `json:"from"`
From linkedql.PathStep `json:"from" minCardinality:"0"`
}

// Description implements Step.
Expand All @@ -25,7 +25,7 @@ func (s *Count) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *Count) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion query/linkedql/steps/difference.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (s *Difference) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *Difference) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions query/linkedql/steps/greater_than.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var _ linkedql.PathStep = (*GreaterThan)(nil)

// GreaterThan corresponds to gt().
type GreaterThan struct {
From linkedql.PathStep `json:"from"`
From linkedql.PathStep `json:"from" minCardinality:"0"`
Value quad.Value `json:"value"`
}

Expand All @@ -28,7 +28,7 @@ func (s *GreaterThan) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *GreaterThan) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions query/linkedql/steps/greater_than_equals.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var _ linkedql.PathStep = (*GreaterThanEquals)(nil)

// GreaterThanEquals corresponds to gte().
type GreaterThanEquals struct {
From linkedql.PathStep `json:"from"`
From linkedql.PathStep `json:"from" minCardinality:"0"`
Value quad.Value `json:"value"`
}

Expand All @@ -28,7 +28,7 @@ func (s *GreaterThanEquals) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *GreaterThanEquals) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions query/linkedql/steps/has.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _ linkedql.PathStep = (*Has)(nil)

// Has corresponds to .has().
type Has struct {
From linkedql.PathStep `json:"from"`
From linkedql.PathStep `json:"from" minCardinality:"0"`
Property *linkedql.PropertyPath `json:"property"`
Values []quad.Value `json:"values"`
}
Expand All @@ -28,7 +28,7 @@ func (s *Has) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *Has) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions query/linkedql/steps/has_reverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _ linkedql.PathStep = (*HasReverse)(nil)

// HasReverse corresponds to .hasR().
type HasReverse struct {
From linkedql.PathStep `json:"from"`
From linkedql.PathStep `json:"from" minCardinality:"0"`
Property *linkedql.PropertyPath `json:"property"`
Values []quad.Value `json:"values"`
}
Expand All @@ -28,7 +28,7 @@ func (s *HasReverse) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *HasReverse) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion query/linkedql/steps/intersect.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (s *Intersect) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *Intersect) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions query/linkedql/steps/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var _ linkedql.PathStep = (*Labels)(nil)

// Labels corresponds to .labels().
type Labels struct {
From linkedql.PathStep `json:"from"`
From linkedql.PathStep `json:"from" minCardinality:"0"`
}

// Description implements Step.
Expand All @@ -25,7 +25,7 @@ func (s *Labels) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *Labels) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions query/linkedql/steps/less_than.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var _ linkedql.PathStep = (*LessThan)(nil)

// LessThan corresponds to lt().
type LessThan struct {
From linkedql.PathStep `json:"from"`
From linkedql.PathStep `json:"from" minCardinality:"0"`
Value quad.Value `json:"value"`
}

Expand All @@ -28,7 +28,7 @@ func (s *LessThan) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *LessThan) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions query/linkedql/steps/less_than_equals.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var _ linkedql.PathStep = (*LessThanEquals)(nil)

// LessThanEquals corresponds to lte().
type LessThanEquals struct {
From linkedql.PathStep `json:"from"`
From linkedql.PathStep `json:"from" minCardinality:"0"`
Value quad.Value `json:"value"`
}

Expand All @@ -28,7 +28,7 @@ func (s *LessThanEquals) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *LessThanEquals) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions query/linkedql/steps/like.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _ linkedql.PathStep = (*Like)(nil)

// Like corresponds to like().
type Like struct {
From linkedql.PathStep `json:"from"`
From linkedql.PathStep `json:"from" minCardinality:"0"`
Pattern string `json:"likePattern"`
}

Expand All @@ -27,7 +27,7 @@ func (s *Like) Description() string {

// BuildPath implements PathStep.
func (s *Like) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion query/linkedql/steps/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (s *Limit) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *Limit) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions query/linkedql/steps/optional.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var _ linkedql.PathStep = (*Optional)(nil)

// Optional corresponds to .optional().
type Optional struct {
From linkedql.PathStep `json:"from"`
From linkedql.PathStep `json:"from" minCardinality:"0"`
Step linkedql.PathStep `json:"step"`
}

Expand All @@ -26,7 +26,7 @@ func (s *Optional) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *Optional) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion query/linkedql/steps/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (s *Order) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *Order) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions query/linkedql/steps/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var _ linkedql.PathStep = (*Properties)(nil)

// Properties corresponds to .properties().
type Properties struct {
From linkedql.PathStep `json:"from"`
From linkedql.PathStep `json:"from" minCardinality:"0"`
Names *linkedql.PropertyPath `json:"names"`
}

Expand Down Expand Up @@ -49,7 +49,7 @@ func resolveNames(names *linkedql.PropertyPath) (linkedql.PropertyIRIs, error) {

// BuildPath implements linkedql.PathStep.
func (s *Properties) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions query/linkedql/steps/property_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var _ linkedql.PathStep = (*PropertyNames)(nil)

// PropertyNames corresponds to .propertyNames().
type PropertyNames struct {
From linkedql.PathStep `json:"from"`
From linkedql.PathStep `json:"from" minCardinality:"0"`
}

// Description implements Step.
Expand All @@ -25,7 +25,7 @@ func (s *PropertyNames) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *PropertyNames) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions query/linkedql/steps/property_names_as.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var _ linkedql.PathStep = (*PropertyNamesAs)(nil)

// PropertyNamesAs corresponds to .propertyNamesAs().
type PropertyNamesAs struct {
From linkedql.PathStep `json:"from"`
From linkedql.PathStep `json:"from" minCardinality:"0"`
Tag string `json:"tag"`
}

Expand All @@ -26,7 +26,7 @@ func (s *PropertyNamesAs) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *PropertyNamesAs) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion query/linkedql/steps/regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (s *RegExp) Description() string {

// BuildPath implements PathStep.
func (s *RegExp) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions query/linkedql/steps/reverse_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _ linkedql.PathStep = (*ReverseProperties)(nil)

// ReverseProperties corresponds to .reverseProperties().
type ReverseProperties struct {
From linkedql.PathStep `json:"from"`
From linkedql.PathStep `json:"from" minCardinality:"0"`
Names *linkedql.PropertyPath `json:"names"`
}

Expand All @@ -27,7 +27,7 @@ func (s *ReverseProperties) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *ReverseProperties) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions query/linkedql/steps/reverse_property_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var _ linkedql.PathStep = (*ReversePropertyNames)(nil)

// ReversePropertyNames corresponds to .reversePropertyNames().
type ReversePropertyNames struct {
From linkedql.PathStep `json:"from"`
From linkedql.PathStep `json:"from" minCardinality:"0"`
}

// Description implements Step.
Expand All @@ -25,7 +25,7 @@ func (s *ReversePropertyNames) Description() string {

// BuildPath implements linkedql.PathStep.
func (s *ReversePropertyNames) BuildPath(qs graph.QuadStore, ns *voc.Namespaces) (*path.Path, error) {
fromPath, err := s.From.BuildPath(qs, ns)
fromPath, err := linkedql.BuildFromPath(qs, ns, s.From)
if err != nil {
return nil, err
}
Expand Down
Loading