Merge lp:~davidagraf/zorba/paging_with_refs into lp:zorba

Proposed by David Graf
Status: Merged
Approved by: David Graf
Approved revision: 10996
Merged at revision: 11037
Proposed branch: lp:~davidagraf/zorba/paging_with_refs
Merge into: lp:zorba
Diff against target: 697 lines (+278/-53)
27 files modified
include/zorba/pregenerated/diagnostic_list.h (+2/-0)
modules/com/zorba-xquery/www/modules/pregenerated/errors.xq (+4/-0)
modules/com/zorba-xquery/www/modules/store/dynamic/collections/dml.xq (+29/-0)
modules/com/zorba-xquery/www/modules/store/static/collections/dml.xq (+27/-0)
src/diagnostics/diagnostic_en.xml (+4/-0)
src/diagnostics/pregenerated/diagnostic_list.cpp (+3/-0)
src/diagnostics/pregenerated/dict_en.cpp (+1/-0)
src/functions/func_sequences_impl.cpp (+13/-10)
src/functions/pregenerated/func_collections.cpp (+28/-0)
src/functions/pregenerated/function_enum.h (+2/-0)
src/runtime/collections/collections_impl.cpp (+41/-13)
src/runtime/collections/pregenerated/collections.h (+2/-0)
src/runtime/spec/collections/collections.xml (+27/-7)
src/store/api/collection.h (+4/-2)
src/store/naive/collection.h (+3/-1)
src/store/naive/simple_collection.cpp (+32/-4)
src/store/naive/simple_collection.h (+6/-2)
test/rbkt/ExpQueryResults/zorba/collections/paging_1.xml.res (+1/-1)
test/rbkt/ExpQueryResults/zorba/collections/paging_2.xml.res (+1/-1)
test/rbkt/ExpQueryResults/zorba/collections/paging_3.xml.res (+1/-1)
test/rbkt/ExpQueryResults/zorba/collections/paging_4.xml.res (+1/-1)
test/rbkt/Queries/zorba/collections/paging_1.xq (+12/-3)
test/rbkt/Queries/zorba/collections/paging_2.xq (+4/-2)
test/rbkt/Queries/zorba/collections/paging_3.xq (+5/-3)
test/rbkt/Queries/zorba/collections/paging_4.xq (+4/-2)
test/rbkt/Queries/zorba/collections/paging_5.spec (+1/-0)
test/rbkt/Queries/zorba/collections/paging_5.xq (+20/-0)
To merge this branch: bzr merge lp:~davidagraf/zorba/paging_with_refs
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Till Westmann Approve
Review via email: mp+123509@code.launchpad.net

This proposal supersedes a proposal from 2012-08-14.

Commit message

feature: skipping nodes in a collection using a node-reference

Description of the change

Resubmit to trigger patchqueue.

To post a comment you must log in.
Revision history for this message
Matthias Brantner (matthias-brantner) wrote : Posted in a previous version of this proposal

- Given the documentation, I was not able to figure out why the collection
function takes the $start and $skip parameters. Is one of the ignored if
the other one is given? Does skipping start at the item identified by
$start? If so, would it make sense to separate the two ways of skipping
into separate functions?

- improved
The reference to first node to return
=>
A reference to the first node to return.

- What does "order is implementation dependent" mean for ordered collections?

- Error message can be improved according to Paul's style:

Node reference $1 doesn't reference a node in collection $2
=>
$1: doesn't reference a node in collection ($2)

- typo:
if the passed reference $start doesn't reference
a _not_ from the collection identified by $name.

- the documentation mention zerr:ZAPI0028 if the given URI
is not a valid node reference

review: Needs Fixing
Revision history for this message
David Graf (davidagraf) wrote : Posted in a previous version of this proposal

> - Given the documentation, I was not able to figure out why the collection
> function takes the $start and $skip parameters. Is one of the ignored if
> the other one is given? Does skipping start at the item identified by
> $start? If so, would it make sense to separate the two ways of skipping
> into separate functions?
No, none is ignored. If you don't wanna skip, you pass 0. If you wanna skip only, you use db:collection($name, $skip). The goal was to not introduce additional function. I think there are already enough dml and ddl functions. If you want, I can make $skip optional.
But as already mentioned in a yammer message, I am thinking about replacing the $skip parameter with an optimisation for fn:subsequence(db:collection(), $start). To get rid of additional stuff.
>
Fixed everything below:
> - improved
> The reference to first node to return
> =>
> A reference to the first node to return.
>
> - What does "order is implementation dependent" mean for ordered collections?
>
> - Error message can be improved according to Paul's style:
>
> Node reference $1 doesn't reference a node in collection $2
> =>
> $1: doesn't reference a node in collection ($2)
>
> - typo:
> if the passed reference $start doesn't reference
> a _not_ from the collection identified by $name.
>
> - the documentation mention zerr:ZAPI0028 if the given URI
> is not a valid node reference

Revision history for this message
Till Westmann (tillw) wrote : Posted in a previous version of this proposal

There are a few small fixes that I've sent as a patch via email as I could not push them into this branch. Once this patch is applied this branch works for me.

review: Needs Fixing
Revision history for this message
Matthias Brantner (matthias-brantner) wrote : Posted in a previous version of this proposal

The patch looks great.

As far as I can tell, the documentation should also mention the error zerr:ZAPI0028.

review: Needs Fixing
Revision history for this message
David Graf (davidagraf) wrote : Posted in a previous version of this proposal

> There are a few small fixes that I've sent as a patch via email as I could not
> push them into this branch. Once this patch is applied this branch works for
> me.

I patched you patch. Unfortunately, I needed to do it by hand. Did you create the patch with bzr diff?

