Merge lp:~zorba-coders/zorba/skiplimit into lp:zorba

Proposed by William Candillon
Status: Superseded
Proposed branch: lp:~zorba-coders/zorba/skiplimit
Merge into: lp:zorba
Diff against target: 417 lines (+222/-3)
19 files modified
src/compiler/parser/parser.y (+22/-3)
src/compiler/parser/scanner.l (+2/-0)
src/compiler/parsetree/parsenode_print_xml_visitor.cpp (+2/-0)
src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp (+2/-0)
src/compiler/parsetree/parsenode_print_xquery_visitor.cpp (+18/-0)
src/compiler/parsetree/parsenode_visitor.h (+2/-0)
src/compiler/parsetree/parsenodes.cpp (+31/-0)
src/compiler/parsetree/parsenodes.h (+27/-0)
src/compiler/translator/translator.cpp (+87/-0)
test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-1.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-2.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-3.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-4.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-5.xml.res (+1/-0)
test/rbkt/Queries/zorba/offset-limit/offset-limit-1.xq (+4/-0)
test/rbkt/Queries/zorba/offset-limit/offset-limit-2.xq (+3/-0)
test/rbkt/Queries/zorba/offset-limit/offset-limit-3.xq (+3/-0)
test/rbkt/Queries/zorba/offset-limit/offset-limit-4.xq (+7/-0)
test/rbkt/Queries/zorba/offset-limit/offset-limit-5.xq (+7/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/skiplimit
Reviewer Review Type Date Requested Status
Ghislain Fourny Needs Fixing
Markos Zaharioudakis Needs Information
William Candillon Approve
Review via email: mp+173126@code.launchpad.net

This proposal has been superseded by a proposal from 2013-07-19.

Commit message

Add offset limit clauses to the FLWOR.

Description of the change

Add offset limit clauses to the FLWOR.
These clauses are similar to limit and offset from SQL.
For example:
for $i in (1 to 10)
offset 5
limit 2
return $i

To post a comment you must log in.
Revision history for this message
William Candillon (wcandillon) :
review: Approve
Revision history for this message
Markos Zaharioudakis (markos-za) wrote :

1. I think Dana will have to approve the adding of proprietary syntax to do what is essentially syntactic sugar for fn:subsequence().

2. Why allow multiple offset/limit clauses when, as far as I can understand, only the last offset/limit clause takes effect?

review: Needs Information
Revision history for this message
William Candillon (wcandillon) wrote :

1. I make an email loop to get Dana's approval.

2. There are couple of options, I wasn't sure which one to pick:

a) (offset ExprSingle)? (limit ExprSingle)?
b) (offset ExprSingle) | (limit ExprSingle) | (limit ExprSingle offset ExprSingle) | (offset ExprSingle limit ExprSingle)
c) ((offset ExprSingle) | (limit ExprSingle)?)*
I ended up doing c) but I can do a) or b).

lp:~zorba-coders/zorba/skiplimit updated
11548. By Chris Hillery

Updated node-position module to Zorba 3.0 format.
Approved: Juan Zacarias, Chris Hillery

11549. By Markos Zaharioudakis

Some work towards multi-threading
1. Fixed a couple of threading bugs in qname pool
2. Redefined free() method for root_static_context and for builtin functions
3. Annotations are not RCObjects anymore
4. Use atomic ints are counters in RCObjects
5. No query cloning in testdriver_mt
Approved: Markos Zaharioudakis

11550. By Chris Hillery

Update "JSON" module: now known as "json-xml", function names changed, namespace changed to zorba.io, moved out of unnecessary subdirectories.
Approved: Paul J. Lucas, Chris Hillery

11551. By sorin.marian.nasoi <email address hidden>

- fixed examples links in the XQDoc documentation
Approved: Sorin Marian Nasoi, Chris Hillery

11552. By sorin.marian.nasoi <email address hidden>

- bumped QT test-suite version
Approved: Chris Hillery, Sorin Marian Nasoi

11553. By sorin.marian.nasoi <email address hidden>

- since ICU does not support "FULLY-NORMALIZED" normalization form Zorba does not support it either: updated the Zorba Manifest to reflect this.
Approved: Chris Hillery, Sorin Marian Nasoi

Revision history for this message
Ghislain Fourny (gislenius) wrote :

