David Graf has proposed merging lp:~davidagraf/zorba/paging into lp:zorba.

Requested reviews:
  Matthias Brantner (matthias-brantner)
  Till Westmann (tillw)

For more details, see:
https://code.launchpad.net/~davidagraf/zorba/paging/+merge/112611

Positional pagination
-- 
https://code.launchpad.net/~davidagraf/zorba/paging/+merge/112611
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2012-06-28 04:14:03 +0000
+++ ChangeLog	2012-06-28 16:58:18 +0000
@@ -8,6 +8,7 @@
   * New XQuery 3.0 functions
     - fn:parse-xml-fragment#1
   * Added support for transient maps to the http://www.zorba-xquery.com/modules/store/data-structures/unordered-map module.
+	* Positional pagination support for collections
 
 Optimizations:
   * Small optimization of comparison operations.

=== modified file 'src/functions/func_sequences_impl.cpp'
--- src/functions/func_sequences_impl.cpp	2012-06-28 04:14:03 +0000
+++ src/functions/func_sequences_impl.cpp	2012-06-28 16:58:18 +0000
@@ -543,19 +543,19 @@
     ZorbaCollectionIterator& collection =
     static_cast<ZorbaCollectionIterator&>(*argv[0]);
 
-    if (collection.isDynamic())
-    {
-      return new CountCollectionIterator(sctx,
-                                         loc,
-                                         collection.getChildren(),
-                                         CountCollectionIterator::ZORBADYNAMIC);
-    }
-    else
-    {
-      return new CountCollectionIterator(sctx,
-                                         loc,
-                                         collection.getChildren(),
-                                         CountCollectionIterator::ZORBASTATIC);
+    /* no optimization if collection iterator skips nodes */
+    if (!collection.hasSkip())
+    {
+      return new CountCollectionIterator(
+                   sctx,
+                   loc,
+                   collection.getChildren(),
+                   (
+                     collection.isDynamic()
+                       ? CountCollectionIterator::ZORBADYNAMIC
+                       : CountCollectionIterator::ZORBASTATIC
+                   )
+                 );
     }
   }
   else if (typeid(FnCollectionIterator) == counted_type)
@@ -600,10 +600,9 @@
     return new ProbeIndexRangeGeneralIterator(
         sctx, loc, lIter.getChildren(), true);
   }
-  else
-  {
-    return new FnCountIterator(sctx, loc, argv);
-  }
+  
+  // fallback
+  return new FnCountIterator(sctx, loc, argv);
 }
 
 

