From b0afec07611ecb8087361687023b9f5e89cd5207 Mon Sep 17 00:00:00 2001 From: Travis Date: Fri, 6 Oct 2017 14:47:56 -0500 Subject: [PATCH] Make sure that outOfRange field predicates return not-null for NEQ queries --- executor.go | 7 ++++++- executor_test.go | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/executor.go b/executor.go index dd9ffc3a8..a620a1145 100644 --- a/executor.go +++ b/executor.go @@ -794,7 +794,7 @@ func (e *Executor) executeFieldRangeSlice(ctx context.Context, index string, c * } baseValue, outOfRange := field.BaseValue(cond.Op, value) - if outOfRange { + if outOfRange && cond.Op != pql.NEQ { return NewBitmap(), nil } @@ -804,6 +804,11 @@ func (e *Executor) executeFieldRangeSlice(ctx context.Context, index string, c * return NewBitmap(), nil } + // outOfRange for NEQ should return all not-null. + if outOfRange && cond.Op == pql.NEQ { + return frag.FieldNotNull(field.BitDepth()) + } + f.Stats.Count("range:field", 1, 1.0) return frag.FieldRange(cond.Op, field.BitDepth(), baseValue) } diff --git a/executor_test.go b/executor_test.go index 130421c00..3ccac27ec 100644 --- a/executor_test.go +++ b/executor_test.go @@ -777,6 +777,13 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { } else if !reflect.DeepEqual([]uint64{SliceWidth, SliceWidth + 1, SliceWidth + 2}, result[0].(*pilosa.Bitmap).Bits()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) } + // NEQ - + if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=other, foo != -20)`), nil, nil); err != nil { + t.Fatal(err) + } else if !reflect.DeepEqual([]uint64{0}, result[0].(*pilosa.Bitmap).Bits()) { + //t.Fatalf("unexpected result: %s", spew.Sdump(result)) + t.Fatalf("unexpected result: %s", result[0].(*pilosa.Bitmap).Bits()) + } }) t.Run("LT", func(t *testing.T) {