Skip to content

Commit

Permalink
Mongo Query pushdown improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Raddon committed Nov 8, 2017
1 parent f5b2328 commit 7cc7f09
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
8 changes: 4 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions backends/mongo/mgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,17 @@ func TestSimpleRowSelect(t *testing.T) {
RowData: &data,
})

validateQuerySpec(t, tu.QuerySpec{
Sql: "select title, count, deleted from article WHERE count = 22 AND `author` = \"aaron\"",
ExpectRowCt: 1,
ValidateRowData: func() {
u.Infof("%v", data)
assert.True(t, data.Deleted == false, "Not deleted? %v", data)
assert.True(t, data.Title == "article1", "%v", data)
},
RowData: &data,
})

return

// The problem here is ?? related to the mysql/mysqlx/type etc, the values are being written
Expand Down
28 changes: 16 additions & 12 deletions backends/mongo/sql_to_mgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,19 +488,9 @@ func (m *SqlToMgo) walkArrayNode(node *expr.ArrayNode, q *bson.M) (value.Value,
//
func (m *SqlToMgo) walkFilterBinary(node *expr.BinaryNode, q *bson.M) (value.Value, error) {

lhval, lhok := m.eval(node.Args[0])
if !lhok {
return nil, fmt.Errorf("Could not evaluate args: %v", node.String())
}
rhval, rhok := vm.Eval(nil, node.Args[1])
if !rhok {
u.Warnf("not ok: %v l:%v r:%v", node, lhval, rhval)
return nil, fmt.Errorf("could not evaluate: %v", node.String())
}
//u.Debugf("walkBinary: %v l:%v r:%v %T %T", node, lhval, rhval, lhval, rhval)
// If we have to recurse deeper for AND, OR operators
switch node.Operator.T {
case lex.TokenLogicAnd:
// this doesn't yet implement x AND y AND z
lhq, rhq := bson.M{}, bson.M{}
_, err := m.walkNode(node.Args[0], &lhq)
_, err2 := m.walkNode(node.Args[1], &rhq)
Expand All @@ -509,8 +499,8 @@ func (m *SqlToMgo) walkFilterBinary(node *expr.BinaryNode, q *bson.M) (value.Val
return nil, fmt.Errorf("could not evaluate: %v", node.String())
}
*q = bson.M{"$and": []bson.M{lhq, rhq}}
return nil, nil
case lex.TokenLogicOr:
// this doesn't yet implement x AND y AND z
lhq, rhq := bson.M{}, bson.M{}
_, err := m.walkNode(node.Args[0], &lhq)
_, err2 := m.walkNode(node.Args[1], &rhq)
Expand All @@ -519,6 +509,20 @@ func (m *SqlToMgo) walkFilterBinary(node *expr.BinaryNode, q *bson.M) (value.Val
return nil, fmt.Errorf("could not evaluate: %v", node.String())
}
*q = bson.M{"$or": []bson.M{lhq, rhq}}
return nil, nil
}

lhval, lhok := m.eval(node.Args[0])
if !lhok {
return nil, fmt.Errorf("Could not evaluate args: %v", node.String())
}
rhval, rhok := m.eval(node.Args[1])
if !rhok {
u.Warnf("not ok: %v l:%v r:%v", node, lhval, rhval)
return nil, fmt.Errorf("could not evaluate: %v", node.String())
}
//u.Debugf("walkBinary: %v l:%v r:%v %T %T", node, lhval, rhval, lhval, rhval)
switch node.Operator.T {
case lex.TokenEqual, lex.TokenEqualEqual:
// The $eq expression is equivalent to { field: <value> }.
if lhval != nil && rhval != nil {
Expand Down

0 comments on commit 7cc7f09

Please sign in to comment.