Skip to content

Commit e7e72b9

Browse files
authored
Revert "Optimize boolean operations between all, any, one, none functions (#555)" (#625)
This reverts commit 3c03e59.
1 parent d9b1093 commit e7e72b9

File tree

3 files changed

+0
-174
lines changed

3 files changed

+0
-174
lines changed

Diff for: optimizer/optimizer.go

-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,5 @@ func Optimize(node *Node, config *conf.Config) error {
3636
Walk(node, &filterLen{})
3737
Walk(node, &filterLast{})
3838
Walk(node, &filterFirst{})
39-
Walk(node, &predicateCombination{})
4039
return nil
4140
}

Diff for: optimizer/optimizer_test.go

-122
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package optimizer_test
22

33
import (
4-
"fmt"
54
"reflect"
65
"strings"
76
"testing"
@@ -340,124 +339,3 @@ func TestOptimize_filter_map_first(t *testing.T) {
340339

341340
assert.Equal(t, ast.Dump(expected), ast.Dump(tree.Node))
342341
}
343-
344-
func TestOptimize_predicate_combination(t *testing.T) {
345-
tests := []struct {
346-
op string
347-
fn string
348-
wantOp string
349-
}{
350-
{"and", "all", "and"},
351-
{"&&", "all", "&&"},
352-
{"or", "all", "or"},
353-
{"||", "all", "||"},
354-
{"and", "any", "and"},
355-
{"&&", "any", "&&"},
356-
{"or", "any", "or"},
357-
{"||", "any", "||"},
358-
{"and", "none", "or"},
359-
{"&&", "none", "||"},
360-
{"and", "one", "or"},
361-
{"&&", "one", "||"},
362-
}
363-
364-
for _, tt := range tests {
365-
rule := fmt.Sprintf(`%s(users, .Age > 18 and .Name != "Bob") %s %s(users, .Age < 30)`, tt.fn, tt.op, tt.fn)
366-
t.Run(rule, func(t *testing.T) {
367-
tree, err := parser.Parse(rule)
368-
require.NoError(t, err)
369-
370-
err = optimizer.Optimize(&tree.Node, nil)
371-
require.NoError(t, err)
372-
373-
expected := &ast.BuiltinNode{
374-
Name: tt.fn,
375-
Arguments: []ast.Node{
376-
&ast.IdentifierNode{Value: "users"},
377-
&ast.ClosureNode{
378-
Node: &ast.BinaryNode{
379-
Operator: tt.wantOp,
380-
Left: &ast.BinaryNode{
381-
Operator: "and",
382-
Left: &ast.BinaryNode{
383-
Operator: ">",
384-
Left: &ast.MemberNode{
385-
Node: &ast.PointerNode{},
386-
Property: &ast.StringNode{Value: "Age"},
387-
},
388-
Right: &ast.IntegerNode{Value: 18},
389-
},
390-
Right: &ast.BinaryNode{
391-
Operator: "!=",
392-
Left: &ast.MemberNode{
393-
Node: &ast.PointerNode{},
394-
Property: &ast.StringNode{Value: "Name"},
395-
},
396-
Right: &ast.StringNode{Value: "Bob"},
397-
},
398-
},
399-
Right: &ast.BinaryNode{
400-
Operator: "<",
401-
Left: &ast.MemberNode{
402-
Node: &ast.PointerNode{},
403-
Property: &ast.StringNode{Value: "Age"},
404-
},
405-
Right: &ast.IntegerNode{Value: 30},
406-
},
407-
},
408-
},
409-
},
410-
}
411-
assert.Equal(t, ast.Dump(expected), ast.Dump(tree.Node))
412-
})
413-
}
414-
}
415-
416-
func TestOptimize_predicate_combination_nested(t *testing.T) {
417-
tree, err := parser.Parse(`any(users, {all(.Friends, {.Age == 18 })}) && any(users, {all(.Friends, {.Name != "Bob" })})`)
418-
require.NoError(t, err)
419-
420-
err = optimizer.Optimize(&tree.Node, nil)
421-
require.NoError(t, err)
422-
423-
expected := &ast.BuiltinNode{
424-
Name: "any",
425-
Arguments: []ast.Node{
426-
&ast.IdentifierNode{Value: "users"},
427-
&ast.ClosureNode{
428-
Node: &ast.BuiltinNode{
429-
Name: "all",
430-
Arguments: []ast.Node{
431-
&ast.MemberNode{
432-
Node: &ast.PointerNode{},
433-
Property: &ast.StringNode{Value: "Friends"},
434-
},
435-
&ast.ClosureNode{
436-
Node: &ast.BinaryNode{
437-
Operator: "&&",
438-
Left: &ast.BinaryNode{
439-
Operator: "==",
440-
Left: &ast.MemberNode{
441-
Node: &ast.PointerNode{},
442-
Property: &ast.StringNode{Value: "Age"},
443-
},
444-
Right: &ast.IntegerNode{Value: 18},
445-
},
446-
Right: &ast.BinaryNode{
447-
Operator: "!=",
448-
Left: &ast.MemberNode{
449-
Node: &ast.PointerNode{},
450-
Property: &ast.StringNode{Value: "Name"},
451-
},
452-
Right: &ast.StringNode{Value: "Bob"},
453-
},
454-
},
455-
},
456-
},
457-
},
458-
},
459-
},
460-
}
461-
462-
assert.Equal(t, ast.Dump(expected), ast.Dump(tree.Node))
463-
}

Diff for: optimizer/predicate_combination.go

-51
This file was deleted.

0 commit comments

Comments
 (0)