82 if not 'relations' in newvar.stinfo: |
82 if not 'relations' in newvar.stinfo: |
83 # not yet initialized |
83 # not yet initialized |
84 newvar.prepare_annotation() |
84 newvar.prepare_annotation() |
85 newvar.stinfo['scope'] = select |
85 newvar.stinfo['scope'] = select |
86 newvar._q_invariant = False |
86 newvar._q_invariant = False |
|
87 select.selection.append(VariableRef(newvar)) |
87 return newvar |
88 return newvar |
88 |
89 |
89 def _fill_to_wrap_rel(var, newselect, towrap, schema): |
90 def _fill_to_wrap_rel(var, newselect, towrap, schema): |
90 for rel in var.stinfo['relations'] - var.stinfo['rhsrelations']: |
91 for rel in var.stinfo['relations'] - var.stinfo['rhsrelations']: |
91 rschema = schema.rschema(rel.r_type) |
92 rschema = schema.rschema(rel.r_type) |
92 if rschema.inlined: |
93 if rschema.inlined: |
93 towrap.add( (var, rel) ) |
94 towrap.add( (var, rel) ) |
94 for vref in rel.children[1].iget_nodes(VariableRef): |
95 for vref in rel.children[1].iget_nodes(VariableRef): |
95 newivar = _new_var(newselect, vref.name) |
96 newivar = _new_var(newselect, vref.name) |
96 newselect.selection.append(VariableRef(newivar)) |
|
97 _fill_to_wrap_rel(vref.variable, newselect, towrap, schema) |
97 _fill_to_wrap_rel(vref.variable, newselect, towrap, schema) |
98 elif rschema.final: |
98 elif rschema.final: |
99 towrap.add( (var, rel) ) |
99 towrap.add( (var, rel) ) |
|
100 for vref in rel.children[1].iget_nodes(VariableRef): |
|
101 newivar = _new_var(newselect, vref.name) |
|
102 newivar.stinfo['attrvar'] = (var, rel.r_type) |
100 |
103 |
101 def rewrite_unstable_outer_join(select, solutions, unstable, schema): |
104 def rewrite_unstable_outer_join(select, solutions, unstable, schema): |
102 """if some optional variables are unstable, they should be selected in a |
105 """if some optional variables are unstable, they should be selected in a |
103 subquery. This function check this and rewrite the rql syntax tree if |
106 subquery. This function check this and rewrite the rql syntax tree if |
104 necessary (in place). Return a boolean telling if the tree has been modified |
107 necessary (in place). Return a boolean telling if the tree has been modified |
114 myunion = Union() |
117 myunion = Union() |
115 myunion.append(newselect) |
118 myunion.append(newselect) |
116 # extract aliases / selection |
119 # extract aliases / selection |
117 newvar = _new_var(newselect, var.name) |
120 newvar = _new_var(newselect, var.name) |
118 newselect.selection = [VariableRef(newvar)] |
121 newselect.selection = [VariableRef(newvar)] |
119 for avar in select.defined_vars.itervalues(): |
|
120 if avar.stinfo['attrvar'] is var: |
|
121 newavar = _new_var(newselect, avar.name) |
|
122 newavar.stinfo['attrvar'] = newvar |
|
123 newselect.selection.append(VariableRef(newavar)) |
|
124 towrap_rels = set() |
122 towrap_rels = set() |
125 _fill_to_wrap_rel(var, newselect, towrap_rels, schema) |
123 _fill_to_wrap_rel(var, newselect, towrap_rels, schema) |
126 # extract relations |
124 # extract relations |
127 for var, rel in towrap_rels: |
125 for var, rel in towrap_rels: |
128 newrel = rel.copy(newselect) |
126 newrel = rel.copy(newselect) |