I have the feeling that this could and should be made more general, i.e., introduce "limit" ExprSingle and "offset" ExprSingle as regular FLWOR clauses, like any other clauses, that you can put everywhere (as intermediate clauses), and that are syntactic sugars for "count $i where $i le ExprSingle" and "count $i where $i gt ExprSingle" respectively.
That way, there would no longer be any need to go through syntactic options as above as they behave like any other clause.

Concretely, I think that it comes down to something as simple as:

IntermediateClause ::= InitialClause | WhereClause | GroupByClause | OrderByClause | CountClause | OffsetClause | LimitClause

OffsetClause ::= "offset" ExprSingle

LimitClause ::= "limit" ExprSingle

Revision history for this message
Ghislain Fourny (gislenius) :
review: Needs Fixing
Revision history for this message
William Candillon (wcandillon) wrote :

Hi Ghislain,

Thank you so much for this insight. That makes perfect sense.

Now I see two way this can go:
- offset/limit is just a syntactic sugar for count/where and using the subsequence optimisation for it is completely orthogonal to this merge proposal.
- offset/limit doesn't make sense if the subsequence optimisation is not used. If so, could I have some pointers on how to implement this optimisation?

Revision history for this message
Ghislain Fourny (gislenius) wrote :

Hi William,

I think that count$i-where$i aka offset/limit can be optimized, but in most cases not in terms of subsequence: it sets an offset or a limit on the number of tuples, not on the number of items (a tuple may well produce zero, or more than one item in the end). I think that an early exit, or skipping, in FLWOR iterators should be possible when encountering a count$i-where$i. Markos is probably more familiar with this code than I am though.

Does it make sense?

Revision history for this message
Ghislain Fourny (gislenius) wrote :

My remark would correspond to your first choice: offset/limit is just a syntactic sugar, and count$i-where$i is optimized separately.

Revision history for this message
William Candillon (wcandillon) wrote :

It feels that the current proposal is actually quite efficient and has a predictable performance.
But I like the beauty of having the count/where syntactic sugar. So I'm not sure what do to.

lp:~zorba-coders/zorba/skiplimit updated
11554. By Chris Hillery

Remove "system" module dependency from core tests.
Approved: Juan Zacarias, Chris Hillery

11555. By Chris Hillery

Don't check %private variables.
Approved: Rodolfo Ochoa, Chris Hillery

11556. By Chris Hillery

Update base64 module to Zorba 3.0 standards.
Approved: Luis Rodriguez Gonzalez, Chris Hillery

11557. By Chris Hillery

Update core math and random modules to Zorba 3.0 standards.
Approved: Luis Rodriguez Gonzalez, Chris Hillery

11558. By William Candillon

Add Offset clause.

11559. By William Candillon

Implement limit clause.

11560. By William Candillon

Add tests.

11561. By William Candillon

Update test suite.

11562. By William Candillon

Remove useless comment.

11563. By William Candillon

Merge.

11564. By William Candillon

Remove unused variable.

11565. By William Candillon

Fix parser bug.

11566. By Paul J. Lucas

Merge from trunk.

11567. By Paul J. Lucas

s/OP_GREATER_EQUAL_2/OP_GREATER_2/

11568. By Paul J. Lucas

Removed unnecessary destructors.

11569. By Paul J. Lucas

Merge from trunk.

11570. By Paul J. Lucas

Merge from trunk.

11571. By Paul J. Lucas

Now using getNameAsString().

11572. By Paul J. Lucas

Comment fix to match reality.

11573. By Paul J. Lucas

Merge from trunk.

11574. By Paul J. Lucas

Fixed test results.

11575. By Paul J. Lucas

Removed erroneous use of theOffsetExpr.

11576. By Paul J. Lucas

Removed useless theOffsetExpr.

11577. By Paul J. Lucas

Comment fix.

Unmerged revisions

11577. By Paul J. Lucas

Comment fix.

11576. By Paul J. Lucas

Removed useless theOffsetExpr.

11575. By Paul J. Lucas

Removed erroneous use of theOffsetExpr.

11574. By Paul J. Lucas

Fixed test results.

11573. By Paul J. Lucas

Merge from trunk.

11572. By Paul J. Lucas

Comment fix to match reality.

11571. By Paul J. Lucas

Now using getNameAsString().

11570. By Paul J. Lucas

Merge from trunk.

11569. By Paul J. Lucas

Merge from trunk.

11568. By Paul J. Lucas

