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

Add query clause for inner joins #435

Closed
jclark opened this issue Feb 26, 2020 · 1 comment
Closed

Add query clause for inner joins #435

jclark opened this issue Feb 26, 2020 · 1 comment
Assignees
Labels
Area/Lang Relates to the Ballerina language specification Type/Improvement Enhancement to language design

Comments

@jclark
Copy link
Collaborator

jclark commented Feb 26, 2020

A join-clause does an inner equijoin, and implements it as a hash join.

intermediate-clause :=
   ...
   | join-clause

join-clause :=
   "join" typed-binding-pattern "in" expression join-on-condition
join-on-condition := "on" expression "equals" expression

Consider

from X in E1
  join Y in E2 on E3 equals E4
  S

The scope of bindings is as follows:

  • bindings from X are in scope in E3 and S but not E4 or E2
  • bindings from Y are in scope in E4 and S but not E3

A join-clause is executed as follows:

  1. Evaluate the expression following "in" (with nothing extra in scope) resulting in an iterable value c
    1. create an empty hash table that allows multiple entries per key and uses == equality
    2. for each item in c
      1. bind c to typed-binding-pattern resulting in frame f'
      2. evaluate the RHS of "equals" with f' in scope resulting in value k'
      3. add an entry into the hash table from k' to f'
    3. for each input frame f
      4. evaluate the LHS of "equals" with f in scope resulting in value k
      5. for each frame f' with key k in the hash table
      1. emit f augmented with f'
@jclark jclark added Type/Improvement Enhancement to language design Area/Lang Relates to the Ballerina language specification labels Feb 26, 2020
@jclark jclark added this to the 2020R2 milestone Feb 26, 2020
@jclark jclark self-assigned this Feb 26, 2020
@jclark jclark changed the title Add query join clause Add query clause for inner joins Feb 26, 2020
@jclark
Copy link
Collaborator Author

jclark commented Feb 28, 2020

Also need to consider how this will work with event streaming #440.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Lang Relates to the Ballerina language specification Type/Improvement Enhancement to language design
Projects
None yet
Development

No branches or pull requests

1 participant