Revision history for this message
David Graf (davidagraf) wrote : Posted in a previous version of this proposal

> The patch looks great.
>
> As far as I can tell, the documentation should also mention the error
> zerr:ZAPI0028.
done

Revision history for this message
Till Westmann (tillw) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Matthias Brantner (matthias-brantner) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Till Westmann (tillw) :
review: Approve
Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~davidagraf/zorba/paging_with_refs into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:274 (message):
  Validation queue job paging_with_refs-2012-09-10T19-15-08.776Z is finished.
  The final status was:

  2 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~davidagraf/zorba/paging_with_refs into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:274 (message):
  Validation queue job paging_with_refs-2012-09-12T11-18-03.523Z is finished.
  The final status was:

  1 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

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 paging_with_refs-2012-09-12T13-08-49.816Z 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
=== modified file 'include/zorba/pregenerated/diagnostic_list.h'
--- include/zorba/pregenerated/diagnostic_list.h 2012-09-12 08:06:26 +0000
+++ include/zorba/pregenerated/diagnostic_list.h 2012-09-12 11:09:20 +0000
@@ -750,6 +750,8 @@
750750
751extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZSTR0065_STRINGS_IN_POOL;751extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZSTR0065_STRINGS_IN_POOL;
752752
753extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZSTR0066_REFERENCED_NODE_NOT_IN_COLLECTION;
754
753extern ZORBA_DLL_PUBLIC ZorbaErrorCode XSST0001;755extern ZORBA_DLL_PUBLIC ZorbaErrorCode XSST0001;
754756
755extern ZORBA_DLL_PUBLIC ZorbaErrorCode XSST0002;757extern ZORBA_DLL_PUBLIC ZorbaErrorCode XSST0002;
756758
=== modified file 'modules/com/zorba-xquery/www/modules/pregenerated/errors.xq'
--- modules/com/zorba-xquery/www/modules/pregenerated/errors.xq 2012-09-10 22:53:04 +0000
+++ modules/com/zorba-xquery/www/modules/pregenerated/errors.xq 2012-09-12 11:09:20 +0000
@@ -781,6 +781,10 @@
781781
782(:~782(:~
783:)783:)
784declare variable $zerr:ZSTR0066 as xs:QName := fn:QName($zerr:NS, "zerr:ZSTR0066");
785
786(:~
787:)
784declare variable $zerr:XSST0001 as xs:QName := fn:QName($zerr:NS, "zerr:XSST0001");788declare variable $zerr:XSST0001 as xs:QName := fn:QName($zerr:NS, "zerr:XSST0001");
785789
786(:~790(:~
787791
=== modified file 'modules/com/zorba-xquery/www/modules/store/dynamic/collections/dml.xq'
--- modules/com/zorba-xquery/www/modules/store/dynamic/collections/dml.xq 2012-09-10 22:53:04 +0000
+++ modules/com/zorba-xquery/www/modules/store/dynamic/collections/dml.xq 2012-09-12 11:09:20 +0000
@@ -632,6 +632,35 @@
632632
633633
634(:~634(:~
635 : The collection function returns the sequence of nodes and/or json items
636 : that belong to the collection identified by the given name.
637 : The parameters $start and $skip can be used to skip over some items at
638 : the beginning of the collection. If both are given, both are applied:
639 : first $start to skip to the referenced item and then $skip to skip an
640 : additional number of items.
641 :
642 : @param $name The name of the collection.
643 : @param $start A reference to the first item to return. All items before
644 are skipped.
645 : @param $skip The number of collection items to skip.
646 :
647 : @return The sequence contained in the given collection.
648 :
649 : @error zerr:ZAPI0028 If the given URI is not a valid node
650 : position computed by the <tt>np:node-position</tt> function.
651 : @error zerr:ZDDY0003 If available collections does not provide a mapping
652 : for the expanded QName $name.
653 : @error zerr:ZSTR0066 If the passed reference $start does not reference
654 : a node from the collection identified by $name.
655 :
656 :)
657declare function
658dml:collection($name as xs:QName,
659 $start as xs:anyURI,
660 $skip as xs:integer) as item()* external;
661
662
663(:~
635 : The collection-name function returns the name of the collection the given664 : The collection-name function returns the name of the collection the given
636 : item (node or json item) belongs to.665 : item (node or json item) belongs to.
637 :666 :
638667
=== modified file 'modules/com/zorba-xquery/www/modules/store/static/collections/dml.xq'
--- modules/com/zorba-xquery/www/modules/store/static/collections/dml.xq 2012-09-10 22:53:04 +0000
+++ modules/com/zorba-xquery/www/modules/store/static/collections/dml.xq 2012-09-12 11:09:20 +0000
@@ -884,6 +884,33 @@
884884
885885
886(:~886(:~
887 : The collection function returns the sequence of nodes and/or json items
888 : that belong to the collection identified by the given name.
889 : The parameters $start and $skip can be used to skip over some items at
890 : the beginning of the collection. If both are given, both are applied:
891 : first $start to skip to the referenced item and then $skip to skip an
892 : additional number of items.
893 :
894 : @param $name The name of the collection.
895 : @param $start The reference to the first item to return. All items before
896 are skipped.
897 : @param $skip The number of collection items to skip.
898 :
899 : @return The sequence contained in the given collection.
900 :
901 : @error zerr:ZAPI0028 If the given URI is not a valid node
902 : position computed by the <tt>np:node-position</tt> function.
903 : @error zerr:ZDDY0001 if the collection identified by $name is not declared.
904 : @error zerr:ZDDY0003 if the collection identified by $name is not available.
905 : @error zerr:ZSTR0066 if the passed reference $start does not reference
906 : a node from the collection identified by $name.
907 :
908 :)
909declare function
910cdml:collection($name as xs:QName,
911 $start as xs:anyURI,
912 $skip as xs:integer) as item()* external;
913(:~
887 : The collection-name function returns the name of the collection the given914 : The collection-name function returns the name of the collection the given
888 : item (node or json item) belongs to.915 : item (node or json item) belongs to.
889 :916 :
890917
=== modified file 'src/diagnostics/diagnostic_en.xml'
--- src/diagnostics/diagnostic_en.xml 2012-09-12 08:06:26 +0000
+++ src/diagnostics/diagnostic_en.xml 2012-09-12 11:09:20 +0000
@@ -2433,6 +2433,10 @@
2433 <value>Zorba did not close properly, objects may still in memory.\n$1 referenced URI(s) remain in the string pool.\nFor help avoiding this message please refer to http://www.zorba-xquery.com/html/documentation in section General Architecture -> Memory Leaks.</value>2433 <value>Zorba did not close properly, objects may still in memory.\n$1 referenced URI(s) remain in the string pool.\nFor help avoiding this message please refer to http://www.zorba-xquery.com/html/documentation in section General Architecture -> Memory Leaks.</value>
2434 </diagnostic>2434 </diagnostic>
24352435
2436 <diagnostic code="ZSTR0066" name="REFERENCED_NODE_NOT_IN_COLLECTION">
2437 <value>$1: does not reference a node in collection $2.</value>
2438 </diagnostic>
2439
2436 <!--////////// XQuery Scripting ////////////////////////////////////////-->2440 <!--////////// XQuery Scripting ////////////////////////////////////////-->
24372441
2438 <diagnostic code="XSST0001">2442 <diagnostic code="XSST0001">
24392443
=== modified file 'src/diagnostics/pregenerated/diagnostic_list.cpp'
--- src/diagnostics/pregenerated/diagnostic_list.cpp 2012-09-12 08:06:26 +0000
+++ src/diagnostics/pregenerated/diagnostic_list.cpp 2012-09-12 11:09:20 +0000
@@ -1103,6 +1103,9 @@
1103ZorbaErrorCode ZSTR0065_STRINGS_IN_POOL( "ZSTR0065" );1103ZorbaErrorCode ZSTR0065_STRINGS_IN_POOL( "ZSTR0065" );
11041104
11051105
1106ZorbaErrorCode ZSTR0066_REFERENCED_NODE_NOT_IN_COLLECTION( "ZSTR0066" );
1107
1108
1106ZorbaErrorCode XSST0001( "XSST0001" );1109ZorbaErrorCode XSST0001( "XSST0001" );
11071110
11081111
11091112
=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
--- src/diagnostics/pregenerated/dict_en.cpp 2012-09-12 08:06:26 +0000
+++ src/diagnostics/pregenerated/dict_en.cpp 2012-09-12 11:09:20 +0000
@@ -453,6 +453,7 @@
453 { "ZSTR0055", "streamable string has already been consumed" },453 { "ZSTR0055", "streamable string has already been consumed" },
454 { "ZSTR0060", "out of range: $1" },454 { "ZSTR0060", "out of range: $1" },
455 { "ZSTR0065", "Zorba did not close properly, objects may still in memory.\n$1 referenced URI(s) remain in the string pool.\nFor help avoiding this message please refer to http://www.zorba-xquery.com/html/documentation in section General Architecture -> Memory Leaks." },455 { "ZSTR0065", "Zorba did not close properly, objects may still in memory.\n$1 referenced URI(s) remain in the string pool.\nFor help avoiding this message please refer to http://www.zorba-xquery.com/html/documentation in section General Architecture -> Memory Leaks." },
456 { "ZSTR0066", "$1: does not reference a node in collection $2." },
456 { "ZWST0002", "\"$1\": unknown or unsupported annotation" },457 { "ZWST0002", "\"$1\": unknown or unsupported annotation" },
457 { "ZWST0003", "\"$1\": function declared sequential, but has non-sequential body" },458 { "ZWST0003", "\"$1\": function declared sequential, but has non-sequential body" },
458 { "ZWST0004", "Sequential FLWOR expr may not have the semantics you expect" },459 { "ZWST0004", "Sequential FLWOR expr may not have the semantics you expect" },
459460
=== modified file 'src/functions/func_sequences_impl.cpp'
--- src/functions/func_sequences_impl.cpp 2012-09-10 22:53:04 +0000
+++ src/functions/func_sequences_impl.cpp 2012-09-12 11:09:20 +0000
@@ -543,16 +543,19 @@
543 ZorbaCollectionIterator& collection =543 ZorbaCollectionIterator& collection =
544 static_cast<ZorbaCollectionIterator&>(*argv[0]);544 static_cast<ZorbaCollectionIterator&>(*argv[0]);
545545
546 return new CountCollectionIterator(546 if (collection.isCountOptimizable())
547 sctx,547 {
548 loc,548 return new CountCollectionIterator(
549 collection.getChildren(),549 sctx,
550 (550 loc,
551 collection.isDynamic()551 collection.getChildren(),
552 ? CountCollectionIterator::ZORBADYNAMIC552 (
553 : CountCollectionIterator::ZORBASTATIC553 collection.isDynamic()
554 )554 ? CountCollectionIterator::ZORBADYNAMIC
555 );555 : CountCollectionIterator::ZORBASTATIC
556 )
557 );
558 }
556 }559 }
557 else if (typeid(FnCollectionIterator) == counted_type)560 else if (typeid(FnCollectionIterator) == counted_type)
558 {561 {
559562
=== modified file 'src/functions/pregenerated/func_collections.cpp'
--- src/functions/pregenerated/func_collections.cpp 2012-09-10 22:53:04 +0000
+++ src/functions/pregenerated/func_collections.cpp 2012-09-12 11:09:20 +0000
@@ -355,6 +355,20 @@
355355
356 {356 {
357 DECL_WITH_KIND(sctx, static_collections_dml_collection,357 DECL_WITH_KIND(sctx, static_collections_dml_collection,
358 (createQName("http://www.zorba-xquery.com/modules/store/static/collections/dml","","collection"),
359 GENV_TYPESYSTEM.QNAME_TYPE_ONE,
360 GENV_TYPESYSTEM.ANY_URI_TYPE_ONE,
361 GENV_TYPESYSTEM.INTEGER_TYPE_ONE,
362 GENV_TYPESYSTEM.STRUCTURED_ITEM_TYPE_STAR),
363 FunctionConsts::STATIC_COLLECTIONS_DML_COLLECTION_3);
364
365 }
366
367
368
369
370 {
371 DECL_WITH_KIND(sctx, static_collections_dml_collection,
358 (createQName("http://www.zorba-xquery.com/modules/store/dynamic/collections/dml","","collection"), 372 (createQName("http://www.zorba-xquery.com/modules/store/dynamic/collections/dml","","collection"),
359 GENV_TYPESYSTEM.QNAME_TYPE_ONE, 373 GENV_TYPESYSTEM.QNAME_TYPE_ONE,
360 GENV_TYPESYSTEM.STRUCTURED_ITEM_TYPE_STAR),374 GENV_TYPESYSTEM.STRUCTURED_ITEM_TYPE_STAR),
@@ -379,6 +393,20 @@
379393
380394
381 {395 {
396 DECL_WITH_KIND(sctx, static_collections_dml_collection,
397 (createQName("http://www.zorba-xquery.com/modules/store/dynamic/collections/dml","","collection"),
398 GENV_TYPESYSTEM.QNAME_TYPE_ONE,
399 GENV_TYPESYSTEM.ANY_URI_TYPE_ONE,
400 GENV_TYPESYSTEM.INTEGER_TYPE_ONE,
401 GENV_TYPESYSTEM.STRUCTURED_ITEM_TYPE_STAR),
402 FunctionConsts::DYNAMIC_COLLECTIONS_DML_COLLECTION_3);
403
404 }
405
406
407
408
409 {
382 DECL_WITH_KIND(sctx, static_collections_dml_collection_name,410 DECL_WITH_KIND(sctx, static_collections_dml_collection_name,
383 (createQName("http://www.zorba-xquery.com/modules/store/static/collections/dml","","collection-name"), 411 (createQName("http://www.zorba-xquery.com/modules/store/static/collections/dml","","collection-name"),
384 GENV_TYPESYSTEM.STRUCTURED_ITEM_TYPE_ONE, 412 GENV_TYPESYSTEM.STRUCTURED_ITEM_TYPE_ONE,
385413
=== modified file 'src/functions/pregenerated/function_enum.h'
--- src/functions/pregenerated/function_enum.h 2012-09-11 16:33:21 +0000
+++ src/functions/pregenerated/function_enum.h 2012-09-12 11:09:20 +0000
@@ -55,8 +55,10 @@
55 FN_COLLECTION_1,55 FN_COLLECTION_1,
56 STATIC_COLLECTIONS_DML_COLLECTION_1,56 STATIC_COLLECTIONS_DML_COLLECTION_1,
57 STATIC_COLLECTIONS_DML_COLLECTION_2,57 STATIC_COLLECTIONS_DML_COLLECTION_2,
58 STATIC_COLLECTIONS_DML_COLLECTION_3,
58 DYNAMIC_COLLECTIONS_DML_COLLECTION_1,59 DYNAMIC_COLLECTIONS_DML_COLLECTION_1,
59 DYNAMIC_COLLECTIONS_DML_COLLECTION_2,60 DYNAMIC_COLLECTIONS_DML_COLLECTION_2,
61 DYNAMIC_COLLECTIONS_DML_COLLECTION_3,
60 STATIC_COLLECTIONS_DML_COLLECTION_NAME_1,62 STATIC_COLLECTIONS_DML_COLLECTION_NAME_1,
61 DYNAMIC_COLLECTIONS_DML_COLLECTION_NAME_1,63 DYNAMIC_COLLECTIONS_DML_COLLECTION_NAME_1,
62 STATIC_COLLECTIONS_DML_INDEX_OF_1,64 STATIC_COLLECTIONS_DML_INDEX_OF_1,
6365
=== modified file 'src/runtime/collections/collections_impl.cpp'
--- src/runtime/collections/collections_impl.cpp 2012-09-10 22:53:04 +0000
+++ src/runtime/collections/collections_impl.cpp 2012-09-12 11:09:20 +0000
@@ -367,6 +367,12 @@
367 }367 }
368}368}
369369
370bool ZorbaCollectionIterator::isCountOptimizable() const
371{
372 // if ref is passed to the collections function, count cannot be
373 // optimized anymore.
374 return theChildren.size() <= 2;
375}
370376
371bool ZorbaCollectionIterator::nextImpl(377bool ZorbaCollectionIterator::nextImpl(
372 store::Item_t& result,378 store::Item_t& result,
@@ -375,6 +381,7 @@
375 store::Item_t name;381 store::Item_t name;
376 store::Collection_t collection;382 store::Collection_t collection;
377 xs_integer lSkip;383 xs_integer lSkip;
384 zstring lStart;
378385
379 ZorbaCollectionIteratorState* state;386 ZorbaCollectionIteratorState* state;
380 DEFAULT_STACK_INIT(ZorbaCollectionIteratorState, state, planState);387 DEFAULT_STACK_INIT(ZorbaCollectionIteratorState, state, planState);
@@ -383,21 +390,42 @@
383390
384 (void)getCollection(theSctx, name, loc, theIsDynamic, collection);391 (void)getCollection(theSctx, name, loc, theIsDynamic, collection);
385392
386 if (theChildren.size() > 1)393 if (theChildren.size() == 1)
387 {394 {
388 // skip parameter passed395 state->theIterator = collection->getIterator();
396 }
397 else
398 {
399 bool lRefPassed = theChildren.size() >= 3;
400
401 // read positional skip parameter
389 store::Item_t lSkipItem;402 store::Item_t lSkipItem;
390 consumeNext(lSkipItem, theChildren[1].getp(), planState);403 consumeNext(lSkipItem, theChildren[(lRefPassed ? 2 : 1)].getp(), planState);
391 lSkip = lSkipItem->getIntegerValue(); 404 lSkip = lSkipItem->getIntegerValue();
392 // negative is transformed into 0405 // negative skip is not allowed
393 state->theIterator = ( lSkip > xs_integer::zero() 406 if (lSkip < xs_integer::zero())
394 ? collection->getIterator(lSkip)407 {
395 : collection->getIterator()408 lSkip = xs_integer::zero();
396 );409 }
397 }410 if (!lRefPassed)
398 else411 {
399 {412 state->theIterator = collection->getIterator(lSkip);
400 state->theIterator = collection->getIterator();413 }
414 else
415 {
416 store::Item_t lRefItem;
417 consumeNext(lRefItem, theChildren[1].getp(), planState);
418 lStart = lRefItem->getString();
419 try
420 {
421 state->theIterator = collection->getIterator(lSkip, lStart);
422 }
423 catch (ZorbaException& e)
424 {
425 set_source(e, loc);
426 throw;
427 }
428 }
401 }429 }
402430
403 ZORBA_ASSERT(state->theIterator != NULL);431 ZORBA_ASSERT(state->theIterator != NULL);
404432
=== modified file 'src/runtime/collections/pregenerated/collections.h'
--- src/runtime/collections/pregenerated/collections.h 2012-09-10 22:53:04 +0000
+++ src/runtime/collections/pregenerated/collections.h 2012-09-12 11:09:20 +0000
@@ -285,6 +285,8 @@
285285
286 bool isDynamic() const { return theIsDynamic; }286 bool isDynamic() const { return theIsDynamic; }
287287
288public:
289 bool isCountOptimizable() const;
288 void accept(PlanIterVisitor& v) const;290 void accept(PlanIterVisitor& v) const;
289291
290 bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;292 bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;
291293
=== modified file 'src/runtime/spec/collections/collections.xml'
--- src/runtime/spec/collections/collections.xml 2012-09-10 22:53:04 +0000
+++ src/runtime/spec/collections/collections.xml 2012-09-12 11:09:20 +0000
@@ -255,13 +255,29 @@
255 <zorba:output>structured-item()*</zorba:output>255 <zorba:output>structured-item()*</zorba:output>
256 </zorba:signature>256 </zorba:signature>
257257
258 <zorba:signature localname="collection" prefix="dynamic-collections-dml">258 <zorba:signature localname="collection"
259 <zorba:param>xs:QName</zorba:param>259 prefix="static-collections-dml">
260 <zorba:output>structured-item()*</zorba:output>260 <zorba:param>xs:QName</zorba:param>
261 </zorba:signature>261 <zorba:param>xs:anyURI</zorba:param><!-- start ref -->
262262 <zorba:param>xs:integer</zorba:param><!-- nodes to skip -->
263 <zorba:signature localname="collection" prefix="dynamic-collections-dml">263 <zorba:output>structured-item()*</zorba:output>
264 <zorba:param>xs:QName</zorba:param>264 </zorba:signature>
265
266 <zorba:signature localname="collection" prefix="dynamic-collections-dml">
267 <zorba:param>xs:QName</zorba:param>
268 <zorba:output>structured-item()*</zorba:output>
269 </zorba:signature>
270
271 <zorba:signature localname="collection" prefix="dynamic-collections-dml">
272 <zorba:param>xs:QName</zorba:param>
273 <zorba:param>xs:integer</zorba:param><!-- start to skip -->
274 <zorba:output>structured-item()*</zorba:output>
275 </zorba:signature>
276
277 <zorba:signature localname="collection"
278 prefix="dynamic-collections-dml">
279 <zorba:param>xs:QName</zorba:param>
280 <zorba:param>xs:anyURI</zorba:param><!-- node ref-->
265 <zorba:param>xs:integer</zorba:param><!-- nodes to skip -->281 <zorba:param>xs:integer</zorba:param><!-- nodes to skip -->
266 <zorba:output>structured-item()*</zorba:output>282 <zorba:output>structured-item()*</zorba:output>
267 </zorba:signature>283 </zorba:signature>
@@ -281,6 +297,10 @@
281297
282 <zorba:member type="bool" name="theIsDynamic" getterName="isDynamic"/>298 <zorba:member type="bool" name="theIsDynamic" getterName="isDynamic"/>
283299
300 <zorba:method const="true"
301 name="isCountOptimizable"
302 return="bool" />
303
284 <zorba:state generateInit="false" generateReset="false" generateDestructor="false">304 <zorba:state generateInit="false" generateReset="false" generateDestructor="false">
285 <zorba:member type="store::Iterator_t" name="theIterator"/>305 <zorba:member type="store::Iterator_t" name="theIterator"/>
286 <zorba:member type="bool" name="theIteratorOpened" defaultValue="false"/>306 <zorba:member type="bool" name="theIteratorOpened" defaultValue="false"/>
287307
=== modified file 'src/store/api/collection.h'
--- src/store/api/collection.h 2012-09-10 22:53:04 +0000
+++ src/store/api/collection.h 2012-09-12 11:09:20 +0000
@@ -54,11 +54,13 @@
54 * It is allowed to have several concurrent iterators on the same Collection,54 * It is allowed to have several concurrent iterators on the same Collection,
55 * but each iterator should be used by a single thread only.55 * but each iterator should be used by a single thread only.
56 *56 *
57 * @param aSkip The number of collection entries to skip.57 * @param aSkip The number of collection items to skip.
58 * @param aStart The reference to the first node. All nodes before are skipped.
58 * @return Iterator59 * @return Iterator
59 */60 */
60 virtual Iterator_t getIterator(61 virtual Iterator_t getIterator(
61 const xs_integer& aSkip = xs_integer::zero()) = 0;62 const xs_integer& aSkip = xs_integer::zero(),
63 const zstring& aStart = "") = 0;
6264
63 /**65 /**
64 * Get the node at the given position in the collection.66 * Get the node at the given position in the collection.
6567
=== modified file 'src/store/naive/collection.h'
--- src/store/naive/collection.h 2012-09-10 22:53:04 +0000
+++ src/store/naive/collection.h 2012-09-12 11:09:20 +0000
@@ -54,7 +54,9 @@
5454
55 zorba::xs_integer size() const = 0;55 zorba::xs_integer size() const = 0;
5656
57 zorba::store::Iterator_t getIterator(const xs_integer& aSkip) = 0;57 zorba::store::Iterator_t getIterator(
58 const xs_integer& aSkip,
59 const zstring& aStart) = 0;
5860
59 virtual zorba::store::Item_t nodeAt(xs_integer position) = 0;61 virtual zorba::store::Item_t nodeAt(xs_integer position) = 0;
6062
6163
=== modified file 'src/store/naive/simple_collection.cpp'
--- src/store/naive/simple_collection.cpp 2012-09-10 22:53:04 +0000
+++ src/store/naive/simple_collection.cpp 2012-09-12 11:09:20 +0000
@@ -81,9 +81,22 @@
81 Note: it is allowed to have several concurrent iterators on the same collection81 Note: it is allowed to have several concurrent iterators on the same collection
82 but each iterator should be used by a single thread only.82 but each iterator should be used by a single thread only.
83********************************************************************************/83********************************************************************************/
84store::Iterator_t SimpleCollection::getIterator(const xs_integer& aSkip)84store::Iterator_t SimpleCollection::getIterator(const xs_integer& aSkip,
85 const zstring& aStart)
85{86{
86 return new CollectionIter(this, aSkip);87 store::Item_t lReferencedNode;
88 xs_integer lReferencedPosition = xs_integer::zero();
89 if (aStart.size() != 0
90 && (!GET_STORE().getNodeByReference(lReferencedNode, aStart)
91 || !findNode(lReferencedNode.getp(), lReferencedPosition)))
92 {
93 throw ZORBA_EXCEPTION(zerr::ZSTR0066_REFERENCED_NODE_NOT_IN_COLLECTION,
94 ERROR_PARAMS(aStart, theName->getStringValue()));
95 }
96
97 return new CollectionIter(
98 this,
99 aSkip + lReferencedPosition);
87}100}
88101
89102
@@ -596,6 +609,21 @@
596 theCollection->theLatch.unlock();)609 theCollection->theLatch.unlock();)
597}610}
598611
612void SimpleCollection::CollectionIter::skip()
613{
614 // skip by position
615 long lToSkip = to_xs_long(theSkip);
616 if (theSkip >= theCollection->size())
617 {
618 // we need to skip more then possible -> jump to the end
619 theIterator = theEnd;
620 }
621 else
622 {
623 theIterator += to_xs_long(theSkip);
624 }
625}
626
599627
600/*******************************************************************************628/*******************************************************************************
601629
@@ -606,8 +634,8 @@
606 theHaveLock = true;634 theHaveLock = true;
607635
608 theIterator = theCollection->theXmlTrees.begin();636 theIterator = theCollection->theXmlTrees.begin();
609 theIterator += to_xs_long(theSkip);
610 theEnd = theCollection->theXmlTrees.end();637 theEnd = theCollection->theXmlTrees.end();
638 skip();
611}639}
612640
613641
@@ -641,8 +669,8 @@
641void SimpleCollection::CollectionIter::reset()669void SimpleCollection::CollectionIter::reset()
642{670{
643 theIterator = theCollection->theXmlTrees.begin();671 theIterator = theCollection->theXmlTrees.begin();
644 theIterator += to_xs_long(theSkip);
645 theEnd = theCollection->theXmlTrees.end();672 theEnd = theCollection->theXmlTrees.end();
673 skip();
646}674}
647675
648676
649677
=== modified file 'src/store/naive/simple_collection.h'
--- src/store/naive/simple_collection.h 2012-09-10 22:53:04 +0000
+++ src/store/naive/simple_collection.h 2012-09-12 11:09:20 +0000
@@ -57,7 +57,8 @@
57 xs_integer theSkip;57 xs_integer theSkip;
5858
59 public:59 public:
60 CollectionIter(SimpleCollection* collection, const xs_integer& aSkip);60 CollectionIter(SimpleCollection* collection,
61 const xs_integer& aSkip);
6162
62 ~CollectionIter();63 ~CollectionIter();
6364
@@ -65,6 +66,8 @@
65 bool next(store::Item_t& result);66 bool next(store::Item_t& result);
66 void reset();67 void reset();
67 void close();68 void close();
69 private:
70 void skip();
68 };71 };
6972
7073
@@ -110,7 +113,8 @@
110113
111 TreeId createTreeId();114 TreeId createTreeId();
112115
113 store::Iterator_t getIterator(const xs_integer& aSkip);116 store::Iterator_t getIterator(const xs_integer& aSkip,
117 const zstring& aStart);
114118
115 void addNode(store::Item* node, xs_integer position = xs_integer(-1));119 void addNode(store::Item* node, xs_integer position = xs_integer(-1));
116120
117121
=== modified file 'test/rbkt/ExpQueryResults/zorba/collections/paging_1.xml.res'
--- test/rbkt/ExpQueryResults/zorba/collections/paging_1.xml.res 2012-06-28 18:19:34 +0000
+++ test/rbkt/ExpQueryResults/zorba/collections/paging_1.xml.res 2012-09-12 11:09:20 +0000
@@ -1,1 +1,1 @@
1<d/><e/><a/><b/><c/><d/><e/>1<d/><e/><delim/><a/><b/><c/><d/><e/><delim/><c/><d/><e/>
22
=== modified file 'test/rbkt/ExpQueryResults/zorba/collections/paging_2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/collections/paging_2.xml.res 2012-06-28 18:19:34 +0000
+++ test/rbkt/ExpQueryResults/zorba/collections/paging_2.xml.res 2012-09-12 11:09:20 +0000
@@ -1,1 +1,1 @@
12 5 012 5 0 3
22
=== modified file 'test/rbkt/ExpQueryResults/zorba/collections/paging_3.xml.res'
--- test/rbkt/ExpQueryResults/zorba/collections/paging_3.xml.res 2012-06-28 18:19:34 +0000
+++ test/rbkt/ExpQueryResults/zorba/collections/paging_3.xml.res 2012-09-12 11:09:20 +0000
@@ -1,1 +1,1 @@
1<d/><e/><a/><b/><c/><d/><e/>1<d/><e/><delim/><a/><b/><c/><d/><e/><delim/><c/><d/><e/>
22
=== modified file 'test/rbkt/ExpQueryResults/zorba/collections/paging_4.xml.res'
--- test/rbkt/ExpQueryResults/zorba/collections/paging_4.xml.res 2012-06-28 18:19:34 +0000
+++ test/rbkt/ExpQueryResults/zorba/collections/paging_4.xml.res 2012-09-12 11:09:20 +0000
@@ -1,1 +1,1 @@
12 5 012 5 0 3
22
=== modified file 'test/rbkt/Queries/zorba/collections/paging_1.xq'
--- test/rbkt/Queries/zorba/collections/paging_1.xq 2012-06-28 18:19:34 +0000
+++ test/rbkt/Queries/zorba/collections/paging_1.xq 2012-09-12 11:09:20 +0000
@@ -1,9 +1,17 @@
1import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";1import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";
2import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";2import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
3import module namespace ns = "http://example.org/datamodule/" at "collections.xqdata";3import module namespace ns = "http://example.org/datamodule/" at "collections.xqdata";
4import module namespace ref = "http://www.zorba-xquery.com/modules/node-reference";
45
5declare namespace ann = "http://www.zorba-xquery.com/annotations";6declare namespace ann = "http://www.zorba-xquery.com/annotations";
67
8declare function local:order($items)
9{
10 for $item in $items
11 order by fn:local-name($item)
12 return $item
13};
14
7declare %ann:sequential function local:test()15declare %ann:sequential function local:test()
8{16{
9 ddl:create(xs:QName("ns:test2"));17 ddl:create(xs:QName("ns:test2"));
@@ -11,10 +19,11 @@
11 dml:insert-nodes(xs:QName("ns:test2"), <b/>);19 dml:insert-nodes(xs:QName("ns:test2"), <b/>);
12 dml:insert-nodes(xs:QName("ns:test2"), (<c/>, <d/>, <e/>));20 dml:insert-nodes(xs:QName("ns:test2"), (<c/>, <d/>, <e/>));
13 (21 (
14 dml:collection(xs:QName("ns:test2"), 3),22 local:order(dml:collection(xs:QName("ns:test2"), 3)), <delim/>,
15 dml:collection(xs:QName("ns:test2"), -1)23 local:order(dml:collection(xs:QName("ns:test2"), -1)), <delim/>,
24 let $ref := ref:node-reference(dml:collection(xs:QName("ns:test2"))[3])
25 return local:order(dml:collection(xs:QName("ns:test2"), $ref, 0))
16 )26 )
17};27};
1828
19local:test()29local:test()
20
2130
=== modified file 'test/rbkt/Queries/zorba/collections/paging_2.xq'
--- test/rbkt/Queries/zorba/collections/paging_2.xq 2012-06-28 18:19:34 +0000
+++ test/rbkt/Queries/zorba/collections/paging_2.xq 2012-09-12 11:09:20 +0000
@@ -1,6 +1,7 @@
1import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";1import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";
2import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";2import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
3import module namespace ns = "http://example.org/datamodule/" at "collections.xqdata";3import module namespace ns = "http://example.org/datamodule/" at "collections.xqdata";
4import module namespace ref = "http://www.zorba-xquery.com/modules/node-reference";
45
5declare namespace ann = "http://www.zorba-xquery.com/annotations";6declare namespace ann = "http://www.zorba-xquery.com/annotations";
67
@@ -13,9 +14,10 @@
13 (14 (
14 fn:count(dml:collection(xs:QName("ns:test2"), 3)),15 fn:count(dml:collection(xs:QName("ns:test2"), 3)),
15 fn:count(dml:collection(xs:QName("ns:test2"), -1)),16 fn:count(dml:collection(xs:QName("ns:test2"), -1)),
16 fn:count(dml:collection(xs:QName("ns:test2"), 100))17 fn:count(dml:collection(xs:QName("ns:test2"), 100)),
18 let $ref := ref:node-reference(dml:collection(xs:QName("ns:test2"))[3])
19 return fn:count(dml:collection(xs:QName("ns:test2"), $ref, 0))
17 )20 )
18};21};
1922
20local:test()23local:test()
21
2224
=== modified file 'test/rbkt/Queries/zorba/collections/paging_3.xq'
--- test/rbkt/Queries/zorba/collections/paging_3.xq 2012-06-28 18:19:34 +0000
+++ test/rbkt/Queries/zorba/collections/paging_3.xq 2012-09-12 11:09:20 +0000
@@ -1,5 +1,6 @@
1import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";1import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";
2import module namespace dml = "http://www.zorba-xquery.com/modules/store/dynamic/collections/dml";2import module namespace dml = "http://www.zorba-xquery.com/modules/store/dynamic/collections/dml";
3import module namespace ref = "http://www.zorba-xquery.com/modules/node-reference";
34
4declare namespace ann = "http://www.zorba-xquery.com/annotations";5declare namespace ann = "http://www.zorba-xquery.com/annotations";
5declare namespace ns = "http://www.zorba-xquery.com/test";6declare namespace ns = "http://www.zorba-xquery.com/test";
@@ -11,10 +12,11 @@
11 dml:insert-nodes-last(xs:QName("ns:test2"), <b/>);12 dml:insert-nodes-last(xs:QName("ns:test2"), <b/>);
12 dml:insert-nodes-last(xs:QName("ns:test2"), (<c/>, <d/>, <e/>));13 dml:insert-nodes-last(xs:QName("ns:test2"), (<c/>, <d/>, <e/>));
13 (14 (
14 dml:collection(xs:QName("ns:test2"), 3),15 dml:collection(xs:QName("ns:test2"), 3), <delim/>,
15 dml:collection(xs:QName("ns:test2"), -1)16 dml:collection(xs:QName("ns:test2"), -1), <delim/>,
17 let $ref := ref:node-reference(dml:collection(xs:QName("ns:test2"))[3])
18 return dml:collection(xs:QName("ns:test2"), $ref, 0)
16 )19 )
17};20};
1821
19local:test()22local:test()
20
2123
=== modified file 'test/rbkt/Queries/zorba/collections/paging_4.xq'
--- test/rbkt/Queries/zorba/collections/paging_4.xq 2012-06-28 18:19:34 +0000
+++ test/rbkt/Queries/zorba/collections/paging_4.xq 2012-09-12 11:09:20 +0000
@@ -1,5 +1,6 @@
1import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";1import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";
2import module namespace dml = "http://www.zorba-xquery.com/modules/store/dynamic/collections/dml";2import module namespace dml = "http://www.zorba-xquery.com/modules/store/dynamic/collections/dml";
3import module namespace ref = "http://www.zorba-xquery.com/modules/node-reference";
34
4declare namespace ann = "http://www.zorba-xquery.com/annotations";5declare namespace ann = "http://www.zorba-xquery.com/annotations";
5declare namespace ns = "http://www.zorba-xquery.com/test";6declare namespace ns = "http://www.zorba-xquery.com/test";
@@ -13,9 +14,10 @@
13 (14 (
14 fn:count(dml:collection(xs:QName("ns:test2"), 3)),15 fn:count(dml:collection(xs:QName("ns:test2"), 3)),
15 fn:count(dml:collection(xs:QName("ns:test2"), -1)),16 fn:count(dml:collection(xs:QName("ns:test2"), -1)),
16 fn:count(dml:collection(xs:QName("ns:test2"), 100))17 fn:count(dml:collection(xs:QName("ns:test2"), 100)),
18 let $ref := ref:node-reference(dml:collection(xs:QName("ns:test2"))[3])
19 return fn:count(dml:collection(xs:QName("ns:test2"), $ref, 0))
17 )20 )
18};21};
1922
20local:test()23local:test()
21
2224
=== added file 'test/rbkt/Queries/zorba/collections/paging_5.spec'
--- test/rbkt/Queries/zorba/collections/paging_5.spec 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/collections/paging_5.spec 2012-09-12 11:09:20 +0000
@@ -0,0 +1,1 @@
1Error: http://www.zorba-xquery.com/errors:ZSTR0066
02
=== added file 'test/rbkt/Queries/zorba/collections/paging_5.xq'
--- test/rbkt/Queries/zorba/collections/paging_5.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/collections/paging_5.xq 2012-09-12 11:09:20 +0000
@@ -0,0 +1,20 @@
1import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";
2import module namespace dml = "http://www.zorba-xquery.com/modules/store/dynamic/collections/dml";
3import module namespace ref = "http://www.zorba-xquery.com/modules/node-reference";
4
5declare namespace ann = "http://www.zorba-xquery.com/annotations";
6declare namespace ns = "http://www.zorba-xquery.com/test";
7
8declare %ann:sequential function local:test()
9{
10 ddl:create(xs:QName("ns:test2"));
11 dml:insert-nodes-last(xs:QName("ns:test2"), <a/>);
12 dml:insert-nodes-last(xs:QName("ns:test2"), <b/>);
13 dml:insert-nodes-last(xs:QName("ns:test2"), (<c/>, <d/>, <e/>));
14
15 dml:collection(
16 xs:QName("ns:test2"),
17 xs:anyURI("urn:uuid:aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"), 0)
18};
19
20local:test()

Subscribers

People subscribed via source and target branches