zed icon indicating copy to clipboard operation
zed copied to clipboard

anti join assignments

Open mccanne opened this issue 4 years ago • 1 comments

The semantic analyzer should check that an anti join does not specify join assignments as the right-hand side is undefined in anti matches. An error should be reported if such assignments appear.

mccanne avatar Feb 07 '22 13:02 mccanne

I think this issue is no longer relevant since with the new join implementation added in #5962 the concept of "assignments" has been removed.

Details

Below is an example of an anti join taken from the Join Tutorial.

With left input fruit.json:

{"name":"apple","color":"red","flavor":"tart"}
{"name":"banana","color":"yellow","flavor":"sweet"}
{"name":"avocado","color":"green","flavor":"savory"}
{"name":"strawberry","color":"red","flavor":"sweet"}
{"name":"dates","color":"brown","flavor":"sweet","note":"in season"}
{"name":"figs","color":"brown","flavor":"plain"}

and right input people.json:

{"name":"morgan","age":61,"likes":"tart"}
{"name":"quinn","age":14,"likes":"sweet","note":"many kids enjoy sweets"}
{"name":"jessie","age":30,"likes":"plain"}
{"name":"chris","age":47,"likes":"tart"}

With an anti join, we'll seek to display which fruits are not liked by anyone. Here's how it looked at super commit f955dc9 right before the changes in #5962 were merged:

$ super -version
Version: f955dc9bf

$ super -c "
file fruit.json
| anti join (
  file people.json
) on flavor=likes"

{name:"avocado",color:"green",flavor:"savory"}

However, if an attempted assignment of a field from the right-hand side was included, it would be quietly swallowed up, hence this issue.

$ super -c "
file fruit.json
| anti join (
  file people.json
) on flavor=likes foo:=bar"

{name:"avocado",color:"green",flavor:"savory"}

Meanwhile on current super commit f86de86 that includes the changes from #5962, this anti join would now typically be implemented like:

$ super -version
Version: f86de86d5

$ super -c "
from fruit.json
| anti join (
  from people.json
) as {fruit,people} on fruit.flavor=people.likes
| values fruit"

{name:"avocado",color:"green",flavor:"savory"}

The user now gets the left/right join outputs (or just the left in this case, since it's an anti join) as embedded records and are free to spread them or pick values out of them in flexible ways as suit their needs, e.g., like we're doing here with values fruit since that provides the expected top-level record. If a user happened to have muscle memory of the former syntax and attempted to invoke assignments as part of the join as was done in the past, that's now a parse error.

$ super -c "
from fruit.json
| anti join (
  from people.json
) as {fruit,people} on fruit.flavor=people.likes foo:=bar
| values fruit"

parse error at line 5, column 50:
) as {fruit,people} on fruit.flavor=people.likes foo:=bar
                                             === ^ ===

I'll hold this one open for some peer review to make sure I'm not missing any other subtleties, but if it passes muster I'll close it out.

philrz avatar Jul 02 '25 23:07 philrz