Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/bug-960083 
into lp:zorba.

Requested reviews:
  Markos Zaharioudakis (markos-za)

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

fixed bug 960083$ (improper error handling of NaN comparisons) + small 
optimization of comparison operations
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug-960083/+merge/108326
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/runtime/booleans/BooleanImpl.cpp'
--- src/runtime/booleans/BooleanImpl.cpp	2012-05-03 12:31:51 +0000
+++ src/runtime/booleans/BooleanImpl.cpp	2012-06-01 12:05:28 +0000
@@ -443,11 +443,8 @@
                                                                 theCollation)),
                  state);
 
-      if (consumeNext(item0, theChild0.getp(), planState) ||
-          consumeNext(item1, theChild1.getp(), planState))
-      {
-        RAISE_ERROR(err::XPTY0004, loc, ERROR_PARAMS(ZED(NoSeqInValueComp)));
-      }
+      assert(!consumeNext(item0, theChild0.getp(), planState) &&
+             !consumeNext(item1, theChild1.getp(), planState));
     }
   }
 
@@ -501,10 +498,11 @@
     }
     }
   }
-  catch (ZorbaException const& e)
+  catch (const ZorbaException& e)
   {
     if (e.diagnostic() == zerr::ZSTR0041_NAN_COMPARISON)
       return false;
+
     throw;
   }
 }
@@ -665,7 +663,7 @@
     }
     }
   }
-  catch (ZorbaException const& e)
+  catch (const ZorbaException& e)
   {
     if (e.diagnostic() == zerr::ZSTR0041_NAN_COMPARISON)
       return false;
@@ -943,7 +941,7 @@
       }
     }
   }
-  catch(ZorbaException const& e)
+  catch(const ZorbaException& e)
   {
     // For example, two QName items do not have an order relationship.
     if (e.diagnostic() == zerr::ZSTR0040_TYPE_ERROR)
@@ -954,6 +952,7 @@
       RAISE_ERROR(err::XPTY0004, loc,
       ERROR_PARAMS(ZED(BadType_23o), *type0, ZED(NoCompareWithType_4), *type1));
     }
+
     throw;
   }
 }
@@ -1001,7 +1000,6 @@
   store::Item_t lItem0, lItem1;
   bool bRes;
   bool neq = false;
-  bool nonempty = false;
   long cmp;
 
   PlanIteratorState* state;
@@ -1009,8 +1007,6 @@
 
   if (CONSUME(lItem0, 0) && CONSUME(lItem1, 1))
   {
-    nonempty = true;
-
     switch (theCompType)
     {
     case CompareConsts::VALUE_NOT_EQUAL:
@@ -1027,39 +1023,41 @@
 
     default:
     {
-      cmp = lItem0->compare(lItem1, theTimezone, theCollation);
+      try
+      {
+        cmp = lItem0->compare(lItem1, theTimezone, theCollation);
 
-      switch (theCompType)
+        switch (theCompType)
+        {
+        case CompareConsts::VALUE_LESS:
+          bRes = (cmp < 0);
+          break;
+        case CompareConsts::VALUE_GREATER:
+          bRes = (cmp > 0);
+          break;
+        case CompareConsts::VALUE_LESS_EQUAL:
+          bRes = (cmp <= 0);
+          break;
+        case CompareConsts::VALUE_GREATER_EQUAL:
+          bRes = (cmp >= 0);
+          break;
+        default:
+          ZORBA_ASSERT(false);
+        } // switch (theCompType)
+      }
+      catch (const ZorbaException& e)
       {
-      case CompareConsts::VALUE_LESS:
-        bRes = (cmp < 0);
-        break;
-      case CompareConsts::VALUE_GREATER:
-        bRes = (cmp > 0);
-        break;
-      case CompareConsts::VALUE_LESS_EQUAL:
-        bRes = (cmp <= 0);
-        break;
-      case CompareConsts::VALUE_GREATER_EQUAL:
-        bRes = (cmp >= 0);
-        break;
-      default:
-        ZORBA_ASSERT(false);
-      } // switch (theCompType)
+        if (e.diagnostic() == zerr::ZSTR0041_NAN_COMPARISON)
+          bRes = false;
+        else
+          throw;
+      }
     } // default
     } // switch (theCompType)
 
-    if (nonempty)
-      STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, bRes), state);
+    STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, bRes), state);
 
