Skip to content

Commit

Permalink
Ensure nullsmax for descending ordered pools
Browse files Browse the repository at this point in the history
Closes #4709
  • Loading branch information
mattnibs committed Jul 30, 2023
1 parent 16214e2 commit f0ac2e4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
3 changes: 1 addition & 2 deletions compiler/kernel/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion runtime/op/meta/lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
29 changes: 29 additions & 0 deletions runtime/op/meta/ztests/nulls-max.yaml
Original file line number Diff line number Diff line change
@@ -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 "// order $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: |
// order asc
{min:1,max:1,count:1(uint64)}
{min:150,max:null,count:2(uint64)}
// ===
{ts:1}
// order desc
{min:150,max:null,count:2(uint64)}
{min:1,max:1,count:1(uint64)}
// ===
{ts:null}

0 comments on commit f0ac2e4

Please sign in to comment.