zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #18297
[Merge] lp:~zorba-coders/zorba/expr-matching into lp:zorba
Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/expr-matching into lp:zorba.
Commit message:
enhanced index key matching
Requested reviews:
Markos Zaharioudakis (markos-za)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/expr-matching/+merge/149949
enhanced index key matching
--
https://code.launchpad.net/~zorba-coders/zorba/expr-matching/+merge/149949
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/rewriter/rules/index_matching_rule.cpp'
--- src/compiler/rewriter/rules/index_matching_rule.cpp 2013-02-21 06:30:02 +0000
+++ src/compiler/rewriter/rules/index_matching_rule.cpp 2013-02-21 22:39:36 +0000
@@ -967,6 +967,9 @@
expr* vexpr,
expr::substitution_t& subst)
{
+ TypeManager* tm = qexpr->get_type_manager();
+ RootTypeManager& rtm = GENV_TYPESYSTEM;
+
if (qexpr->get_expr_kind() == promote_expr_kind &&
vexpr->get_expr_kind() == promote_expr_kind)
{
@@ -975,9 +978,6 @@
xqtref_t qtype = qe->get_return_type();
xqtref_t vtype = ve->get_target_type();
- TypeManager* tm = qe->get_type_manager();
- RootTypeManager& rtm = GENV_TYPESYSTEM;
-
if (TypeOps::is_subtype(tm, *vtype, *qtype) ||
(TypeOps::is_subtype(tm, *qtype, *rtm.UNTYPED_ATOMIC_TYPE_STAR) &&
TypeOps::is_subtype(tm, *vtype, *rtm.STRING_TYPE_STAR)))
@@ -994,9 +994,6 @@
xqtref_t qtype = qexpr->get_return_type();
xqtref_t vtype = ve->get_target_type();
- TypeManager* tm = qexpr->get_type_manager();
- RootTypeManager& rtm = GENV_TYPESYSTEM;
-
if (TypeOps::is_subtype(tm, *qtype, *vtype) ||
(TypeOps::is_subtype(tm, *qtype, *rtm.UNTYPED_ATOMIC_TYPE_STAR) &&
TypeOps::is_subtype(tm, *vtype, *rtm.STRING_TYPE_STAR)))
@@ -1011,6 +1008,18 @@
{
treat_expr* ve = static_cast<treat_expr*>(vexpr);
+ if (qexpr->get_expr_kind() == promote_expr_kind)
+ {
+ promote_expr* qe = static_cast<promote_expr*>(qexpr);
+ xqtref_t qtype = qe->get_return_type();
+ xqtref_t vtype = ve->get_target_type();
+
+ if (TypeOps::is_subtype(tm, *vtype, *qtype))
+ {
+ return expr_tools::match_exact(qe->get_input(), ve->get_input(), subst);
+ }
+ }
+
return expr_tools::match_exact(qexpr, ve->get_input(), subst);
}
=== added file 'test/rbkt/ExpCompilerResults/IterPlan/zorba/index/match_veq_09.iter'
--- test/rbkt/ExpCompilerResults/IterPlan/zorba/index/match_veq_09.iter 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpCompilerResults/IterPlan/zorba/index/match_veq_09.iter 2013-02-21 22:39:36 +0000
@@ -0,0 +1,113 @@
+Iterator tree for index:
+<flwor::FLWORIterator>
+ <ForVariable name="$$context-item">
+ <ZorbaCollectionIterator>
+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
+ </ZorbaCollectionIterator>
+ </ForVariable>
+ <ReturnClause>
+ <ValueIndexEntryBuilderIterator>
+ <ForVarIterator varname="$$context-item"/>
+ <TreatIterator type="xs:integer" quant="">
+ <FnDataIterator>
+ <JSONObjectValueIterator>
+ <ForVarIterator varname="$$context-item"/>
+ <SingletonIterator value="xs:string(question_id)"/>
+ </JSONObjectValueIterator>
+ </FnDataIterator>
+ </TreatIterator>
+ </ValueIndexEntryBuilderIterator>
+ </ReturnClause>
+</flwor::FLWORIterator>
+
+Iterator tree for const-folded expr:
+<OrIterator>
+ <SingletonIterator value="xs:boolean(false)"/>
+ <SingletonIterator value="xs:boolean(false)"/>
+ <SingletonIterator value="xs:boolean(false)"/>
+</OrIterator>
+
+Iterator tree for main query:
+<SequentialIterator>
+ <ApplyIterator>
+ <ZorbaCreateCollectionIterator>
+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,faqs)"/>
+ </ZorbaCreateCollectionIterator>
+ </ApplyIterator>
+ <ApplyIterator>
+ <ZorbaCreateCollectionIterator>
+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
+ </ZorbaCreateCollectionIterator>
+ </ApplyIterator>
+ <ApplyIterator>
+ <CreateIndexIterator>
+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
+ </CreateIndexIterator>
+ </ApplyIterator>
+ <flwor::TupleStreamIterator>
+ <flwor::OrderByIterator>
+ <OrderByForVariable inputVar="id : "/>
+ <OrderByForVariable inputVar="count : "/>
+ <OrderBySpec>
+ <ForVarIterator varname="count"/>
+ </OrderBySpec>
+ <flwor::ForIterator>
+ <ForVariable name="count"/>
+ <flwor::GroupByIterator>
+ <flwor::ForIterator>
+ <ForVariable name="answers"/>
+ <flwor::TupleSourceIterator/>
+ <ZorbaCollectionIterator>
+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,answers)"/>
+ </ZorbaCollectionIterator>
+ </flwor::ForIterator>
+ <Spec>
+ <TreatIterator quant="?">
+ <FnDataIterator>
+ <JSONObjectValueIterator>
+ <ForVarIterator varname="answers"/>
+ <SingletonIterator value="xs:string(question_id)"/>
+ </JSONObjectValueIterator>
+ </FnDataIterator>
+ </TreatIterator>
+ <GroupVariable/>
+ </Spec>
+ <Spec>
+ <ForVarIterator varname="answers"/>
+ <NonGroupVariable/>
+ </Spec>
+ </flwor::GroupByIterator>
+ <FnCountIterator>
+ <LetVarIterator varname="answers"/>
+ </FnCountIterator>
+ </flwor::ForIterator>
+ </flwor::OrderByIterator>
+ <JSONDirectObjectIterator>
+ <SingletonIterator value="xs:string(title)"/>
+ <SingletonIterator value="xs:string(answer_count)"/>
+ <JSONBoxIterator>
+ <flwor::FLWORIterator>
+ <ForVariable name="$$context-item">
+ <ProbeIndexRangeValueIterator>
+ <SingletonIterator value="xs:QName(http://28.io/collections,db28,question-id-idx)"/>
+ <ForVarIterator varname="id"/>
+ <ForVarIterator varname="id"/>
+ <SingletonIterator value="xs:boolean(true)"/>
+ <SingletonIterator value="xs:boolean(true)"/>
+ <SingletonIterator value="xs:boolean(true)"/>
+ <SingletonIterator value="xs:boolean(true)"/>
+ </ProbeIndexRangeValueIterator>
+ </ForVariable>
+ <ReturnClause>
+ <JSONObjectValueIterator>
+ <ForVarIterator varname="$$context-item"/>
+ <SingletonIterator value="xs:string(title)"/>
+ </JSONObjectValueIterator>
+ </ReturnClause>
+ </flwor::FLWORIterator>
+ </JSONBoxIterator>
+ <ForVarIterator varname="count"/>
+ </JSONDirectObjectIterator>
+ </flwor::TupleStreamIterator>
+</SequentialIterator>
+
=== added file 'test/rbkt/ExpQueryResults/zorba/index/match_veq_09.xml.res'
=== added file 'test/rbkt/Queries/zorba/index/match_veq_09.xq'
--- test/rbkt/Queries/zorba/index/match_veq_09.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/index/match_veq_09.xq 2013-02-21 22:39:36 +0000
@@ -0,0 +1,31 @@
+
+
+import module namespace db28 =
+"http://28.io/collections" at "match_veq_09.xqlib";
+
+import module namespace dml =
+"http://www.zorba-xquery.com/modules/store/static/collections/dml";
+
+import module namespace ddl =
+"http://www.zorba-xquery.com/modules/store/static/collections/ddl";
+
+import module namespace iddl =
+"http://www.zorba-xquery.com/modules/store/static/indexes/ddl";
+
+
+ddl:create(xs:QName("db28:faqs"));
+
+ddl:create(xs:QName("db28:answers"));
+
+iddl:create(xs:QName("db28:question-id-idx"));
+
+
+for $answers in dml:collection(xs:QName("db28:answers"))
+let $id := $answers("question_id")
+group by $id
+let $count := count($answers)
+order by $count descending
+return {
+ "title": dml:collection(xs:QName("db28:faqs"))[$id eq .("question_id")]("title"),
+ "answer_count": $count
+}
=== added file 'test/rbkt/Queries/zorba/index/match_veq_09.xqlib'
--- test/rbkt/Queries/zorba/index/match_veq_09.xqlib 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/index/match_veq_09.xqlib 2013-02-21 22:39:36 +0000
@@ -0,0 +1,15 @@
+
+module namespace db28 = "http://28.io/collections";
+
+import module namespace db = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
+
+declare namespace an = "http://www.zorba-xquery.com/annotations";
+
+declare collection db28:answers as object()*;
+
+declare collection db28:faqs as object()*;
+
+declare %an:value-range index db28:question-id-idx
+on nodes db:collection(xs:QName("db28:faqs"))
+by .("question_id") as xs:integer;
+
Follow ups