Merge lp:~zorba-coders/zorba/expr-matching into lp:zorba

Proposed by Markos Zaharioudakis
Status: Merged
Approved by: Markos Zaharioudakis
Approved revision: 11156
Merged at revision: 11250
Proposed branch: lp:~zorba-coders/zorba/expr-matching
Merge into: lp:zorba
Diff against target: 411 lines (+341/-7)
7 files modified
src/compiler/rewriter/rules/index_matching_rule.cpp (+16/-7)
test/rbkt/ExpCompilerResults/IterPlan/zorba/index/match_veq_09.iter (+113/-0)
test/rbkt/ExpCompilerResults/IterPlan/zorba/index/match_veq_10.iter (+119/-0)
test/rbkt/Queries/zorba/index/match_veq_09.xq (+31/-0)
test/rbkt/Queries/zorba/index/match_veq_09.xqlib (+15/-0)
test/rbkt/Queries/zorba/index/match_veq_10.xq (+31/-0)
test/rbkt/Queries/zorba/index/match_veq_10.xqlib (+16/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/expr-matching
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Approve
Review via email: mp+149949@code.launchpad.net

Commit message

enhanced index key matching

Description of the change

enhanced index key matching

To post a comment you must log in.
lp:~zorba-coders/zorba/expr-matching updated
11156. By Markos Zaharioudakis

enhanced index key matching

Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job expr-matching-2013-02-21T22-46-52.532Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/compiler/rewriter/rules/index_matching_rule.cpp'
2--- src/compiler/rewriter/rules/index_matching_rule.cpp 2013-02-21 06:30:02 +0000
3+++ src/compiler/rewriter/rules/index_matching_rule.cpp 2013-02-21 22:44:24 +0000
4@@ -967,6 +967,9 @@
5 expr* vexpr,
6 expr::substitution_t& subst)
7 {
8+ TypeManager* tm = qexpr->get_type_manager();
9+ RootTypeManager& rtm = GENV_TYPESYSTEM;
10+
11 if (qexpr->get_expr_kind() == promote_expr_kind &&
12 vexpr->get_expr_kind() == promote_expr_kind)
13 {
14@@ -975,9 +978,6 @@
15 xqtref_t qtype = qe->get_return_type();
16 xqtref_t vtype = ve->get_target_type();
17
18- TypeManager* tm = qe->get_type_manager();
19- RootTypeManager& rtm = GENV_TYPESYSTEM;
20-
21 if (TypeOps::is_subtype(tm, *vtype, *qtype) ||
22 (TypeOps::is_subtype(tm, *qtype, *rtm.UNTYPED_ATOMIC_TYPE_STAR) &&
23 TypeOps::is_subtype(tm, *vtype, *rtm.STRING_TYPE_STAR)))
24@@ -994,10 +994,7 @@
25 xqtref_t qtype = qexpr->get_return_type();
26 xqtref_t vtype = ve->get_target_type();
27
28- TypeManager* tm = qexpr->get_type_manager();
29- RootTypeManager& rtm = GENV_TYPESYSTEM;
30-
31- if (TypeOps::is_subtype(tm, *qtype, *vtype) ||
32+ if (TypeOps::is_subtype(tm, *vtype, *qtype) ||
33 (TypeOps::is_subtype(tm, *qtype, *rtm.UNTYPED_ATOMIC_TYPE_STAR) &&
34 TypeOps::is_subtype(tm, *vtype, *rtm.STRING_TYPE_STAR)))
35 {
36@@ -1011,6 +1008,18 @@
37 {
38 treat_expr* ve = static_cast<treat_expr*>(vexpr);
39
40+ if (qexpr->get_expr_kind() == promote_expr_kind)
41+ {
42+ promote_expr* qe = static_cast<promote_expr*>(qexpr);
43+ xqtref_t qtype = qe->get_return_type();
44+ xqtref_t vtype = ve->get_target_type();
45+
46+ if (TypeOps::is_subtype(tm, *vtype, *qtype))
47+ {
48+ return expr_tools::match_exact(qe->get_input(), ve->get_input(), subst);
49+ }
50+ }
51+
52 return expr_tools::match_exact(qexpr, ve->get_input(), subst);
53 }
54
55
56=== added file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/index/match_veq_09.iter'
57--- test/rbkt/ExpCompilerResults/IterPlan/zorba/index/match_veq_09.iter 1970-01-01 00:00:00 +0000
58+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/index/match_veq_09.iter 2013-02-21 22:44:24 +0000
59@@ -0,0 +1,113 @@
60+Iterator tree for index:
61+<flwor::FLWORIterator>
62+ <ForVariable name="$$context-item">
63+ <ZorbaCollectionIterator>
64+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
65+ </ZorbaCollectionIterator>
66+ </ForVariable>
67+ <ReturnClause>
68+ <ValueIndexEntryBuilderIterator>
69+ <ForVarIterator varname="$$context-item"/>
70+ <TreatIterator type="xs:integer" quant="">
71+ <FnDataIterator>
72+ <JSONObjectValueIterator>
73+ <ForVarIterator varname="$$context-item"/>
74+ <SingletonIterator value="xs:string(question_id)"/>
75+ </JSONObjectValueIterator>
76+ </FnDataIterator>
77+ </TreatIterator>
78+ </ValueIndexEntryBuilderIterator>
79+ </ReturnClause>
80+</flwor::FLWORIterator>
81+
82+Iterator tree for const-folded expr:
83+<OrIterator>
84+ <SingletonIterator value="xs:boolean(false)"/>
85+ <SingletonIterator value="xs:boolean(false)"/>
86+ <SingletonIterator value="xs:boolean(false)"/>
87+</OrIterator>
88+
89+Iterator tree for main query:
90+<SequentialIterator>
91+ <ApplyIterator>
92+ <ZorbaCreateCollectionIterator>
93+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
94+ </ZorbaCreateCollectionIterator>
95+ </ApplyIterator>
96+ <ApplyIterator>
97+ <ZorbaCreateCollectionIterator>
98+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
99+ </ZorbaCreateCollectionIterator>
100+ </ApplyIterator>
101+ <ApplyIterator>
102+ <CreateIndexIterator>
103+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
104+ </CreateIndexIterator>
105+ </ApplyIterator>
106+ <flwor::TupleStreamIterator>
107+ <flwor::OrderByIterator>
108+ <OrderByForVariable inputVar="id : "/>
109+ <OrderByForVariable inputVar="count : "/>
110+ <OrderBySpec>
111+ <ForVarIterator varname="count"/>
112+ </OrderBySpec>
113+ <flwor::ForIterator>
114+ <ForVariable name="count"/>
115+ <flwor::GroupByIterator>
116+ <flwor::ForIterator>
117+ <ForVariable name="answers"/>
118+ <flwor::TupleSourceIterator/>
119+ <ZorbaCollectionIterator>
120+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
121+ </ZorbaCollectionIterator>
122+ </flwor::ForIterator>
123+ <Spec>
124+ <TreatIterator quant="?">
125+ <FnDataIterator>
126+ <JSONObjectValueIterator>
127+ <ForVarIterator varname="answers"/>
128+ <SingletonIterator value="xs:string(question_id)"/>
129+ </JSONObjectValueIterator>
130+ </FnDataIterator>
131+ </TreatIterator>
132+ <GroupVariable/>
133+ </Spec>
134+ <Spec>
135+ <ForVarIterator varname="answers"/>
136+ <NonGroupVariable/>
137+ </Spec>
138+ </flwor::GroupByIterator>
139+ <FnCountIterator>
140+ <LetVarIterator varname="answers"/>
141+ </FnCountIterator>
142+ </flwor::ForIterator>
143+ </flwor::OrderByIterator>
144+ <JSONDirectObjectIterator>
145+ <SingletonIterator value="xs:string(title)"/>
146+ <SingletonIterator value="xs:string(answer_count)"/>
147+ <JSONBoxIterator>
148+ <flwor::FLWORIterator>
149+ <ForVariable name="$$context-item">
150+ <ProbeIndexRangeValueIterator>
151+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
152+ <ForVarIterator varname="id"/>
153+ <ForVarIterator varname="id"/>
154+ <SingletonIterator value="xs:boolean(true)"/>
155+ <SingletonIterator value="xs:boolean(true)"/>
156+ <SingletonIterator value="xs:boolean(true)"/>
157+ <SingletonIterator value="xs:boolean(true)"/>
158+ </ProbeIndexRangeValueIterator>
159+ </ForVariable>
160+ <ReturnClause>
161+ <JSONObjectValueIterator>
162+ <ForVarIterator varname="$$context-item"/>
163+ <SingletonIterator value="xs:string(title)"/>
164+ </JSONObjectValueIterator>
165+ </ReturnClause>
166+ </flwor::FLWORIterator>
167+ </JSONBoxIterator>
168+ <ForVarIterator varname="count"/>
169+ </JSONDirectObjectIterator>
170+ </flwor::TupleStreamIterator>
171+</SequentialIterator>
172+
173
174=== added file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/index/match_veq_10.iter'
175--- test/rbkt/ExpCompilerResults/IterPlan/zorba/index/match_veq_10.iter 1970-01-01 00:00:00 +0000
176+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/index/match_veq_10.iter 2013-02-21 22:44:24 +0000
177@@ -0,0 +1,119 @@
178+Iterator tree for index:
179+<flwor::FLWORIterator>
180+ <ForVariable name="$$context-item">
181+ <ZorbaCollectionIterator>
182+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
183+ </ZorbaCollectionIterator>
184+ </ForVariable>
185+ <ReturnClause>
186+ <ValueIndexEntryBuilderIterator>
187+ <ForVarIterator varname="$$context-item"/>
188+ <PromoteIterator type="xs:string">
189+ <CastIterator type="xs:string">
190+ <FnDataIterator>
191+ <JSONObjectValueIterator>
192+ <ForVarIterator varname="$$context-item"/>
193+ <SingletonIterator value="xs:string(question_id)"/>
194+ </JSONObjectValueIterator>
195+ </FnDataIterator>
196+ </CastIterator>
197+ </PromoteIterator>
198+ </ValueIndexEntryBuilderIterator>
199+ </ReturnClause>
200+</flwor::FLWORIterator>
201+
202+Iterator tree for const-folded expr:
203+<OrIterator>
204+ <SingletonIterator value="xs:boolean(false)"/>
205+ <SingletonIterator value="xs:boolean(false)"/>
206+ <SingletonIterator value="xs:boolean(false)"/>
207+</OrIterator>
208+
209+Iterator tree for main query:
210+<SequentialIterator>
211+ <ApplyIterator>
212+ <ZorbaCreateCollectionIterator>
213+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
214+ </ZorbaCreateCollectionIterator>
215+ </ApplyIterator>
216+ <ApplyIterator>
217+ <ZorbaCreateCollectionIterator>
218+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
219+ </ZorbaCreateCollectionIterator>
220+ </ApplyIterator>
221+ <ApplyIterator>
222+ <CreateIndexIterator>
223+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
224+ </CreateIndexIterator>
225+ </ApplyIterator>
226+ <flwor::TupleStreamIterator>
227+ <flwor::OrderByIterator>
228+ <OrderByForVariable inputVar="id : "/>
229+ <OrderByForVariable inputVar="count : "/>
230+ <OrderBySpec>
231+ <ForVarIterator varname="count"/>
232+ </OrderBySpec>
233+ <flwor::ForIterator>
234+ <ForVariable name="count"/>
235+ <flwor::GroupByIterator>
236+ <flwor::ForIterator>
237+ <ForVariable name="answers"/>
238+ <flwor::TupleSourceIterator/>
239+ <ZorbaCollectionIterator>
240+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
241+ </ZorbaCollectionIterator>
242+ </flwor::ForIterator>
243+ <Spec>
244+ <TreatIterator quant="?">
245+ <FnDataIterator>
246+ <JSONObjectValueIterator>
247+ <ForVarIterator varname="answers"/>
248+ <SingletonIterator value="xs:string(question_id)"/>
249+ </JSONObjectValueIterator>
250+ </FnDataIterator>
251+ </TreatIterator>
252+ <GroupVariable/>
253+ </Spec>
254+ <Spec>
255+ <ForVarIterator varname="answers"/>
256+ <NonGroupVariable/>
257+ </Spec>
258+ </flwor::GroupByIterator>
259+ <FnCountIterator>
260+ <LetVarIterator varname="answers"/>
261+ </FnCountIterator>
262+ </flwor::ForIterator>
263+ </flwor::OrderByIterator>
264+ <JSONDirectObjectIterator>
265+ <SingletonIterator value="xs:string(title)"/>
266+ <SingletonIterator value="xs:string(answer_count)"/>
267+ <JSONBoxIterator>
268+ <flwor::FLWORIterator>
269+ <ForVariable name="$$context-item">
270+ <ProbeIndexRangeValueIterator>
271+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
272+ <CastIterator type="xs:string">
273+ <ForVarIterator varname="id"/>
274+ </CastIterator>
275+ <CastIterator type="xs:string">
276+ <ForVarIterator varname="id"/>
277+ </CastIterator>
278+ <SingletonIterator value="xs:boolean(true)"/>
279+ <SingletonIterator value="xs:boolean(true)"/>
280+ <SingletonIterator value="xs:boolean(true)"/>
281+ <SingletonIterator value="xs:boolean(true)"/>
282+ </ProbeIndexRangeValueIterator>
283+ </ForVariable>
284+ <ReturnClause>
285+ <JSONObjectValueIterator>
286+ <ForVarIterator varname="$$context-item"/>
287+ <SingletonIterator value="xs:string(title)"/>
288+ </JSONObjectValueIterator>
289+ </ReturnClause>
290+ </flwor::FLWORIterator>
291+ </JSONBoxIterator>
292+ <ForVarIterator varname="count"/>
293+ </JSONDirectObjectIterator>
294+ </flwor::TupleStreamIterator>
295+</SequentialIterator>
296+
297
298=== added file 'test/rbkt/ExpQueryResults/zorba/index/match_veq_09.xml.res'
299=== added file 'test/rbkt/ExpQueryResults/zorba/index/match_veq_10.xml.res'
300=== added file 'test/rbkt/Queries/zorba/index/match_veq_09.xq'
301--- test/rbkt/Queries/zorba/index/match_veq_09.xq 1970-01-01 00:00:00 +0000
302+++ test/rbkt/Queries/zorba/index/match_veq_09.xq 2013-02-21 22:44:24 +0000
303@@ -0,0 +1,31 @@
304+
305+
306+import module namespace db28 =
307+"http://28.io/collections" at "match_veq_09.xqlib";
308+
309+import module namespace dml =
310+"http://www.zorba-xquery.com/modules/store/static/collections/dml";
311+
312+import module namespace ddl =
313+"http://www.zorba-xquery.com/modules/store/static/collections/ddl";
314+
315+import module namespace iddl =
316+"http://www.zorba-xquery.com/modules/store/static/indexes/ddl";
317+
318+
319+ddl:create(xs:QName("db28:faqs"));
320+
321+ddl:create(xs:QName("db28:answers"));
322+
323+iddl:create(xs:QName("db28:question-id-idx"));
324+
325+
326+for $answers in dml:collection(xs:QName("db28:answers"))
327+let $id := $answers("question_id")
328+group by $id
329+let $count := count($answers)
330+order by $count descending
331+return {
332+ "title": dml:collection(xs:QName("db28:faqs"))[$id eq .("question_id")]("title"),
333+ "answer_count": $count
334+}
335
336=== added file 'test/rbkt/Queries/zorba/index/match_veq_09.xqlib'
337--- test/rbkt/Queries/zorba/index/match_veq_09.xqlib 1970-01-01 00:00:00 +0000
338+++ test/rbkt/Queries/zorba/index/match_veq_09.xqlib 2013-02-21 22:44:24 +0000
339@@ -0,0 +1,15 @@
340+
341+module namespace db28 = "http://28.io/collections";
342+
343+import module namespace db = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
344+
345+declare namespace an = "http://www.zorba-xquery.com/annotations";
346+
347+declare collection db28:answers as object()*;
348+
349+declare collection db28:faqs as object()*;
350+
351+declare %an:value-range index db28:question-id-idx
352+on nodes db:collection(xs:QName("db28:faqs"))
353+by .("question_id") as xs:integer;
354+
355
356=== added file 'test/rbkt/Queries/zorba/index/match_veq_10.xq'
357--- test/rbkt/Queries/zorba/index/match_veq_10.xq 1970-01-01 00:00:00 +0000
358+++ test/rbkt/Queries/zorba/index/match_veq_10.xq 2013-02-21 22:44:24 +0000
359@@ -0,0 +1,31 @@
360+
361+
362+import module namespace db28 =
363+"http://28.io/collections" at "match_veq_10.xqlib";
364+
365+import module namespace dml =
366+"http://www.zorba-xquery.com/modules/store/static/collections/dml";
367+
368+import module namespace ddl =
369+"http://www.zorba-xquery.com/modules/store/static/collections/ddl";
370+
371+import module namespace iddl =
372+"http://www.zorba-xquery.com/modules/store/static/indexes/ddl";
373+
374+
375+ddl:create(xs:QName("db28:faqs"));
376+
377+ddl:create(xs:QName("db28:answers"));
378+
379+iddl:create(xs:QName("db28:question-id-idx"));
380+
381+
382+for $answers in dml:collection(xs:QName("db28:answers"))
383+let $id := $answers("question_id")
384+group by $id
385+let $count := count($answers)
386+order by $count descending
387+return {
388+ "title": dml:collection(xs:QName("db28:faqs"))[xs:string($id) eq xs:string(.("question_id"))]("title"),
389+ "answer_count": $count
390+}
391
392=== added file 'test/rbkt/Queries/zorba/index/match_veq_10.xqlib'
393--- test/rbkt/Queries/zorba/index/match_veq_10.xqlib 1970-01-01 00:00:00 +0000
394+++ test/rbkt/Queries/zorba/index/match_veq_10.xqlib 2013-02-21 22:44:24 +0000
395@@ -0,0 +1,16 @@
396+
397+module namespace db28 = "http://28.io/collections";
398+
399+import module namespace db =
400+"http://www.zorba-xquery.com/modules/store/static/collections/dml";
401+
402+declare namespace an = "http://www.zorba-xquery.com/annotations";
403+
404+declare collection db28:answers as object()*;
405+
406+declare collection db28:faqs as object()*;
407+
408+declare %an:value-range index db28:question-id-idx
409+on nodes db:collection(xs:QName("db28:faqs"))
410+by xs:string(.("question_id")) as xs:string;
411+

Subscribers

People subscribed via source and target branches