-    if (CONSUME(lItem0, 0) || CONSUME(lItem1, 1))
-    {
-      throw XQUERY_EXCEPTION(
-        err::XPTY0004,
-        ERROR_PARAMS( ZED( NoSeqInValueComp ) ),
-        ERROR_LOC( this->loc )
-      );
-    }
+    assert(!CONSUME(lItem0, 0) && !CONSUME(lItem1, 1));
   }
 
   STACK_END(state);

=== modified file 'src/runtime/indexing/index_ddl.cpp'
--- src/runtime/indexing/index_ddl.cpp	2012-05-11 22:49:47 +0000
+++ src/runtime/indexing/index_ddl.cpp	2012-06-01 12:05:28 +0000
@@ -713,9 +713,9 @@
     
     STACK_END(state);
   }
-  catch (XQueryException& e)
+  catch (ZorbaException& e)
   {
-    set_source( e,  loc, false );
+    set_source(e,  loc, false);
     throw;
   }
 }
@@ -822,12 +822,10 @@
           numChildren != 2)
       {
         RAISE_ERROR(zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS, loc,
-        ERROR_PARAMS(
-          qnameItem->getStringValue(),
-          "index",
-          numChildren-1,
-          state->theIndexDecl->getKeyExpressions().size())
-        );
+        ERROR_PARAMS(qnameItem->getStringValue(),
+                     "index",
+                     numChildren-1,
+                     state->theIndexDecl->getKeyExpressions().size()));
       }
 
       state->theIndex = (state->theIndexDecl->isTemp() ?
@@ -877,9 +875,9 @@
 
     STACK_END(state);
   }
-  catch (XQueryException& e)
+  catch (ZorbaException& e)
   {
-    set_source( e, loc, false );
+    set_source(e, loc, false);
     throw;
   }
 }
@@ -995,168 +993,176 @@
   bool status;
   TypeManager* tm = theSctx->get_typemanager();
   RootTypeManager& rtm = GENV_TYPESYSTEM;
