Matthias Brantner has proposed merging lp:~zorba-coders/zorba/bug-945241 into 
lp:zorba.

Requested reviews:
  Matthias Brantner (matthias-brantner)
  Till Westmann (tillw)
Related bugs:
  Bug #945241 in Zorba: "StaticCollectionManager::declaredIndexes() and 
temporary indexes"
  https://bugs.launchpad.net/zorba/+bug/945241

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-945241/+merge/95704

StaticCollectionManager::declaredIndexes() doesn't return temporary indexes 
anymore. Also isDeclaredIndex also doesn't return true if asked whether a 
temporary index is declared.
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug-945241/+merge/95704
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2012-03-01 21:22:16 +0000
+++ ChangeLog	2012-03-02 23:58:19 +0000
@@ -24,6 +24,7 @@
     case of early-out)
   * More efficient implementation for base64Binary items
   * Added index management function to the C++ api's StaticCollectionManager.
+  * Fixed bug #945241 (StaticCollectionManager::declaredIndexes() and temporary indexes)
   * Fixed bug #872288 (reset recursive flag during node rename)
   * Fixed bug #905041 (allow for the default element and function namespaces to be
     set multiple times via the c++ api).

=== modified file 'src/runtime/collections/collections_impl.cpp'
--- src/runtime/collections/collections_impl.cpp	2012-02-16 12:48:17 +0000
+++ src/runtime/collections/collections_impl.cpp	2012-03-02 23:58:19 +0000
@@ -30,6 +30,7 @@
 #include "context/uri_resolver.h"
 #include "context/static_context_consts.h"
 
+#include "compiler/xqddf/value_index.h"
 #include "compiler/xqddf/value_ic.h"
 
 #include "runtime/collections/collections.h"
@@ -2331,20 +2332,21 @@
     PlanState& aPlanState) const
 {
   store::Item_t      lName;
+  zorba::IndexDecl*  lDecl;
 
   PlanIteratorState* lState;
   DEFAULT_STACK_INIT(PlanIteratorState, lState, aPlanState);
 
   consumeNext(lName, theChildren[0].getp(), aPlanState);
 
-  if (theSctx->lookup_index(lName.getp()) == 0)
+  if ((lDecl = theSctx->lookup_index(lName.getp())) && !lDecl->isTemp())
+  {
+    STACK_PUSH(GENV_ITEMFACTORY->createBoolean(aResult, true), lState);
+  }
+  else
   {
     STACK_PUSH(GENV_ITEMFACTORY->createBoolean(aResult, false), lState);
   }
-  else
-  {
-    STACK_PUSH(GENV_ITEMFACTORY->createBoolean(aResult, true), lState);
-  }
 
   STACK_END(lState);
 }
@@ -2386,6 +2388,10 @@
   for ((lState->nameItState = theSctx->index_names())->open();
        lState->nameItState->next(lName); )
   {
+    if (theSctx->lookup_index(lName.getp())->isTemp()) 
+    {
+      continue;
+    }
     aResult = lName;
     STACK_PUSH(true, lState);
   }

=== modified file 'test/unit/module1.xq'
--- test/unit/module1.xq	2011-08-05 02:21:55 +0000
+++ test/unit/module1.xq	2012-03-02 23:58:19 +0000
@@ -18,4 +18,4 @@
 
 import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";;
 
-1+1
+mod2:foo()

=== modified file 'test/unit/module2.xq'
--- test/unit/module2.xq	2011-12-21 14:40:33 +0000
+++ test/unit/module2.xq	2012-03-02 23:58:19 +0000
@@ -27,3 +27,14 @@
 declare index mod2:index
   on nodes ddl:collection(xs:QName("mod2:coll"))
   by data(@id) as xs:string;
+
+
+(: test that a temp index doesn't have impact on the indexes 
+   returned by the static collection mgr :)
+declare function mod2:foo()
+{
+  for $i in 1 to 10
+  for $j in 1 to 10
+  where $i eq $j
+  return $i
+};

=== modified file 'test/unit/staticcollectionmanager.cpp'
--- test/unit/staticcollectionmanager.cpp	2012-01-11 17:30:25 +0000
+++ test/unit/staticcollectionmanager.cpp	2012-03-02 23:58:19 +0000
@@ -206,23 +206,26 @@
   Item lCollName2 = lFac->createQName("http://www.mod2.com/";, "coll");
   
   lColMgr->createCollection(lCollName2);
-  Collection_t lColl = lColMgr->getCollection(lCollName2);
-
-  std::vector<Annotation_t> lAnnotations;
-  lColl->getAnnotations(lAnnotations);
-  size_t num_annotations = 0;
-  for (std::vector<Annotation_t>::const_iterator lIter = lAnnotations.begin();
-       lIter != lAnnotations.end(); ++lIter)
-  {
-    std::cout << "Annotation QName " << (*lIter)->getQName().getStringValue() << std::endl;
-    ++num_annotations;
-  }
-
-  if (num_annotations != 3)
-  {
-    return false;
-  }
-
+
+  {
+    Collection_t lColl = lColMgr->getCollection(lCollName2);
+    std::vector<Annotation_t> lAnnotations;
+    lColl->getAnnotations(lAnnotations);
+    size_t num_annotations = 0;
+    for (std::vector<Annotation_t>::const_iterator lIter = lAnnotations.begin();
+         lIter != lAnnotations.end(); ++lIter)
+    {
+      std::cout << "Annotation QName " << (*lIter)->getQName().getStringValue() << std::endl;
+      ++num_annotations;
+    }
+
+    if (num_annotations != 3)
+    {
+      return false;
+    }
+  }
+
+  lColMgr->deleteCollection(lCollName2);
 
   return true;
 }
@@ -259,6 +262,44 @@
   return i == 1;
 }
 
+(: test that declaredIndexes doesn't return temporary indexes and crashes
+ : if one tries to create one :)
+bool
+staticcollectionamanger5(zorba::Zorba* z)
+{
+  std::ifstream lIn("module1.xq");
+
+  zorba::XQuery_t lQuery = z->createQuery();
+  Zorba_CompilerHints lHints;
+  lQuery->compile(lIn, lHints);
+
+  StaticCollectionManager* lColMgr = lQuery->getStaticCollectionManager();
+
+  ItemFactory* lFac = z->getItemFactory();
+  Item lCollName2 = lFac->createQName("http://www.mod2.com/";, "coll");
+  Item lIdxName   = lFac->createQName("http://www.mod2.com/";, "index");
+  Item lCollName3 = lFac->createQName("http://www.mod3.com/";, "coll");
+
+  ItemSequence_t lSeq = lColMgr->declaredCollections();
+  Iterator_t lIter = lSeq->getIterator();
+  lIter->open();
+  Item lTmp;
+  while (lIter->next(lTmp)) {
+    std::cout << "name " << lTmp.getStringValue() << std::endl;
+    lColMgr->createCollection(lTmp);
+  }
+  
+  lSeq = lColMgr->declaredIndexes();
+  lIter = lSeq->getIterator();
+  lIter->open();
+  while (lIter->next(lTmp)) {
+    std::cout << "name " << lTmp.getStringValue() << std::endl;
+    lColMgr->createIndex(lTmp);
+  }
+
+  return true;
+}
+
 int
 staticcollectionmanager(int argc, char* argv[])
 {
@@ -287,6 +328,11 @@
     return 4;
   std::cout << std::endl;
 
+  std::cout << "executing example 5" << std::endl;
+  if (!staticcollectionamanger5(z))
+    return 5;
+  std::cout << std::endl;
+
   return 0;
 }
 

-- 
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