Skip to content

Commit

Permalink
Dont add ident comparisons to null lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyhb committed Jan 8, 2024
1 parent 446dbfb commit 63ecd3f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ func treeType(p Predicate) TreeType {
case int64, float64:
return TreeTypeBTree
case nil:
// Only allow this if we're not comparing two idents.
if p.LiteralIdent != nil {
return TreeTypeNone
}
return TreeTypeNullMatch
default:
return TreeTypeNone
Expand Down
25 changes: 24 additions & 1 deletion expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ func TestEvaluate_Null(t *testing.T) {
require.NoError(t, err)

e := NewAggregateEvaluator(parser, testBoolEvaluator)

notNull := tex(`event.ts != null`, "id-1")
isNull := tex(`event.ts == null`, "id-2")

Expand Down Expand Up @@ -572,6 +571,30 @@ func TestEvaluate_Null(t *testing.T) {
require.EqualValues(t, 0, count)
})
})

t.Run("Two idents aren't treated as nulls", func(t *testing.T) {
e := NewAggregateEvaluator(parser, testBoolEvaluator)
idents := tex("event.data.a == event.data.b")
ok, err := e.Add(ctx, idents)
require.NoError(t, err)
require.False(t, ok)

require.Equal(t, 1, e.Len())
require.Equal(t, 1, e.ConstantLen())
require.Equal(t, 0, e.AggregateableLen())

eval, count, err := e.Evaluate(ctx, map[string]any{
"event": map[string]any{
"data": map[string]any{
"a": 1,
"b": 1,
},
},
})
require.NoError(t, err)
require.EqualValues(t, 1, len(eval))
require.EqualValues(t, 1, count)
})
}

// tex represents a test Evaluable expression
Expand Down

0 comments on commit 63ecd3f

Please sign in to comment.