Skip to content

Commit

Permalink
refactor: Internal doc restructure (sourcenetwork#471)
Browse files Browse the repository at this point in the history
* Alias internal doc object

* Reduce Select mutation

* Remove unused return param (arb. join)

* Remove extra funcs from MultiNode

* Remove deprecated unit tests

Are hard to maintain with the coming changes, and prod code should be covered by integration tests

* Remove connor unit tests

Maintaining them is not worth the effort with connor now being covered by our integration tests, and the upcoming changes.

* Restructure internal document data structure

* Rework type join to make use of new select

Work could be taken futher by creating a new mapper.relation struct, but would suggest that is out of scope here. Also removes an explain parameter as it is not useful, duplicating info already highly visible in the result whilst using an otherwise dead property.

* Remove dead code from parser package

* I443: Expand deep group filter tests

Looks like case A in the issue was already tested, and the new test passes in develop - so I guess this was just a coverage issue, unless something else fixed it before I448.

* I387: Handle multiple aggregate sources

* I390: Handle multiple aliased joins with filters

Checked test against develop, it failed.  Was a bug and it is now fixed.

* I484: Handle filters on unrendered children

* I495: Handle version select within create

Turned out the bug wasnt really related to this PR (unless there was another bug hiding this one maybe), but I fixed it anyway.
  • Loading branch information
AndrewSisley authored Jun 27, 2022
1 parent e828cef commit 338730a
Show file tree
Hide file tree
Showing 89 changed files with 4,487 additions and 5,630 deletions.
31 changes: 0 additions & 31 deletions connor/and_test.go

This file was deleted.

4 changes: 3 additions & 1 deletion connor/connor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package connor
import (
"fmt"
"strings"

"github.com/sourcenetwork/defradb/core"
)

// Match is the default method used in Connor to match some data to a
// set of conditions.
func Match(conditions, data map[string]interface{}) (bool, error) {
func Match(conditions map[FilterKey]interface{}, data core.Doc) (bool, error) {
return MatchWith("$eq", conditions, data)
}

Expand Down
42 changes: 0 additions & 42 deletions connor/connor_test.go

This file was deleted.

59 changes: 0 additions & 59 deletions connor/contains_test.go

This file was deleted.

30 changes: 10 additions & 20 deletions connor/eq.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package connor

import (
"reflect"
"strings"

"github.com/sourcenetwork/defradb/connor/fields"
"github.com/sourcenetwork/defradb/connor/numbers"
"github.com/sourcenetwork/defradb/core"
)

func init() {
Expand Down Expand Up @@ -34,7 +33,8 @@ func (o *EqualOperator) Evaluate(condition, data interface{}) (bool, error) {
return true, nil
}
}
case []map[string]interface{}:
return false, nil
case []core.Doc:
for _, item := range arr {
m, err := MatchWith("$eq", condition, item)
if err != nil {
Expand All @@ -45,6 +45,7 @@ func (o *EqualOperator) Evaluate(condition, data interface{}) (bool, error) {
return true, nil
}
}
return false, nil
}

switch cn := condition.(type) {
Expand All @@ -65,31 +66,20 @@ func (o *EqualOperator) Evaluate(condition, data interface{}) (bool, error) {
return numbers.Equal(cn, data), nil
case float64:
return numbers.Equal(cn, data), nil
case map[string]interface{}:
case map[FilterKey]interface{}:
m := true
for prop, cond := range cn {
if !m {
// No need to evaluate after we fail
continue
}

if strings.HasPrefix(prop, "$") {
mm, err := MatchWith(prop, cond, data)
if err != nil {
return false, err
}

m = m && mm
} else if d, ok := data.(map[string]interface{}); ok {
mm, err := MatchWith("$eq", cond, fields.TryGet(d, prop))
if err != nil {
return false, err
}

m = m && mm
} else {
return reflect.DeepEqual(condition, data), nil
mm, err := MatchWith(prop.GetOperatorOrDefault("$eq"), cond, prop.GetProp(data))
if err != nil {
return false, err
}

m = m && mm
}

return m, nil
Expand Down
Loading

0 comments on commit 338730a

Please sign in to comment.