Skip to content

Commit

Permalink
Fix parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
harshil-goel committed Aug 13, 2024
1 parent 3efeff6 commit 4b937fb
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
19 changes: 19 additions & 0 deletions query/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ func processBinary(mNode *mathTree) error {
return nil
}

// If mpl or mpr have 0 and just 0 in it, that means it's an output of aggregation somewhere.
// This value would need to be applied to all.
checkAggrResult := func(value map[uint64]types.Val) (types.Val, bool) {
if len(value) != 1 {
return types.Val{}, false
}

val, ok := value[0]
return val, ok
}

if val, ok := checkAggrResult(mpl); ok {
cl = val
mpl = nil
} else if val, ok := checkAggrResult(mpr); ok {
cr = val
mpr = nil
}

if len(mpl) != 0 || len(mpr) != 0 {
for k := range mpr {
if err := f(k); err != nil {
Expand Down
47 changes: 47 additions & 0 deletions query/math_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,53 @@ import (
"github.com/dgraph-io/dgraph/types"
)

func TestVector(t *testing.T) {
tree := &mathTree{
Fn: "sqrt",
Child: []*mathTree{{
Fn: "dot",
Child: []*mathTree{
{
Fn: "-",
Child: []*mathTree{
{
Var: "v1",
Val: map[uint64]types.Val{
0: {Tid: 12, Value: []float32{1.0, 2.0}},
},
},
{
Var: "v2",
Val: map[uint64]types.Val{
123: {Tid: 12, Value: []float32{1.0, 2.0}},
},
},
},
},
{
Fn: "-",
Child: []*mathTree{
{
Var: "v1",
Val: map[uint64]types.Val{
0: {Tid: 12, Value: []float32{1.0, 2.0}},
},
},
{
Var: "v2",
Val: map[uint64]types.Val{
123: {Tid: 12, Value: []float32{1.0, 2.0}},
},
},
},
},
},
}},
}

require.NoError(t, evalMathTree(tree))
}

func TestProcessBinary(t *testing.T) {
tests := []struct {
in *mathTree
Expand Down
5 changes: 0 additions & 5 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -1186,11 +1186,6 @@ func (sg *SubGraph) transformVars(doneVars map[string]varValue, path []*SubGraph
continue
}

if val, ok := newMap[0]; ok && len(newMap) == 1 {
mt.Const = val
continue
}

mt.Val = newMap
}
return nil
Expand Down

0 comments on commit 4b937fb

Please sign in to comment.