Removed unnecessary destructors.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/compiler/parser/parser.y'
--- src/compiler/parser/parser.y 2013-06-17 20:05:21 +0000
+++ src/compiler/parser/parser.y 2013-07-19 07:43:31 +0000
@@ -325,6 +325,8 @@
325%token QUOTE "'\"'"325%token QUOTE "'\"'"
326%token RBRACE "'}'"326%token RBRACE "'}'"
327%token RBRACK "']'"327%token RBRACK "']'"
328%token OFFSET "'offset'"
329%token LIMIT "'limit'"
328%token RETURN "'return'"330%token RETURN "'return'"
329%token RPAR "')'"331%token RPAR "')'"
330%token SATISFIES "'satisfies'"332%token SATISFIES "'satisfies'"
@@ -637,6 +639,8 @@
637%type <node> BlockVarDecl639%type <node> BlockVarDecl
638%type <node> WhereClause640%type <node> WhereClause
639%type <node> CountClause641%type <node> CountClause
642%type <node> OffsetClause
643%type <node> LimitClause
640%type <node> Wildcard644%type <node> Wildcard
641645
642/* left-hand sides: expressions */646/* left-hand sides: expressions */
@@ -883,7 +887,7 @@
883%destructor { release_hack( $$ ); } SchemaPrefix SequenceType SequenceTypeList Setter SignList SingleType TextTest NamespaceTest TypeDeclaration TypeName TypeName_WITH_HOOK 887%destructor { release_hack( $$ ); } SchemaPrefix SequenceType SequenceTypeList Setter SignList SingleType TextTest NamespaceTest TypeDeclaration TypeName TypeName_WITH_HOOK
884%destructor { release_hack( $$ ); } URILiteralList ValueComp CollectionDecl IndexDecl IndexKeySpec IndexKeyList IntegrityConstraintDecl CtxItemDecl CtxItemDecl2 CtxItemDecl3 888%destructor { release_hack( $$ ); } URILiteralList ValueComp CollectionDecl IndexDecl IndexKeySpec IndexKeyList IntegrityConstraintDecl CtxItemDecl CtxItemDecl2 CtxItemDecl3
885%destructor { release_hack( $$ ); } CtxItemDecl4 VarDecl VarGetsDecl VarGetsDeclList VarInDecl VarInDeclList WindowVarDecl WindowVars WindowVars2 WindowVars3 FLWORWinCond 889%destructor { release_hack( $$ ); } CtxItemDecl4 VarDecl VarGetsDecl VarGetsDeclList VarInDecl VarInDeclList WindowVarDecl WindowVars WindowVars2 WindowVars3 FLWORWinCond
886%destructor { release_hack( $$ ); } VersionDecl VFO_Decl VFO_DeclList WhereClause CountClause Wildcard DecimalFormatDecl TypedFunctionTest AnyFunctionTest TypeList 890%destructor { release_hack( $$ ); } VersionDecl VFO_Decl VFO_DeclList WhereClause CountClause LimitClause OffsetClause Wildcard DecimalFormatDecl TypedFunctionTest AnyFunctionTest TypeList
887%destructor { release_hack( $$ ); } SwitchCaseClause SwitchCaseClauseList SwitchCaseOperandList891%destructor { release_hack( $$ ); } SwitchCaseClause SwitchCaseClauseList SwitchCaseOperandList
888892
889#ifdef XQUERY_PARSER893#ifdef XQUERY_PARSER
@@ -2712,8 +2716,23 @@
2712 | OrderByClause2716 | OrderByClause
2713 | GroupByClause2717 | GroupByClause
2714 | CountClause2718 | CountClause
2715;2719 | OffsetClause
27162720 | LimitClause
2721;
2722
2723OffsetClause :
2724 OFFSET ExprSingle
2725 {
2726 $$ = new OffsetClause(LOC (@$), $2);
2727 }
2728;
2729
2730LimitClause :
2731 LIMIT ExprSingle
2732 {
2733 $$ = new LimitClause(LOC (@$), $2);
2734 }
2735;
27172736
2718FLWORClauseList :2737FLWORClauseList :
2719 ForLetWinClause2738 ForLetWinClause
27202739
=== modified file 'src/compiler/parser/scanner.l'
--- src/compiler/parser/scanner.l 2013-04-23 13:20:31 +0000
+++ src/compiler/parser/scanner.l 2013-07-19 07:43:31 +0000
@@ -557,6 +557,8 @@
557"by" { return token::BY; }557"by" { return token::BY; }
558"stable" { return token::STABLE; }558"stable" { return token::STABLE; }
559"or" { return token::OR; }559"or" { return token::OR; }
560"limit" { return token::LIMIT; }
561"offset" { return token::OFFSET; }
560"return" { return token::RETURN; }562"return" { return token::RETURN; }
561#ifdef JSONIQ_SCANNER563#ifdef JSONIQ_SCANNER
562"select" { return token::RETURN; }564"select" { return token::RETURN; }
563565
=== modified file 'src/compiler/parsetree/parsenode_print_xml_visitor.cpp'
--- src/compiler/parsetree/parsenode_print_xml_visitor.cpp 2013-06-07 13:46:26 +0000
+++ src/compiler/parsetree/parsenode_print_xml_visitor.cpp 2013-07-19 07:43:31 +0000
@@ -726,6 +726,8 @@
726BEGIN_END_TAG (ContextItemExpr)726BEGIN_END_TAG (ContextItemExpr)
727BEGIN_END_TAG (CopyNamespacesDecl)727BEGIN_END_TAG (CopyNamespacesDecl)
728BEGIN_END_TAG (CountClause)728BEGIN_END_TAG (CountClause)
729BEGIN_END_TAG (LimitClause)
730BEGIN_END_TAG (OffsetClause)
729BEGIN_END_TAG (DefaultCollationDecl)731BEGIN_END_TAG (DefaultCollationDecl)
730BEGIN_END_TAG (DeleteExpr)732BEGIN_END_TAG (DeleteExpr)
731END_TAG (DirAttr)733END_TAG (DirAttr)
732734
=== modified file 'src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp'
--- src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp 2013-07-01 18:59:06 +0000
+++ src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp 2013-07-19 07:43:31 +0000
@@ -1529,6 +1529,8 @@
1529XQDOC_NO_BEGIN_END_TAG (VarRef)1529XQDOC_NO_BEGIN_END_TAG (VarRef)
1530XQDOC_NO_BEGIN_END_TAG (VFO_DeclList)1530XQDOC_NO_BEGIN_END_TAG (VFO_DeclList)
1531XQDOC_NO_BEGIN_END_TAG (WhereClause)1531XQDOC_NO_BEGIN_END_TAG (WhereClause)
1532XQDOC_NO_BEGIN_END_TAG (OffsetClause)
1533XQDOC_NO_BEGIN_END_TAG (LimitClause)
1532XQDOC_NO_BEGIN_END_TAG (WhileExpr)1534XQDOC_NO_BEGIN_END_TAG (WhileExpr)
1533XQDOC_NO_BEGIN_END_TAG (Wildcard)1535XQDOC_NO_BEGIN_END_TAG (Wildcard)
1534XQDOC_NO_BEGIN_END_TAG (WindowClause)1536XQDOC_NO_BEGIN_END_TAG (WindowClause)
15351537
=== modified file 'src/compiler/parsetree/parsenode_print_xquery_visitor.cpp'
--- src/compiler/parsetree/parsenode_print_xquery_visitor.cpp 2013-06-07 13:46:26 +0000
+++ src/compiler/parsetree/parsenode_print_xquery_visitor.cpp 2013-07-19 07:43:31 +0000
@@ -1199,6 +1199,24 @@
1199 }1199 }
1200 DEFAULT_END_VISIT (WhereClause)1200 DEFAULT_END_VISIT (WhereClause)
12011201
1202 void* begin_visit(const OffsetClause& n)
1203 {
1204 os << "offset ";
1205 n.get_offset()->accept(*this);
1206 return 0;
1207 }
1208 DEFAULT_END_VISIT (OffsetClause)
1209
1210
1211 void* begin_visit(const LimitClause& n)
1212 {
1213 os << "limit ";
1214 n.get_limit()->accept(*this);
1215 return 0;
1216 }
1217 DEFAULT_END_VISIT (LimitClause)
1218
1219
1202 void* begin_visit(const CountClause& n)1220 void* begin_visit(const CountClause& n)
1203 {1221 {
1204 os << "count $" << n.get_varname();1222 os << "count $" << n.get_varname();
12051223
=== modified file 'src/compiler/parsetree/parsenode_visitor.h'
--- src/compiler/parsetree/parsenode_visitor.h 2013-06-17 13:32:23 +0000
+++ src/compiler/parsetree/parsenode_visitor.h 2013-07-19 07:43:31 +0000
@@ -146,6 +146,8 @@
146 DECL_PARSENODE_VISITOR_VISIT_MEM_FNS( VFO_DeclList );146 DECL_PARSENODE_VISITOR_VISIT_MEM_FNS( VFO_DeclList );
147 DECL_PARSENODE_VISITOR_VISIT_MEM_FNS( WhereClause );147 DECL_PARSENODE_VISITOR_VISIT_MEM_FNS( WhereClause );
148 DECL_PARSENODE_VISITOR_VISIT_MEM_FNS( CountClause );148 DECL_PARSENODE_VISITOR_VISIT_MEM_FNS( CountClause );
149 DECL_PARSENODE_VISITOR_VISIT_MEM_FNS( OffsetClause );
150 DECL_PARSENODE_VISITOR_VISIT_MEM_FNS( LimitClause );
149 DECL_PARSENODE_VISITOR_VISIT_MEM_FNS( Wildcard );151 DECL_PARSENODE_VISITOR_VISIT_MEM_FNS( Wildcard );
150 DECL_PARSENODE_VISITOR_VISIT_MEM_FNS( QName );152 DECL_PARSENODE_VISITOR_VISIT_MEM_FNS( QName );
151 DECL_PARSENODE_VISITOR_VISIT_MEM_FNS( DecimalFormatNode );153 DECL_PARSENODE_VISITOR_VISIT_MEM_FNS( DecimalFormatNode );
152154
=== modified file 'src/compiler/parsetree/parsenodes.cpp'
--- src/compiler/parsetree/parsenodes.cpp 2013-06-17 18:00:35 +0000
+++ src/compiler/parsetree/parsenodes.cpp 2013-07-19 07:43:31 +0000
@@ -1783,6 +1783,37 @@
1783 END_VISITOR();1783 END_VISITOR();
1784}1784}
17851785
1786OffsetClause::OffsetClause(
1787 const QueryLoc& loc_,
1788 rchandle<exprnode> _offset_h)
1789:
1790 FLWORClause(loc_),
1791 offset_h(_offset_h)
1792{}
1793
1794
1795void OffsetClause::accept( parsenode_visitor &v ) const
1796{
1797 BEGIN_VISITOR();
1798 ACCEPT (offset_h);
1799 END_VISITOR();
1800}
1801
1802LimitClause::LimitClause(
1803 const QueryLoc& loc_,
1804 rchandle<exprnode> _limit_h)
1805:
1806 FLWORClause(loc_),
1807 limit_h(_limit_h)
1808{}
1809
1810
1811void LimitClause::accept( parsenode_visitor &v ) const
1812{
1813 BEGIN_VISITOR();
1814 ACCEPT (limit_h);
1815 END_VISITOR();
1816}
17861817
1787void CountClause::accept(parsenode_visitor& v) const1818void CountClause::accept(parsenode_visitor& v) const
1788{1819{
17891820
=== modified file 'src/compiler/parsetree/parsenodes.h'
--- src/compiler/parsetree/parsenodes.h 2013-06-17 18:00:35 +0000
+++ src/compiler/parsetree/parsenodes.h 2013-07-19 07:43:31 +0000
@@ -180,6 +180,8 @@
180class VarGetsDeclList;180class VarGetsDeclList;
181class VarGetsDecl;181class VarGetsDecl;
182class WhereClause;182class WhereClause;
183class OffsetClause;
184class LimitClause;
183class GroupByClause;185class GroupByClause;
184class GroupSpecList;186class GroupSpecList;
185class GroupSpec;187class GroupSpec;
@@ -2235,6 +2237,31 @@
2235 void accept(parsenode_visitor&) const;2237 void accept(parsenode_visitor&) const;
2236};2238};
22372239
2240class OffsetClause : public FLWORClause
2241{
2242protected:
2243 rchandle<exprnode> offset_h;
2244
2245public:
2246 OffsetClause(const QueryLoc&, rchandle<exprnode>);
2247
2248 rchandle<exprnode> get_offset() const { return offset_h; }
2249
2250 void accept(parsenode_visitor&) const;
2251};
2252
2253class LimitClause : public FLWORClause
2254{
2255protected:
2256 rchandle<exprnode> limit_h;
2257
2258public:
2259 LimitClause(const QueryLoc&, rchandle<exprnode>);
2260
2261 rchandle<exprnode> get_limit() const { return limit_h; }
2262
2263 void accept(parsenode_visitor&) const;
2264};
22382265
2239/*******************************************************************************2266/*******************************************************************************
2240 GroupByClause ::= "group" "by" GroupingSpecList2267 GroupByClause ::= "group" "by" GroupingSpecList
22412268
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp 2013-07-06 06:59:32 +0000
+++ src/compiler/translator/translator.cpp 2013-07-19 07:43:31 +0000
@@ -678,6 +678,8 @@
678678
679 std::vector<flwor_clause*> theFlworClausesStack;679 std::vector<flwor_clause*> theFlworClausesStack;
680680
681 expr* theOffsetExpr;
682
681 std::vector<const parsenode*> theTryStack;683 std::vector<const parsenode*> theTryStack;
682684
683 std::stack<NodeSortInfo> theNodeSortStack;685 std::stack<NodeSortInfo> theNodeSortStack;
@@ -6857,6 +6859,7 @@
6857 TRACE_VISIT();6859 TRACE_VISIT();
68586860
6859 theFlworClausesStack.push_back(NULL);6861 theFlworClausesStack.push_back(NULL);
6862 theOffsetExpr = CREATE(const)(theRootSctx, theUDF, loc, numeric_consts<xs_integer>::one());
68606863
6861 return no_state;6864 return no_state;
6862}6865}
@@ -7907,6 +7910,90 @@
7907 theFlworClausesStack.push_back(clause);7910 theFlworClausesStack.push_back(clause);
7908}7911}
79097912
7913void* begin_visit(const OffsetClause& v)
7914{
7915 TRACE_VISIT ();
7916 return no_state;
7917}
7918
7919void end_visit(const OffsetClause& v, void* /*visit_state*/)
7920{
7921 TRACE_VISIT_OUT ();
7922
7923 expr* theOffsetExpr = pop_nodestack();
7924
7925 //'offset offset_expr' is rewritten to:
7926 //count $Q{http://zorba.io/internals}count
7927 //where ${http://zorba.io/internals}count ge offset_expr
7928
7929 //1. Add Count Clause
7930 push_scope();
7931 store::Item_t countVar;
7932 theSctx->expand_qname(countVar, "http://zorba.io/internals", "", "count", loc);
7933 var_expr* varExpr = bind_var(loc, countVar, var_expr::count_var, NULL);
7934 count_clause* countClause = theExprManager->create_count_clause(theRootSctx,
7935 loc,
7936 varExpr);
7937 theFlworClausesStack.push_back(countClause);
7938
7939 //2. Create WhereExpr
7940 function* f = BUILTIN_FUNC(OP_GREATER_EQUAL_2);
7941 expr* left = lookup_var(countVar, loc, true);
7942 expr* right = theOffsetExpr;
7943 expr* whereExpr = theExprManager->create_fo_expr(theRootSctx, theUDF, loc, f, left, right);
7944
7945 //3. Add WhereClause
7946 whereExpr = wrap_in_bev(whereExpr);
7947 wrap_in_debugger_expr(whereExpr, whereExpr->get_loc());
7948 where_clause* clause = theExprManager->create_where_clause(theRootSctx,
7949 loc,
7950 whereExpr);
7951 theFlworClausesStack.push_back(clause);
7952}
7953
7954void* begin_visit(const LimitClause& v)
7955{
7956 TRACE_VISIT ();
7957 return no_state;
7958}
7959
7960void end_visit(const LimitClause& v, void* /*visit_state*/)
7961{
7962 TRACE_VISIT_OUT ();
7963 //'limit 3' is rewritten to:
7964 //count $Q{http://zorba.io/internals}count
7965 //where ${http://zorba.io/internals}count lt ($offset + 3)
7966
7967 expr* limitExpr = pop_nodestack();
7968
7969 //1. Add Count Clause
7970 push_scope();
7971 store::Item_t countVar;
7972 theSctx->expand_qname(countVar, "http://zorba.io/internals", "", "count", loc);
7973 var_expr* varExpr = bind_var(loc, countVar, var_expr::count_var, NULL);
7974 count_clause* countClause = theExprManager->create_count_clause(theRootSctx,
7975 loc,
7976 varExpr);
7977 theFlworClausesStack.push_back(countClause);
7978
7979 //4. Create (offset_expr + limit_expr) expr
7980 function* add = BUILTIN_FUNC(OP_ADD_2);
7981 expr* limitPlusOffsetExpr = theExprManager->create_fo_expr(theRootSctx, theUDF, loc, add, theOffsetExpr, limitExpr);
7982
7983 //3. Create WhereExpr
7984 function* f = BUILTIN_FUNC(OP_LESS_2);
7985 expr* left = lookup_var(countVar, loc, true);
7986 expr* right = limitPlusOffsetExpr;
7987 expr* whereExpr = theExprManager->create_fo_expr(theRootSctx, theUDF, loc, f, left, right);
7988
7989 //4. Add WhereClause
7990 whereExpr = wrap_in_bev(whereExpr);
7991 wrap_in_debugger_expr(whereExpr, whereExpr->get_loc());
7992 where_clause* clause = theExprManager->create_where_clause(theRootSctx,
7993 loc,
7994 whereExpr);
7995 theFlworClausesStack.push_back(clause);
7996}
79107997
7911/*******************************************************************************7998/*******************************************************************************
7912 CountClause ::= "count" "$" VarName7999 CountClause ::= "count" "$" VarName
79138000
=== added directory 'test/rbkt/ExpQueryResults/zorba/offset-limit'
=== added file 'test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-1.xml.res'
--- test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-1.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-1.xml.res 2013-07-19 07:43:31 +0000
@@ -0,0 +1,1 @@
15 6
02
=== added file 'test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-2.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-2.xml.res 2013-07-19 07:43:31 +0000
@@ -0,0 +1,1 @@
15 6 7 8 9 10
02
=== added file 'test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-3.xml.res'
--- test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-3.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-3.xml.res 2013-07-19 07:43:31 +0000
@@ -0,0 +1,1 @@
11 2 3 4 5
02
=== added file 'test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-4.xml.res'
--- test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-4.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-4.xml.res 2013-07-19 07:43:31 +0000
@@ -0,0 +1,1 @@
1
02
=== added file 'test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-5.xml.res'
--- test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-5.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/offset-limit/offset-limit-5.xml.res 2013-07-19 07:43:31 +0000
@@ -0,0 +1,1 @@
13
02
=== added directory 'test/rbkt/Queries/zorba/offset-limit'
=== added file 'test/rbkt/Queries/zorba/offset-limit/offset-limit-1.xq'
--- test/rbkt/Queries/zorba/offset-limit/offset-limit-1.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/offset-limit/offset-limit-1.xq 2013-07-19 07:43:31 +0000
@@ -0,0 +1,4 @@
1for $i in (1 to 10)
2offset 5
3limit 2
4return $i
05
=== added file 'test/rbkt/Queries/zorba/offset-limit/offset-limit-2.xq'
--- test/rbkt/Queries/zorba/offset-limit/offset-limit-2.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/offset-limit/offset-limit-2.xq 2013-07-19 07:43:31 +0000
@@ -0,0 +1,3 @@
1for $i in (1 to 10)
2offset 5
3return $i
04
=== added file 'test/rbkt/Queries/zorba/offset-limit/offset-limit-3.xq'
--- test/rbkt/Queries/zorba/offset-limit/offset-limit-3.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/offset-limit/offset-limit-3.xq 2013-07-19 07:43:31 +0000
@@ -0,0 +1,3 @@
1for $i in (1 to 10)
2limit 5
3return $i
04
=== added file 'test/rbkt/Queries/zorba/offset-limit/offset-limit-4.xq'
--- test/rbkt/Queries/zorba/offset-limit/offset-limit-4.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/offset-limit/offset-limit-4.xq 2013-07-19 07:43:31 +0000
@@ -0,0 +1,7 @@
1for $i in (1 to 10)
2offset 2
3limit 5
4limit 2
5offset 5
6limit 1
7return $i
08
=== added file 'test/rbkt/Queries/zorba/offset-limit/offset-limit-5.xq'
--- test/rbkt/Queries/zorba/offset-limit/offset-limit-5.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/offset-limit/offset-limit-5.xq 2013-07-19 07:43:31 +0000
@@ -0,0 +1,7 @@
1for $i in (1 to 10)
2offset 2
3limit 5
4limit 2
5offset 2
6limit 1
7return $i

Subscribers

People subscribed via source and target branches