diff --git a/compiler/kernel/op.go b/compiler/kernel/op.go index d23a49da1c..e536607bb6 100644 --- a/compiler/kernel/op.go +++ b/compiler/kernel/op.go @@ -600,8 +600,7 @@ func (b *Builder) compile(o dag.Op, parents []zbuf.Puller) ([]zbuf.Puller, error if err != nil { return nil, err } - nullsMax := o.Order == order.Asc - cmp := expr.NewComparator(nullsMax, !nullsMax, e).WithMissingAsNull() + cmp := expr.NewComparator(true, o.Order == order.Desc, e).WithMissingAsNull() return []zbuf.Puller{merge.New(b.octx, parents, cmp.Compare)}, nil case *dag.Combine: return []zbuf.Puller{combine.New(b.octx, parents)}, nil diff --git a/runtime/op/meta/lister.go b/runtime/op/meta/lister.go index ee5f9af99a..d7265eec05 100644 --- a/runtime/op/meta/lister.go +++ b/runtime/op/meta/lister.go @@ -104,7 +104,7 @@ func initObjectScan(snap commits.View, sortKey order.SortKey) []*data.Object { } func sortObjects(objects []*data.Object, o order.Which) { - cmp := expr.NewValueCompareFn(o, o == order.Asc) //XXX is nullsMax correct here? + cmp := expr.NewValueCompareFn(o, true) lessFunc := func(a, b *data.Object) bool { aFrom, aTo, bFrom, bTo := &a.Min, &a.Max, &b.Min, &b.Max if o == order.Desc { diff --git a/runtime/op/meta/ztests/nulls-max.yaml b/runtime/op/meta/ztests/nulls-max.yaml new file mode 100644 index 0000000000..e1486092ff --- /dev/null +++ b/runtime/op/meta/ztests/nulls-max.yaml @@ -0,0 +1,29 @@ +# This test ensures that nulls are max for either descending or ascending +# ordered pools + +script: | + export ZED_LAKE=test + zed init -q + for o in asc desc; do + echo "// $o" + zed create -q -use -orderby ts:$o $o + echo '{ts:150} {ts:null}' | zed load -q - + echo '{ts:1}' | zed load -q - + zed query -z "from $o:objects | drop id, size" + echo "// ===" + zed query -z 'head 1' + done + +outputs: + - name: "stdout" + data: | + // asc + {min:1,max:1,count:1(uint64)} + {min:150,max:null,count:2(uint64)} + // === + {ts:1} + // desc + {min:150,max:null,count:2(uint64)} + {min:1,max:1,count:1(uint64)} + // === + {ts:null}