=== modified file 'src/functions/pregenerated/func_collections.cpp'
--- src/functions/pregenerated/func_collections.cpp	2012-06-28 04:14:03 +0000
+++ src/functions/pregenerated/func_collections.cpp	2012-06-28 16:58:18 +0000
@@ -342,6 +342,19 @@
 
       {
     DECL_WITH_KIND(sctx, static_collections_dml_collection,
+        (createQName("http://www.zorba-xquery.com/modules/store/static/collections/dml","","collection";), 
+        GENV_TYPESYSTEM.QNAME_TYPE_ONE, 
+        GENV_TYPESYSTEM.INTEGER_TYPE_ONE, 
+        GENV_TYPESYSTEM.ANY_NODE_TYPE_STAR),
+        FunctionConsts::STATIC_COLLECTIONS_DML_COLLECTION_2);
+
+  }
+
+
+
+
+      {
+    DECL_WITH_KIND(sctx, static_collections_dml_collection,
         (createQName("http://www.zorba-xquery.com/modules/store/dynamic/collections/dml","","collection";), 
         GENV_TYPESYSTEM.QNAME_TYPE_ONE, 
         GENV_TYPESYSTEM.ANY_NODE_TYPE_STAR),
@@ -353,6 +366,19 @@
 
 
       {
+    DECL_WITH_KIND(sctx, static_collections_dml_collection,
+        (createQName("http://www.zorba-xquery.com/modules/store/dynamic/collections/dml","","collection";), 
+        GENV_TYPESYSTEM.QNAME_TYPE_ONE, 
+        GENV_TYPESYSTEM.INTEGER_TYPE_ONE, 
+        GENV_TYPESYSTEM.ANY_NODE_TYPE_STAR),
+        FunctionConsts::DYNAMIC_COLLECTIONS_DML_COLLECTION_2);
+
+  }
+
+
+
+
+      {
     DECL_WITH_KIND(sctx, static_collections_dml_collection_name,
         (createQName("http://www.zorba-xquery.com/modules/store/static/collections/dml","","collection-name";), 
         GENV_TYPESYSTEM.ANY_NODE_TYPE_ONE, 

=== modified file 'src/functions/pregenerated/function_enum.h'
--- src/functions/pregenerated/function_enum.h	2012-06-28 04:14:03 +0000
+++ src/functions/pregenerated/function_enum.h	2012-06-28 16:58:18 +0000
@@ -54,7 +54,9 @@
   FN_COLLECTION_0,
   FN_COLLECTION_1,
   STATIC_COLLECTIONS_DML_COLLECTION_1,
+  STATIC_COLLECTIONS_DML_COLLECTION_2,
   DYNAMIC_COLLECTIONS_DML_COLLECTION_1,
+  DYNAMIC_COLLECTIONS_DML_COLLECTION_2,
   STATIC_COLLECTIONS_DML_COLLECTION_NAME_1,
   DYNAMIC_COLLECTIONS_DML_COLLECTION_NAME_1,
   STATIC_COLLECTIONS_DML_INDEX_OF_1,

=== modified file 'src/runtime/collections/collections_impl.cpp'
--- src/runtime/collections/collections_impl.cpp	2012-06-28 04:14:03 +0000
+++ src/runtime/collections/collections_impl.cpp	2012-06-28 16:58:18 +0000
@@ -369,7 +369,16 @@
   (void)getCollection(theSctx, name, loc, theIsDynamic, collection);
 
   // return the nodes of the collection
-  state->theIterator = collection->getIterator();
+  if (hasSkip()) {
+    store::Item_t lSkipItem;
+    consumeNext(lSkipItem, theChildren[1].getp(), planState);
+    xs_integer lSkip = lSkipItem->getIntegerValue(); 
+    state->theIterator = collection->getIterator(lSkip);
+  }
+  else {
+    state->theIterator = collection->getIterator();
+  }
+
   ZORBA_ASSERT(state->theIterator != NULL);
   state->theIterator->open();
   state->theIteratorOpened = true;
@@ -384,6 +393,9 @@
   STACK_END(state);
 }
 
+bool ZorbaCollectionIterator::hasSkip() const {
+  return theChildren.size() > 1;
+}
 
 /*******************************************************************************
   declare function index-of($name as xs:QName,

=== modified file 'src/runtime/collections/pregenerated/collections.h'
--- src/runtime/collections/pregenerated/collections.h	2012-06-28 04:14:03 +0000
+++ src/runtime/collections/pregenerated/collections.h	2012-06-28 16:58:18 +0000
@@ -285,6 +285,8 @@
 
   bool isDynamic() const { return theIsDynamic; }
 
+public:
+  bool hasSkip() const;
   void accept(PlanIterVisitor& v) const;
 
   bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;

=== modified file 'src/runtime/spec/collections/collections.xml'
--- src/runtime/spec/collections/collections.xml	2012-06-28 04:14:03 +0000
+++ src/runtime/spec/collections/collections.xml	2012-06-28 16:58:18 +0000
@@ -249,8 +249,20 @@
         <zorba:output>structured-item()*</zorba:output>
       </zorba:signature>
 
-      <zorba:signature localname="collection" prefix="dynamic-collections-dml">
-        <zorba:param>xs:QName</zorba:param>
+      <zorba:signature localname="collection" prefix="static-collections-dml">
+        <zorba:param>xs:QName</zorba:param>
+        <zorba:param>xs:integer</zorba:param><!-- nodes to skip -->
+        <zorba:output>structured-item()*</zorba:output>
+      </zorba:signature>
+
+      <zorba:signature localname="collection" prefix="dynamic-collections-dml">
+        <zorba:param>xs:QName</zorba:param>
+        <zorba:output>structured-item()*</zorba:output>
+      </zorba:signature>
+
+      <zorba:signature localname="collection" prefix="dynamic-collections-dml">
+        <zorba:param>xs:QName</zorba:param>
+        <zorba:param>xs:integer</zorba:param><!-- nodes to skip -->
         <zorba:output>structured-item()*</zorba:output>
       </zorba:signature>
 
@@ -268,6 +280,7 @@
     </zorba:constructor>
 
     <zorba:member type="bool" name="theIsDynamic" getterName="isDynamic"/>
+    <zorba:method const="true" name="hasSkip" return="bool"></zorba:method>
 
     <zorba:state generateInit="false" generateReset="false" generateDestructor="false">
       <zorba:member type="store::Iterator_t" name="theIterator"/>

=== modified file 'src/store/api/collection.h'
--- src/store/api/collection.h	2012-06-28 04:14:03 +0000
+++ src/store/api/collection.h	2012-06-28 16:58:18 +0000
@@ -53,8 +53,21 @@
    *
    * It is allowed to have several concurrent iterators on the same Collection,
    * but each iterator should be used by a single thread only.
+   *
+   * @return Iterator
    */
   virtual Iterator_t getIterator() = 0;
+  
+  /**
+   * Get an iterator to iterate over the nodes of the collection.
+   *
+   * It is allowed to have several concurrent iterators on the same Collection,
+   * but each iterator should be used by a single thread only.
+   *
+   * @param  aPosition The position of the node in the collection. 
+   * @return Iterator
+   */
+  virtual Iterator_t getIterator(xs_integer aSkip) = 0;
 
   /**
    * Get the node at the given position in the collection.

=== modified file 'src/store/naive/collection.h'
--- src/store/naive/collection.h	2012-06-28 04:14:03 +0000
+++ src/store/naive/collection.h	2012-06-28 16:58:18 +0000
@@ -56,6 +56,8 @@
 
   zorba::store::Iterator_t getIterator() = 0;
 
+  zorba::store::Iterator_t getIterator(xs_integer aSkip) = 0;
+
   virtual zorba::store::Item_t nodeAt(xs_integer position) = 0;
 
   virtual bool findNode(const store::Item* node, xs_integer& position) const = 0;

=== modified file 'src/store/naive/simple_collection.cpp'
--- src/store/naive/simple_collection.cpp	2012-06-28 04:14:03 +0000
+++ src/store/naive/simple_collection.cpp	2012-06-28 16:58:18 +0000
@@ -83,7 +83,12 @@
 ********************************************************************************/
 store::Iterator_t SimpleCollection::getIterator()
 {
-  return new CollectionIter(this);
+  return new CollectionIter(this, xs_integer(0));
+}
+
+store::Iterator_t SimpleCollection::getIterator(xs_integer aSkip)
+{
+  return new CollectionIter(this, aSkip);
 }
 
 
@@ -607,10 +612,13 @@
 /*******************************************************************************
 
 ********************************************************************************/
-SimpleCollection::CollectionIter::CollectionIter(SimpleCollection* collection)
+SimpleCollection::CollectionIter::CollectionIter(
+    SimpleCollection* collection,
+    xs_integer aSkip)
   :
   theCollection(collection),
-  theHaveLock(false)
+  theHaveLock(false),
+  theSkip(aSkip)
 {
 }
 
@@ -634,6 +642,7 @@
   theHaveLock = true;
 
   theIterator = theCollection->theXmlTrees.begin();
+  theIterator += to_xs_long(theSkip);
   theEnd = theCollection->theXmlTrees.end();
 }
 
@@ -668,6 +677,7 @@
 void SimpleCollection::CollectionIter::reset()
 {
   theIterator = theCollection->theXmlTrees.begin();
+  theIterator += to_xs_long(theSkip);
   theEnd = theCollection->theXmlTrees.end();
 }
 

=== modified file 'src/store/naive/simple_collection.h'
--- src/store/naive/simple_collection.h	2012-06-28 04:14:03 +0000
+++ src/store/naive/simple_collection.h	2012-06-28 16:58:18 +0000
@@ -54,9 +54,10 @@
     checked_vector<store::Item_t>::iterator theIterator;
     checked_vector<store::Item_t>::iterator theEnd;
     bool                                    theHaveLock;
+    xs_integer                              theSkip;
 
   public:
-    CollectionIter(SimpleCollection* collection);
+    CollectionIter(SimpleCollection* collection, xs_integer aSkip);
 
     ~CollectionIter();
 
@@ -111,6 +112,8 @@
 
   store::Iterator_t getIterator();
 
+  store::Iterator_t getIterator(xs_integer aSkip);
+
   void addNode(store::Item* node, xs_integer position = xs_integer(-1));
 
   xs_integer addNodes(

=== added file 'test/rbkt/ExpQueryResults/zorba/collections/paging_1.xml.res'
--- test/rbkt/ExpQueryResults/zorba/collections/paging_1.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/collections/paging_1.xml.res	2012-06-28 16:58:18 +0000
@@ -0,0 +1,1 @@
+<d/><e/>

=== added file 'test/rbkt/ExpQueryResults/zorba/collections/paging_2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/collections/paging_2.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/collections/paging_2.xml.res	2012-06-28 16:58:18 +0000
@@ -0,0 +1,1 @@
+2

=== added file 'test/rbkt/Queries/zorba/collections/paging_1.xq'
--- test/rbkt/Queries/zorba/collections/paging_1.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/collections/paging_1.xq	2012-06-28 16:58:18 +0000
@@ -0,0 +1,17 @@
+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";;
+import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";;
+import module namespace ns = "http://example.org/datamodule/"; at "collections.xqdata";
+
+declare namespace ann = "http://www.zorba-xquery.com/annotations";;
+
+declare %ann:sequential function local:test()
+{
+  ddl:create(xs:QName("ns:test2"));
+  dml:insert-nodes(xs:QName("ns:test2"), <a/>);
+  dml:insert-nodes(xs:QName("ns:test2"), <b/>);
+  dml:insert-nodes(xs:QName("ns:test2"), (<c/>, <d/>, <e/>));
+  dml:collection(xs:QName("ns:test2"), 3)
+};
+
+local:test()
+

=== added file 'test/rbkt/Queries/zorba/collections/paging_2.xq'
--- test/rbkt/Queries/zorba/collections/paging_2.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/collections/paging_2.xq	2012-06-28 16:58:18 +0000
@@ -0,0 +1,17 @@
+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";;
+import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";;
+import module namespace ns = "http://example.org/datamodule/"; at "collections.xqdata";
+
+declare namespace ann = "http://www.zorba-xquery.com/annotations";;
+
+declare %ann:sequential function local:test()
+{
+  ddl:create(xs:QName("ns:test2"));
+  dml:insert-nodes(xs:QName("ns:test2"), <a/>);
+  dml:insert-nodes(xs:QName("ns:test2"), <b/>);
+  dml:insert-nodes(xs:QName("ns:test2"), (<c/>, <d/>, <e/>));
+  fn:count(dml:collection(xs:QName("ns:test2"), 3))
+};
+
+local:test()
+

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to