Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify in join doc that fields can be copied from the right side without assignment #5206

Merged
merged 1 commit into from
Aug 7, 2024

Conversation

philrz
Copy link
Contributor

@philrz philrz commented Aug 7, 2024

What's changing

A small clarification is being made to the join operator doc.

Why

A community user recently spotted this omission.

Details

In the user's own words from the community Slack thread:

for joins - I feel like the syntax here in the docs could somehow also illustrate that just the name of a field from the right-side can be included without assignment:
now:

<left-input>
| [anti|inner|left|right] join (
 <right-input>
) on <left-key>=<right-key> [<field>:=<right-expr>, ...]

off-the-cuff proposal:

<left-input>
| [anti|inner|left|right] join (
 <right-input>
) on <left-key>=<right-key> [<field>:=<right-expr>, <right-field>, ...]

At first I toyed with updating it to [<field>:=<right-expr>|<right-field>, ...], but that may give the impression that only an explicit right-side field name would be supported, but expressions such as function calls cook up field names on the fly, e.g., this change from the Inner Join example in the join tutorial:

$ zq -z '
file fruit.ndjson | sort flavor
| inner join (
  file people.ndjson | sort likes
) on flavor=likes upper(name)'
{name:"figs",color:"brown",flavor:"plain",upper:"JESSIE"}
{name:"banana",color:"yellow",flavor:"sweet",upper:"QUINN"}
{name:"strawberry",color:"red",flavor:"sweet",upper:"QUINN"}
{name:"dates",color:"brown",flavor:"sweet",note:"in season",upper:"QUINN"}
{name:"apple",color:"red",flavor:"tart",upper:"MORGAN"}
{name:"apple",color:"red",flavor:"tart",upper:"CHRIS"}

So instead I've taken the approach of making the assignment portion appear optional, knowing that errors will further communicate the limitations if the user tries something unworkable, e.g.,

$ zq -z '
file fruit.ndjson | sort flavor
| inner join (
  file people.ndjson | sort likes
) on flavor=likes name+"hi"
'
zq: cannot infer field from expression at line 5, column 19:
) on flavor=likes name+"hi"
                  ~~~~~~~~~
illegal left-hand side of assignment at line 5, column 19:
) on flavor=likes name+"hi"
                  ~~~~~~~~~

@philrz philrz requested a review from a team August 7, 2024 19:15
@philrz philrz self-assigned this Aug 7, 2024
@philrz philrz merged commit 54a5a15 into main Aug 7, 2024
4 checks passed
@philrz philrz deleted the join-doc-no-assign branch August 7, 2024 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants