234 rewrite, rqlst, {('C', 'X'): (c1,), |
234 rewrite, rqlst, {('C', 'X'): (c1,), |
235 ('A', 'X'): (c2,), |
235 ('A', 'X'): (c2,), |
236 ('A2', 'X'): (c2,), |
236 ('A2', 'X'): (c2,), |
237 }, {}) |
237 }, {}) |
238 |
238 |
|
239 def test_optional_var_inlined_linked(self): |
|
240 c1 = ('X require_permission P') |
|
241 c2 = ('X inlined_card O, O require_permission P') |
|
242 rqlst = parse('Any A,W WHERE A inlined_card C?, C inlined_note N, ' |
|
243 'N inlined_affaire W') |
|
244 rewrite(rqlst, {('C', 'X'): (c1,)}, {}) |
|
245 self.failUnlessEqual(rqlst.as_string(), |
|
246 'Any A,W WHERE A inlined_card C?, A is Affaire ' |
|
247 'WITH C,N,W BEING (Any C,N,W WHERE C inlined_note N, ' |
|
248 'N inlined_affaire W, EXISTS(C require_permission B), ' |
|
249 'C is Card, N is Note, W is Affaire)') |
|
250 |
239 def test_relation_optimization_1_lhs(self): |
251 def test_relation_optimization_1_lhs(self): |
240 # since Card in_state State as monovalued cardinality, the in_state |
252 # since Card in_state State as monovalued cardinality, the in_state |
241 # relation used in the rql expression can be ignored and S replaced by |
253 # relation used in the rql expression can be ignored and S replaced by |
242 # the variable from the incoming query |
254 # the variable from the incoming query |
243 snippet = ('X in_state S, S name "hop"') |
255 snippet = ('X in_state S, S name "hop"') |
244 rqlst = parse('Card C WHERE C in_state STATE') |
256 rqlst = parse('Card C WHERE C in_state STATE') |
245 rewrite(rqlst, {('C', 'X'): (snippet,)}, {}) |
257 rewrite(rqlst, {('C', 'X'): (snippet,)}, {}) |
246 self.failUnlessEqual(rqlst.as_string(), |
258 self.failUnlessEqual(rqlst.as_string(), |
247 "Any C WHERE C in_state STATE, C is Card, " |
259 "Any C WHERE C in_state STATE, C is Card, " |
248 "EXISTS(STATE name 'hop'), STATE is State") |
260 "EXISTS(STATE name 'hop'), STATE is State") |
|
261 |
249 def test_relation_optimization_1_rhs(self): |
262 def test_relation_optimization_1_rhs(self): |
250 snippet = ('TW subworkflow_exit X, TW name "hop"') |
263 snippet = ('TW subworkflow_exit X, TW name "hop"') |
251 rqlst = parse('WorkflowTransition C WHERE C subworkflow_exit EXIT') |
264 rqlst = parse('WorkflowTransition C WHERE C subworkflow_exit EXIT') |
252 rewrite(rqlst, {('EXIT', 'X'): (snippet,)}, {}) |
265 rewrite(rqlst, {('EXIT', 'X'): (snippet,)}, {}) |
253 self.failUnlessEqual(rqlst.as_string(), |
266 self.failUnlessEqual(rqlst.as_string(), |