Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnibs committed Sep 22, 2023
1 parent 0db72a0 commit 74afb32
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
14 changes: 7 additions & 7 deletions compiler/ast/dag/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ type (
Count int `json:"count"`
}
Join struct {
Kind string `json:"kind" unpack:""`
Style string `json:"style"`
LeftKey Expr `json:"left_key"`
LeftSortOrder order.Which `json:"left_sort_order"`
RightKey Expr `json:"right_key"`
RightSortOrder order.Which `json:"right_sort_order"`
Args []Assignment `json:"args"`
Kind string `json:"kind" unpack:""`
Style string `json:"style"`
LeftKey Expr `json:"left_key"`
LeftOrder order.Which `json:"left_order"`
RightKey Expr `json:"right_key"`
RightOrder order.Which `json:"right_order"`
Args []Assignment `json:"args"`
}
Load struct {
Kind string `json:"kind" unpack:""`
Expand Down
2 changes: 1 addition & 1 deletion compiler/kernel/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func (b *Builder) compile(o dag.Op, parents []zbuf.Puller) ([]zbuf.Puller, error
return nil, err
}
leftParent, rightParent := parents[0], parents[1]
leftOrder, rightOrder := o.LeftSortOrder, o.RightSortOrder
leftOrder, rightOrder := o.LeftOrder, o.RightOrder
var anti, inner bool
switch o.Style {
case "anti":
Expand Down
14 changes: 7 additions & 7 deletions compiler/optimizer/optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ func (o *Optimizer) propagateSortKeyOp(op dag.Op, parents []order.SortKey) ([]or
if len(parents) != 2 {
return nil, errors.New("internal error: join does not have two parents")
}
if leftKey := fieldOf(join.LeftKey); leftKey.Equal(parents[0].Primary()) {
join.LeftSortOrder = parents[0].Order
if fieldOf(join.LeftKey).Equal(parents[0].Primary()) {
join.LeftOrder = parents[0].Order
}
if rightKey := fieldOf(join.RightKey); rightKey.Equal(parents[1].Primary()) {
join.RightSortOrder = parents[1].Order
if fieldOf(join.RightKey).Equal(parents[1].Primary()) {
join.RightOrder = parents[1].Order
}
// XXX There is definitely a way to propagate the sort key but there's
// some complexity here. The propagated sort key should be whatever key
Expand All @@ -300,9 +300,9 @@ func (o *Optimizer) propagateSortKeyOp(op dag.Op, parents []order.SortKey) ([]or
// sort order.
return []order.SortKey{order.Nil}, nil
}
// If the op is not a join then condense sort into a single parent, since
// all the ops only care about the sort order of multiple parents if the
// SortKey of all parents is unified.
// If the op is not a join then condense sort order into a single parent,
// since all the ops only care about the sort order of multiple parents if
// the SortKey of all parents is unified.
parent := order.Nil
for k, p := range parents {
if k == 0 {
Expand Down
23 changes: 8 additions & 15 deletions compiler/ztests/join-desc.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
script: |
echo "// join file desc"
zq -z -I file.zed
echo "// join pool desc"
export ZED_LAKE="test"
zq -z -I file.zed > file.zson
export ZED_LAKE=test
zed init -q
zed create -q -use -orderby likes:desc people
zed load -q people.zson
zed create -q -use -orderby flavor:desc fruits
zed load -q fruits.zson
zed query -z -I pool.zed
zed query -z -I pool.zed > pool.zson
inputs:
- name: people.zson
Expand Down Expand Up @@ -36,19 +34,14 @@ inputs:
outputs:
- name: stdout

data: |
// join file desc
data: ""
- name: file.zson
data: &file_zson |
{name:"apple",color:"red",flavor:"tart",eater:"morgan"}
{name:"apple",color:"red",flavor:"tart",eater:"chris"}
{name:"banana",color:"yellow",flavor:"sweet",eater:"quinn"}
{name:"strawberry",color:"red",flavor:"sweet",eater:"quinn"}
{name:"dates",color:"brown",flavor:"sweet",note:"in season",eater:"quinn"}
{name:"figs",color:"brown",flavor:"plain",eater:"jessie"}
// join pool desc
{name:"apple",color:"red",flavor:"tart",eater:"morgan"}
{name:"apple",color:"red",flavor:"tart",eater:"chris"}
{name:"strawberry",color:"red",flavor:"sweet",eater:"quinn"}
{name:"banana",color:"yellow",flavor:"sweet",eater:"quinn"}
{name:"dates",color:"brown",flavor:"sweet",note:"in season",eater:"quinn"}
{name:"figs",color:"brown",flavor:"plain",eater:"jessie"}
- name: pool.zson
data: *file_zson

0 comments on commit 74afb32

Please sign in to comment.