- 
-  ProbeIndexRangeValueIteratorState* state;
-  DEFAULT_STACK_INIT(ProbeIndexRangeValueIteratorState, state, planState);
-
-  status = consumeNext(qname, theChildren[0], planState);
-  ZORBA_ASSERT(status);
-
-  if (state->theQname == NULL || !state->theQname->equals(qname)) 
-  {
-    state->theQname = qname;
-
-    if ((indexDecl = theSctx->lookup_index(qname)) == NULL)
-    {
-      RAISE_ERROR(zerr::ZDDY0021_INDEX_NOT_DECLARED, loc,
-      ERROR_PARAMS(qname->getStringValue()));
-    }
-
-    if (indexDecl->getMethod() != IndexDecl::TREE)
-    {
-      RAISE_ERROR(zerr::ZDDY0026_INDEX_RANGE_PROBE_NOT_ALLOWED, loc,
-      ERROR_PARAMS(qname->getStringValue()));
-    }
-
-    if (numChildren < 7 || (numChildren-1) % 6 != 0)
-    {
-      RAISE_ERROR(zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS, loc,
-      ERROR_PARAMS(qname->getStringValue(),
-                   "index",
-                   numChildren-1,
-                   "multiple of 6"));
-    }
-
-    if (indexDecl->getKeyExpressions().size() * 6 < numChildren-1)
-    {
-      RAISE_ERROR(zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS, loc,
-      ERROR_PARAMS(qname->getStringValue(),
-                   "index",
-                   numChildren-1,
-                   indexDecl->getKeyExpressions().size() * 6));
-    }
-
-    state->theIndex = (indexDecl->isTemp() ?
-                       planState.theLocalDynCtx->getIndex(qname) :
-                       GENV_STORE.getIndex(state->theQname));
-
-    if (state->theIndex == NULL)
-    {
-      RAISE_ERROR(zerr::ZDDY0023_INDEX_DOES_NOT_EXIST, loc,
-      ERROR_PARAMS(qname->getStringValue()));
-    }
-
-    state->theIterator = GENV_STORE.getIteratorFactory()->
-                         createIndexProbeIterator(state->theIndex);
-  }
-
-  cond = state->theIndex->createCondition(store::IndexCondition::BOX_VALUE);
-
-  ulong keyNo;
-  ulong i;
-  for (i = 1, keyNo = 0; i < numChildren; i += 6, ++keyNo) 
-  {
-    store::Item_t tempLeft;
-    store::Item_t tempRight;
-    store::Item_t tempHaveLeft;
-    store::Item_t tempHaveRight;
-    store::Item_t tempInclLeft;
-    store::Item_t tempInclRight;
-
-    if (!consumeNext(tempLeft, theChildren[i], planState))
-      tempLeft = NULL;
- 
-    if (!consumeNext(tempRight, theChildren[i + 1], planState))
-      tempRight = NULL;
-
-    if (!consumeNext(tempHaveLeft, theChildren[i + 2], planState))
-      ZORBA_ASSERT(false);
-
-    if (!consumeNext(tempHaveRight, theChildren[i + 3], planState))
-     ZORBA_ASSERT(false);
-
-    if (!consumeNext(tempInclLeft, theChildren[i + 4], planState))
-     ZORBA_ASSERT(false);
- 
-    if (!consumeNext(tempInclRight, theChildren[i + 5], planState))
-     ZORBA_ASSERT(false);
-
-    bool haveLeft = tempHaveLeft->getBooleanValue();
-    bool haveRight = tempHaveRight->getBooleanValue();
-    bool inclLeft = tempInclLeft->getBooleanValue();
-    bool inclRight = tempInclRight->getBooleanValue();
-
-    if (tempLeft != NULL && theCheckKeyType)
-    {
-      checkKeyType(loc, theSctx->get_typemanager(), indexDecl, keyNo, tempLeft);
-    }
-
-    if (tempRight != NULL && theCheckKeyType)
-    {
-      checkKeyType(loc, theSctx->get_typemanager(), indexDecl, keyNo, tempRight);
-    }
-
-    if (indexDecl->isGeneral() &&
-        (indexDecl->getKeyTypes())[keyNo] == NULL)
-    {
-      xqtref_t leftType;
-      xqtref_t rightType;
-
-      if (tempLeft != NULL)
-      {
-        leftType = tm->create_value_type(tempLeft);
-        
-        if (TypeOps::is_equal(tm, *leftType, *rtm.UNTYPED_ATOMIC_TYPE_ONE))
-        {
-          zstring str = tempLeft->getStringValue();
-          GENV_ITEMFACTORY->createString(tempLeft, str);
-          leftType = rtm.STRING_TYPE_ONE;
-        }
-      }
-
-      if (tempRight != NULL)
-      {
-        rightType = tm->create_value_type(tempRight);
-        
-        if (TypeOps::is_equal(tm, *rightType, *rtm.UNTYPED_ATOMIC_TYPE_ONE))
-        {
-          zstring str = tempRight->getStringValue();
-          GENV_ITEMFACTORY->createString(tempRight, str);
-          rightType = rtm.STRING_TYPE_ONE;
-        }
-      }
-
-      if (leftType != NULL && rightType != NULL)
-      {
-        if (!TypeOps::is_subtype(tm, *leftType, *rightType) &&
-            !TypeOps::is_subtype(tm, *rightType, *leftType))
-        {
-          RAISE_ERROR(zerr::ZDDY0034_INDEX_RANGE_VALUE_PROBE_BAD_KEY_TYPES, loc,
-          ERROR_PARAMS(qname->getStringValue()));
-        }
-      }
-    }
-
-    cond->pushRange(tempLeft, tempRight, haveLeft, haveRight, inclLeft, inclRight);
-  }
-
-  state->theIterator->init(cond);
-  if (!theCountOnly)
-  {
-    state->theIterator->open();
-
-    while(state->theIterator->next(result)) 
-    {
+
+  try
+  {
+    ProbeIndexRangeValueIteratorState* state;
+    DEFAULT_STACK_INIT(ProbeIndexRangeValueIteratorState, state, planState);
+
+    status = consumeNext(qname, theChildren[0], planState);
+    ZORBA_ASSERT(status);
+
+    if (state->theQname == NULL || !state->theQname->equals(qname)) 
+    {
+      state->theQname = qname;
+
+      if ((indexDecl = theSctx->lookup_index(qname)) == NULL)
+      {
+        RAISE_ERROR(zerr::ZDDY0021_INDEX_NOT_DECLARED, loc,
+        ERROR_PARAMS(qname->getStringValue()));
+      }
+
+      if (indexDecl->getMethod() != IndexDecl::TREE)
+      {
+        RAISE_ERROR(zerr::ZDDY0026_INDEX_RANGE_PROBE_NOT_ALLOWED, loc,
+        ERROR_PARAMS(qname->getStringValue()));
+      }
+
+      if (numChildren < 7 || (numChildren-1) % 6 != 0)
+      {
+        RAISE_ERROR(zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS, loc,
+        ERROR_PARAMS(qname->getStringValue(),
+                     "index",
+                     numChildren-1,
+                     "multiple of 6"));
+      }
+
+      if (indexDecl->getKeyExpressions().size() * 6 < numChildren-1)
+      {
+        RAISE_ERROR(zerr::ZDDY0025_INDEX_WRONG_NUMBER_OF_PROBE_ARGS, loc,
+        ERROR_PARAMS(qname->getStringValue(),
+                     "index",
+                     numChildren-1,
+                     indexDecl->getKeyExpressions().size() * 6));
+      }
+
+      state->theIndex = (indexDecl->isTemp() ?
+                         planState.theLocalDynCtx->getIndex(qname) :
+                         GENV_STORE.getIndex(state->theQname));
+      
+      if (state->theIndex == NULL)
+      {
+        RAISE_ERROR(zerr::ZDDY0023_INDEX_DOES_NOT_EXIST, loc,
+        ERROR_PARAMS(qname->getStringValue()));
+      }
+
+      state->theIterator = GENV_STORE.getIteratorFactory()->
+                           createIndexProbeIterator(state->theIndex);
+    }
+
+    cond = state->theIndex->createCondition(store::IndexCondition::BOX_VALUE);
+
+    ulong keyNo;
+    ulong i;
+    for (i = 1, keyNo = 0; i < numChildren; i += 6, ++keyNo) 
+    {
+      store::Item_t tempLeft;
+      store::Item_t tempRight;
+      store::Item_t tempHaveLeft;
+      store::Item_t tempHaveRight;
+      store::Item_t tempInclLeft;
+      store::Item_t tempInclRight;
+
+      if (!consumeNext(tempLeft, theChildren[i], planState))
+        tempLeft = NULL;
+ 
+      if (!consumeNext(tempRight, theChildren[i + 1], planState))
+        tempRight = NULL;
+
+      if (!consumeNext(tempHaveLeft, theChildren[i + 2], planState))
+        ZORBA_ASSERT(false);
+
+      if (!consumeNext(tempHaveRight, theChildren[i + 3], planState))
+        ZORBA_ASSERT(false);
+
+      if (!consumeNext(tempInclLeft, theChildren[i + 4], planState))
+        ZORBA_ASSERT(false);
+ 
+      if (!consumeNext(tempInclRight, theChildren[i + 5], planState))
+        ZORBA_ASSERT(false);
+
+      bool haveLeft = tempHaveLeft->getBooleanValue();
+      bool haveRight = tempHaveRight->getBooleanValue();
+      bool inclLeft = tempInclLeft->getBooleanValue();
+      bool inclRight = tempInclRight->getBooleanValue();
+      
+      if (tempLeft != NULL && theCheckKeyType)
+      {
+        checkKeyType(loc, theSctx->get_typemanager(), indexDecl, keyNo, tempLeft);
+      }
+
+      if (tempRight != NULL && theCheckKeyType)
+      {
+        checkKeyType(loc, theSctx->get_typemanager(), indexDecl, keyNo, tempRight);
+      }
+
+      if (indexDecl->isGeneral() &&
+          (indexDecl->getKeyTypes())[keyNo] == NULL)
+      {
+        xqtref_t leftType;
+        xqtref_t rightType;
+
+        if (tempLeft != NULL)
+        {
+          leftType = tm->create_value_type(tempLeft);
+          
+          if (TypeOps::is_equal(tm, *leftType, *rtm.UNTYPED_ATOMIC_TYPE_ONE))
+          {
+            zstring str = tempLeft->getStringValue();
+            GENV_ITEMFACTORY->createString(tempLeft, str);
+            leftType = rtm.STRING_TYPE_ONE;
+          }
+        }
+        
+        if (tempRight != NULL)
+        {
+          rightType = tm->create_value_type(tempRight);
+          
+          if (TypeOps::is_equal(tm, *rightType, *rtm.UNTYPED_ATOMIC_TYPE_ONE))
+          {
+            zstring str = tempRight->getStringValue();
+            GENV_ITEMFACTORY->createString(tempRight, str);
+            rightType = rtm.STRING_TYPE_ONE;
+          }
+        }
+        
+        if (leftType != NULL && rightType != NULL)
+        {
+          if (!TypeOps::is_subtype(tm, *leftType, *rightType) &&
+              !TypeOps::is_subtype(tm, *rightType, *leftType))
+          {
+            RAISE_ERROR(zerr::ZDDY0034_INDEX_RANGE_VALUE_PROBE_BAD_KEY_TYPES, loc,
+            ERROR_PARAMS(qname->getStringValue()));
+          }
+        }
+      }
+      
+      cond->pushRange(tempLeft, tempRight, haveLeft, haveRight, inclLeft, inclRight);
+    }
+
+    state->theIterator->init(cond);
+    if (!theCountOnly)
+    {
+      state->theIterator->open();
+      
+      while(state->theIterator->next(result)) 
+      {
+        STACK_PUSH(true, state);
+      }
+    }
+    else
+    {
+      state->theIterator->count(result);
       STACK_PUSH(true, state);
     }
+    
+    STACK_END(state);
   }
-  else
+  catch (ZorbaException& e)
   {
-    state->theIterator->count(result);
-    STACK_PUSH(true, state);
+    set_source(e, loc, false);
+    throw;
   }
-
-  STACK_END(state);
 }
 
 
@@ -1267,202 +1273,228 @@
 
   TypeManager* tm = theSctx->get_typemanager();
 
-  ProbeIndexRangeGeneralIteratorState* state;
-  DEFAULT_STACK_INIT(ProbeIndexRangeGeneralIteratorState, state, planState);
-
-  status = consumeNext(qname, theChildren[0], planState);
-  ZORBA_ASSERT(status);
-
-  if (state->theQname == NULL || !state->theQname->equals(qname)) 
-  {
-    state->theQname = qname;
-
-    if ((indexDecl = theSctx->lookup_index(qname)) == NULL)
-    {
-      RAISE_ERROR(zerr::ZDDY0021_INDEX_NOT_DECLARED, loc,
-      ERROR_PARAMS(qname->getStringValue()));
-    }
-
-    if (indexDecl->getMethod() != IndexDecl::TREE)
-    {
-      RAISE_ERROR(zerr::ZDDY0030_INDEX_RANGE_GENERAL_PROBE_NOT_ALLOWED, loc,
-      ERROR_PARAMS(qname->getStringValue()));
-    }
-
-    if (!indexDecl->isGeneral())
-    {
-      RAISE_ERROR(zerr::ZDDY0030_INDEX_RANGE_GENERAL_PROBE_NOT_ALLOWED, loc,
-      ERROR_PARAMS(qname->getStringValue()));
-    }
-
-    state->theIndex = (indexDecl->isTemp() ?
-                       planState.theLocalDynCtx->getIndex(qname) :
-                       GENV_STORE.getIndex(state->theQname));
-
-    if (state->theIndex == NULL)
-    {
-      RAISE_ERROR(zerr::ZDDY0023_INDEX_DOES_NOT_EXIST, loc,
-      ERROR_PARAMS(qname->getStringValue()));
-    }
-
-    state->theIterator = GENV_STORE.getIteratorFactory()->
-                         createIndexProbeIterator(state->theIndex);
-
-    state->theTimezone = state->theIndex->getSpecification().getTimezone();
-    state->theCollator = state->theIndex->getCollator(0);
-
-    xqtref_t keyType = indexDecl->getKeyTypes()[0];
-
-    assert(keyType == NULL ||
-           keyType->get_quantifier() == TypeConstants::QUANT_ONE);
-
-    if (keyType != NULL && 
-        !TypeOps::is_subtype(tm, *keyType, *GENV_TYPESYSTEM.UNTYPED_ATOMIC_TYPE_ONE) &&
-        !TypeOps::is_equal(tm, *keyType, *GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_ONE))
-    {
-      state->theKeyType = keyType;
-    }
-  }
-
-  {
-    store::Item_t itemHaveLower;
-    store::Item_t itemHaveUpper;
-    store::Item_t itemInclLower;
-    store::Item_t itemInclUpper;
-
-    // Get the values of $haveLowerBound, $haveUpperBound, $lowerBoundIncluded,
-    // and $upperBoundIncluded params
-    if (!consumeNext(itemHaveLower, theChildren[3], planState))
-      ZORBA_ASSERT(false);
-
-    if (!consumeNext(itemHaveUpper, theChildren[4], planState))
-     ZORBA_ASSERT(false);
-
-    if (!consumeNext(itemInclLower, theChildren[5], planState))
-     ZORBA_ASSERT(false);
- 
-    if (!consumeNext(itemInclUpper, theChildren[6], planState))
-     ZORBA_ASSERT(false);
-
-    haveLower = itemHaveLower->getBooleanValue();
-    haveUpper = itemHaveUpper->getBooleanValue();
-    inclLower = itemInclLower->getBooleanValue();
-    inclUpper = itemInclUpper->getBooleanValue();
-  }
-
-  cond = state->theIndex->createCondition(store::IndexCondition::BOX_GENERAL);
-
-  if (haveLower && haveUpper)
-  {
-    //
-    // Build hashmap from the nodes satisfying the lower bound condition
-    //
-
-    if (!getSearchItems(planState, state, true, false, inclLower, false))
-      goto done;
-
-    assert(state->theSearchItems.size() >= 1);
-    assert(state->theKeyType == NULL || state->theSearchItems.size() == 1);
-
-    state->theNodeHashSet = new ItemHandleHashSet(1024, false);
-
-    state->theSearchItemsIte = state->theSearchItems.begin();
-    state->theSearchItemsEnd = state->theSearchItems.end();
-
-    for (;
-         state->theSearchItemsIte != state->theSearchItemsEnd;
-         ++state->theSearchItemsIte)
-    {
-      cond->clear();
-      cond->pushBound(*state->theSearchItemsIte, true, inclLower);
-      
-      state->theIterator->init(cond);
-      state->theIterator->open();
-
-      while(state->theIterator->next(result)) 
-      {
-        state->theNodeHashSet->insert(result.getp());
-      }
-      
-      state->theIterator->close();
-    }
-
-    state->theSearchItems.clear();
-    cond->clear();
-
-    //
-    // Compute the nodes satisfying the upper bound condition and probe the
-    // node hashmap.
-    //
-
-    if (!getSearchItems(planState, state, false, true, false, inclUpper))
-      goto done;
-
-    assert(state->theSearchItems.size() >= 1);
-    assert(state->theKeyType == NULL || state->theSearchItems.size() == 1);
-
-    state->theSearchItemsIte = state->theSearchItems.begin();
-    state->theSearchItemsEnd = state->theSearchItems.end();
-
-    for (;
-         state->theSearchItemsIte != state->theSearchItemsEnd;
-         ++state->theSearchItemsIte)
-    {
-      cond->clear();
-      cond->pushBound(*state->theSearchItemsIte, false, inclUpper);
-
-      state->theIterator->init(cond);
-
-      if (!theCountOnly)
-      {
+  try
+  {
+    ProbeIndexRangeGeneralIteratorState* state;
+    DEFAULT_STACK_INIT(ProbeIndexRangeGeneralIteratorState, state, planState);
+
+    status = consumeNext(qname, theChildren[0], planState);
+    ZORBA_ASSERT(status);
+
+    if (state->theQname == NULL || !state->theQname->equals(qname)) 
+    {
+      state->theQname = qname;
+
+      if ((indexDecl = theSctx->lookup_index(qname)) == NULL)
+      {
+        RAISE_ERROR(zerr::ZDDY0021_INDEX_NOT_DECLARED, loc,
+        ERROR_PARAMS(qname->getStringValue()));
+      }
+
+      if (indexDecl->getMethod() != IndexDecl::TREE)
+      {
+        RAISE_ERROR(zerr::ZDDY0030_INDEX_RANGE_GENERAL_PROBE_NOT_ALLOWED, loc,
+        ERROR_PARAMS(qname->getStringValue()));
+      }
+
+      if (!indexDecl->isGeneral())
+      {
+        RAISE_ERROR(zerr::ZDDY0030_INDEX_RANGE_GENERAL_PROBE_NOT_ALLOWED, loc,
+        ERROR_PARAMS(qname->getStringValue()));
+      }
+
+      state->theIndex = (indexDecl->isTemp() ?
+                         planState.theLocalDynCtx->getIndex(qname) :
+                         GENV_STORE.getIndex(state->theQname));
+      
+      if (state->theIndex == NULL)
+      {
+        RAISE_ERROR(zerr::ZDDY0023_INDEX_DOES_NOT_EXIST, loc,
+        ERROR_PARAMS(qname->getStringValue()));
+      }
+
+      state->theIterator = GENV_STORE.getIteratorFactory()->
+                           createIndexProbeIterator(state->theIndex);
+
+      state->theTimezone = state->theIndex->getSpecification().getTimezone();
+      state->theCollator = state->theIndex->getCollator(0);
+
+      xqtref_t keyType = indexDecl->getKeyTypes()[0];
+
+      assert(keyType == NULL ||
+             keyType->get_quantifier() == TypeConstants::QUANT_ONE);
+
+      if (keyType != NULL && 
+          !TypeOps::is_subtype(tm, *keyType, *GENV_TYPESYSTEM.UNTYPED_ATOMIC_TYPE_ONE) &&
+          !TypeOps::is_equal(tm, *keyType, *GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_ONE))
+      {
+        state->theKeyType = keyType;
+      }
+    }
+    
+    {
+      store::Item_t itemHaveLower;
+      store::Item_t itemHaveUpper;
+      store::Item_t itemInclLower;
+      store::Item_t itemInclUpper;
+      
+      // Get the values of $haveLowerBound, $haveUpperBound, $lowerBoundIncluded,
+      // and $upperBoundIncluded params
+      if (!consumeNext(itemHaveLower, theChildren[3], planState))
+        ZORBA_ASSERT(false);
+      
+      if (!consumeNext(itemHaveUpper, theChildren[4], planState))
+        ZORBA_ASSERT(false);
+      
+      if (!consumeNext(itemInclLower, theChildren[5], planState))
+        ZORBA_ASSERT(false);
+      
+      if (!consumeNext(itemInclUpper, theChildren[6], planState))
+        ZORBA_ASSERT(false);
+      
+      haveLower = itemHaveLower->getBooleanValue();
+      haveUpper = itemHaveUpper->getBooleanValue();
+      inclLower = itemInclLower->getBooleanValue();
+      inclUpper = itemInclUpper->getBooleanValue();
+    }
+    
+    cond = state->theIndex->createCondition(store::IndexCondition::BOX_GENERAL);
+
+    if (haveLower && haveUpper)
+    {
+      //
+      // Build hashmap from the nodes satisfying the lower bound condition
+      //
+      
+      if (!getSearchItems(planState, state, true, false, inclLower, false))
+        goto done;
+      
+      assert(state->theSearchItems.size() >= 1);
+      assert(state->theKeyType == NULL || state->theSearchItems.size() == 1);
+      
+      state->theNodeHashSet = new ItemHandleHashSet(1024, false);
+      
+      state->theSearchItemsIte = state->theSearchItems.begin();
+      state->theSearchItemsEnd = state->theSearchItems.end();
+      
+      for (;
+           state->theSearchItemsIte != state->theSearchItemsEnd;
+           ++state->theSearchItemsIte)
+      {
+        cond->clear();
+        cond->pushBound(*state->theSearchItemsIte, true, inclLower);
+        
+        state->theIterator->init(cond);
         state->theIterator->open();
-
+        
         while(state->theIterator->next(result)) 
         {
-          if (state->theNodeHashSet->exists(result))
+          state->theNodeHashSet->insert(result.getp());
+        }
+        
+        state->theIterator->close();
+      }
+      
+      state->theSearchItems.clear();
+      cond->clear();
+
+      //
+      // Compute the nodes satisfying the upper bound condition and probe the
+      // node hashmap.
+      //
+      
+      if (!getSearchItems(planState, state, false, true, false, inclUpper))
+        goto done;
+
+      assert(state->theSearchItems.size() >= 1);
+      assert(state->theKeyType == NULL || state->theSearchItems.size() == 1);
+
+      state->theSearchItemsIte = state->theSearchItems.begin();
+      state->theSearchItemsEnd = state->theSearchItems.end();
+
+      for (;
+           state->theSearchItemsIte != state->theSearchItemsEnd;
+           ++state->theSearchItemsIte)
+      {
+        cond->clear();
+        cond->pushBound(*state->theSearchItemsIte, false, inclUpper);
+
+        state->theIterator->init(cond);
+
+        if (!theCountOnly)
+        {
+          state->theIterator->open();
+
+          while(state->theIterator->next(result)) 
+          {
+            if (state->theNodeHashSet->exists(result))
+              STACK_PUSH(true, state);
+          }
+          
+          state->theIterator->close();
+        }
+        else
+        {
+          state->theIterator->count(result);
+          STACK_PUSH(true, state);
+        }
+      }
+    }
+    
+    else if (haveLower || haveUpper)
+    {
+      if (!getSearchItems(planState, state, haveLower, haveUpper, inclLower, inclUpper))
+        goto done;
+      
+      assert(state->theSearchItems.size() >= 1);
+      assert(state->theKeyType == NULL || state->theSearchItems.size() == 1);
+      
+      inclBound = (haveLower ? inclLower : inclUpper);
+      
+      state->theSearchItemsIte = state->theSearchItems.begin();
+      state->theSearchItemsEnd = state->theSearchItems.end();
+      
+      for (;
+           state->theSearchItemsIte != state->theSearchItemsEnd;
+           ++state->theSearchItemsIte)
+      {
+        cond->clear();
+        cond->pushBound(*state->theSearchItemsIte, haveLower, inclBound);
+        
+        state->theIterator->init(cond);
+        if (!theCountOnly)
+        {
+          state->theIterator->open();
+          
+          while(state->theIterator->next(result)) 
+          {
             STACK_PUSH(true, state);
-        }
-        
-        state->theIterator->close();
-      }
-      else
-      {
-        state->theIterator->count(result);
-        STACK_PUSH(true, state);
+          }
+          
+          state->theIterator->close();
+        }
+        else
+        {
+          state->theIterator->count(result);
+          STACK_PUSH(true, state);
+        }
       }
     }
-  }
-
-  else if (haveLower || haveUpper)
-  {
-    if (!getSearchItems(planState, state, haveLower, haveUpper, inclLower, inclUpper))
-      goto done;
-
-    assert(state->theSearchItems.size() >= 1);
-    assert(state->theKeyType == NULL || state->theSearchItems.size() == 1);
-
-    inclBound = (haveLower ? inclLower : inclUpper);
-
-    state->theSearchItemsIte = state->theSearchItems.begin();
-    state->theSearchItemsEnd = state->theSearchItems.end();
-
-    for (;
-         state->theSearchItemsIte != state->theSearchItemsEnd;
-         ++state->theSearchItemsIte)
+    
+    else
     {
-      cond->clear();
-      cond->pushBound(*state->theSearchItemsIte, haveLower, inclBound);
-      
+      getSearchItems(planState, state, false, false, false, false);
+
       state->theIterator->init(cond);
       if (!theCountOnly)
       {
         state->theIterator->open();
-
+        
         while(state->theIterator->next(result)) 
         {
           STACK_PUSH(true, state);
         }
-
+        
         state->theIterator->close();
       }
       else
@@ -1471,33 +1503,15 @@
         STACK_PUSH(true, state);
       }
     }
+
+  done:
+    STACK_END(state);
   }
-
-  else
+  catch (ZorbaException& e)
   {
-    getSearchItems(planState, state, false, false, false, false);
-
-    state->theIterator->init(cond);
-    if (!theCountOnly)
-    {
-      state->theIterator->open();
-
-      while(state->theIterator->next(result)) 
-      {
-        STACK_PUSH(true, state);
-      }
-
-      state->theIterator->close();
-    }
-    else
-    {
-      state->theIterator->count(result);
-      STACK_PUSH(true, state);
-    }
+    set_source(e, loc, false);
+    throw;
   }
-
- done:
-  STACK_END(state);
 }
 
 

=== added file 'test/rbkt/ExpQueryResults/zorba/numerics/comp01.xml.res'
--- test/rbkt/ExpQueryResults/zorba/numerics/comp01.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/numerics/comp01.xml.res	2012-06-01 12:05:28 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+false

=== added file 'test/rbkt/Queries/zorba/numerics/comp01.xq'
--- test/rbkt/Queries/zorba/numerics/comp01.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/numerics/comp01.xq	2012-06-01 12:05:28 +0000
@@ -0,0 +1,1 @@
+fn:number(<x/>) lt 100

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