-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Variable resolution currently checks the local bindings and then searches the global context for each lookup:
| let value = Bindings::get(bindings, &self.name).or_else(|| ctx.bindings().get(&self.name)); |
There is currently no way to perform the global lookup first and then the local binding lookup that is required when a variable or path in the FROM source is unqualified as specified in section 10 of the spec. This is apparent in a test case such as:
-- assuming a global table is defined as `foo`
SELECT a FROM foo, foo AS t2
The LHS of the cross join will be correct in pulling foo from the globals since the local bindings are empty. This will put foo in the local bindings. However the RHS of the cross join should check globals first (from section 10 of the spec) but will check the locals bindings first due to the current variable reference implementation.
Another consequence of the current modeling of variable references is that dynamic lookup will check the global context for every local variable lookup. For instance if we have some dynamic lookup of [path(local(a)), path(local(b)), path(local(c)), varref(global(d))], the actual lookup will do something like:
- local lookup of a; if nothing, then global lookup of a
- if nothing, local lookup of b; if nothing, then global lookup of b
- if nothing, local lookup of c; if nothing, then global lookup of c
- if nothing, global lookup of d
- else Missing
when it should be something like:
- local lookup of a
- if nothing, local lookup of b
- if nothing, local lookup of c
- if nothing, global lookup of d
- else Missing