zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #03680
[Merge] lp:~zorba-coders/zorba/bug900677 into lp:zorba
Matthias Brantner has proposed merging lp:~zorba-coders/zorba/bug900677 into lp:zorba.
Requested reviews:
Markos Zaharioudakis (markos-za)
William Candillon (wcandillon)
Related bugs:
Bug #900677 in Zorba: "XQDDF access-keys($index) function"
https://bugs.launchpad.net/zorba/+bug/900677
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug900677/+merge/88973
Added a keys() function to the index dml module. This fixes bug #900677.
--
https://code.launchpad.net/~zorba-coders/zorba/bug900677/+merge/88973
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog 2012-01-11 17:30:25 +0000
+++ ChangeLog 2012-01-18 01:10:33 +0000
@@ -21,6 +21,8 @@
support.
* zerr is not predeclared anymore to be http://www.zorba-xquery.com/errors
* Added API method Item::getNamespaceBindings().
+ * Added a function to the http://www.zorba-xquery.com/modules/store/static/indexes/dml module which returns
+ the value of all keys contained in an index.
version 2.1
=== modified file 'modules/com/zorba-xquery/www/modules/store/static/indexes/dml.xq'
--- modules/com/zorba-xquery/www/modules/store/static/indexes/dml.xq 2011-11-01 15:59:24 +0000
+++ modules/com/zorba-xquery/www/modules/store/static/indexes/dml.xq 2012-01-18 01:10:33 +0000
@@ -268,3 +268,28 @@
:)
declare updating function idml:refresh-index($name as xs:QName) external;
+(:~
+ : The keys function returns a sequence of all keys contained in the
+ : index with the given name.
+ :
+ : @param $name The QName of the index
+ : @return The result of the function is sequence of elements each representing
+ : one key contained in the index. Each element has the following
+ : structure:
+ : <pre>
+ : <key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml">
+ : <attribute value="key1_value"/>
+ : <attribute value="key2_value"/>
+ : <attribute value="key3_value"/>
+ : </key>
+ : </pre>
+ :
+ : Note that the order of the attribute elements reflects the order of
+ : the keys in the index specification. Also note that the values in
+ : these attributes have the type that is declared in the corresponding
+ : index specification.
+ :
+ : @error zerr:ZDDY0021 if the index with name $name is not declared.
+ : @error zerr:ZDDY0023 if the index with name $name does not exist.
+ :)
+declare function idml:keys($name as xs:QName) as node()* external;
=== modified file 'src/functions/library.cpp'
--- src/functions/library.cpp 2011-10-14 07:35:51 +0000
+++ src/functions/library.cpp 2012-01-18 01:10:33 +0000
@@ -41,6 +41,7 @@
#include "functions/func_fnput.h"
#include "functions/func_hoist.h"
#include "functions/func_index_ddl.h"
+#include "functions/func_index_func.h"
#include "functions/func_ic_ddl.h"
#include "functions/func_maths.h"
#include "functions/func_nodes.h"
@@ -106,6 +107,7 @@
populate_context_errors_and_diagnostics(sctx);
populate_context_fnput(sctx);
populate_context_index_ddl(sctx);
+ populate_context_index_func(sctx);
populate_context_ic_ddl(sctx);
populate_context_maths(sctx);
populate_context_nodes(sctx);
=== added file 'src/functions/pregenerated/func_index_func.cpp'
--- src/functions/pregenerated/func_index_func.cpp 1970-01-01 00:00:00 +0000
+++ src/functions/pregenerated/func_index_func.cpp 2012-01-18 01:10:33 +0000
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2006-2008 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ******************************************
+// * *
+// * THIS IS A GENERATED FILE. DO NOT EDIT! *
+// * SEE .xml FILE WITH SAME NAME *
+// * *
+// ******************************************
+
+
+#include "stdafx.h"
+#include "runtime/indexing/index_func.h"
+#include "functions/func_index_func.h"
+
+
+namespace zorba{
+
+
+
+PlanIter_t zorba_store_indexes_static_dml_keys::codegen(
+ CompilerCB*,
+ static_context* sctx,
+ const QueryLoc& loc,
+ std::vector<PlanIter_t>& argv,
+ AnnotationHolder& ann) const
+{
+ return new IndexKeysIterator(sctx, loc, argv);
+}
+
+void populate_context_index_func(static_context* sctx)
+{
+ {
+
+
+ DECL_WITH_KIND(sctx, zorba_store_indexes_static_dml_keys,
+ (createQName("http://www.zorba-xquery.com/modules/store/static/indexes/dml","","keys"),
+ GENV_TYPESYSTEM.QNAME_TYPE_ONE,
+ GENV_TYPESYSTEM.ANY_NODE_TYPE_STAR),
+ FunctionConsts::ZORBA_STORE_INDEXES_STATIC_DML_KEYS_1);
+
+ }
+
+}
+
+
+}
+
+
+
=== added file 'src/functions/pregenerated/func_index_func.h'
--- src/functions/pregenerated/func_index_func.h 1970-01-01 00:00:00 +0000
+++ src/functions/pregenerated/func_index_func.h 2012-01-18 01:10:33 +0000
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2006-2008 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ******************************************
+// * *
+// * THIS IS A GENERATED FILE. DO NOT EDIT! *
+// * SEE .xml FILE WITH SAME NAME *
+// * *
+// ******************************************
+
+
+#ifndef ZORBA_FUNCTIONS_INDEX_FUNC_H
+#define ZORBA_FUNCTIONS_INDEX_FUNC_H
+
+
+#include "common/shared_types.h"
+#include "functions/function_impl.h"
+
+
+namespace zorba {
+
+
+void populate_context_index_func(static_context* sctx);
+
+
+
+
+//zorba-store-indexes-static-dml:keys
+class zorba_store_indexes_static_dml_keys : public function
+{
+public:
+ zorba_store_indexes_static_dml_keys(const signature& sig, FunctionConsts::FunctionKind kind)
+ :
+ function(sig, kind)
+ {
+
+ }
+
+ bool accessesDynCtx() const { return true; }
+
+ CODEGEN_DECL();
+};
+
+
+} //namespace zorba
+
+
+#endif
+/*
+ * Local variables:
+ * mode: c++
+ * End:
+ */
=== modified file 'src/functions/pregenerated/function_enum.h'
--- src/functions/pregenerated/function_enum.h 2012-01-11 17:30:25 +0000
+++ src/functions/pregenerated/function_enum.h 2012-01-18 01:10:33 +0000
@@ -141,6 +141,7 @@
ZORBA_STORE_INTEGRITY_CONSTRAINTS_STATIC_DDL_ACTIVATE_1,
ZORBA_STORE_INTEGRITY_CONSTRAINTS_STATIC_DDL_DEACTIVATE_1,
ZORBA_STORE_INTEGRITY_CONSTRAINTS_STATIC_DML_CHECK_INTEGRITY_CONSTRAINT_1,
+ ZORBA_STORE_INDEXES_STATIC_DML_KEYS_1,
FN_ZORBA_INTROSPECT_SCTX_STATICALLY_KNOWN_NAMESPACES_0,
FN_ZORBA_INTROSPECT_SCTX_DEFAULT_FUNCTION_NAMESPACE_0,
FN_ZORBA_INTROSPECT_SCTX_BASE_URI_0,
=== added file 'src/runtime/indexing/index_func_impl.cpp'
--- src/runtime/indexing/index_func_impl.cpp 1970-01-01 00:00:00 +0000
+++ src/runtime/indexing/index_func_impl.cpp 2012-01-18 01:10:33 +0000
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "stdafx.h"
+
+#include "diagnostics/assert.h"
+#include "diagnostics/xquery_diagnostics.h"
+
+#include "zorbatypes/URI.h"
+
+#include "system/globalenv.h"
+
+#include "runtime/indexing/index_func.h"
+#include "runtime/indexing/index_util.h"
+
+#include "context/namespace_context.h"
+#include "context/static_context.h"
+
+#include "store/api/item.h"
+#include "store/api/index.h"
+
+#include "compiler/xqddf/value_index.h"
+
+namespace zorba {
+
+/*******************************************************************************
+********************************************************************************/
+bool
+IndexKeysIterator::nextImpl(
+ store::Item_t& result,
+ PlanState& aPlanState) const
+{
+ store::Item_t lQName;
+ IndexDecl_t indexDecl;
+ store::Index* lIndex;
+ store::IndexKey lKey;
+
+ store::Item_t lKeyNodeName;
+ GENV_ITEMFACTORY->createQName(lKeyNodeName,
+ static_context::ZORBA_STORE_DYNAMIC_UNORDERED_MAP_FN_NS,
+ "", "key");
+
+ IndexKeysIteratorState* state;
+ DEFAULT_STACK_INIT(IndexKeysIteratorState, state, aPlanState);
+
+ consumeNext(lQName, theChildren[0].getp(), aPlanState);
+
+ if ((indexDecl = theSctx->lookup_index(lQName)) == NULL)
+ {
+ throw XQUERY_EXCEPTION(
+ zerr::ZDDY0021_INDEX_NOT_DECLARED,
+ ERROR_PARAMS( lQName->getStringValue() ),
+ ERROR_LOC( loc )
+ );
+ }
+
+ lIndex = GENV_STORE.getIndex(lQName);
+
+ if (!lIndex)
+ {
+ throw XQUERY_EXCEPTION(
+ zerr::ZDDY0023_INDEX_DOES_NOT_EXIST,
+ ERROR_PARAMS( lQName->getStringValue() ),
+ ERROR_LOC( loc )
+ );
+ }
+
+ state->theIter = lIndex->keys();
+
+ state->theIter->open();
+
+ // generate result elements of the form
+ // <key>
+ // <attribute value="key1_value"/>
+ // <attribute value="key2_value"/>
+ // <attribute value="key3_value"/>
+ // </key>
+ while (state->theIter->next(lKey))
+ {
+ IndexUtil::createIndexKeyElement(
+ result, lKey, static_context::ZORBA_STORE_STATIC_INDEXES_DML_FN_NS
+ );
+ STACK_PUSH(true, state);
+ }
+
+ STACK_END(state);
+}
+
+} // namespace zorba
+/* vim:set et sw=2 ts=2: */
+
=== added file 'src/runtime/indexing/index_util.h'
--- src/runtime/indexing/index_util.h 1970-01-01 00:00:00 +0000
+++ src/runtime/indexing/index_util.h 2012-01-18 01:10:33 +0000
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef ZORBA_INDEX_UTIL_H
+#define ZORBA_INDEX_UTIL_H
+
+#include "stdafx.h"
+
+#include "context/namespace_context.h"
+
+#include "store/api/pul.h"
+#include "store/api/store.h"
+#include "store/api/item.h"
+#include "store/api/item_factory.h"
+#include "store/api/iterator.h"
+#include "store/api/index.h"
+
+#include "types/typeimpl.h"
+#include "types/typeops.h"
+#include "types/casting.h"
+
+namespace zorba {
+
+class IndexUtil
+{
+public:
+ /*******************************************************************************
+ generate result elements of the form
+ <aBase:key>
+ <aBase:attribute aBase:value="key1_value"/>
+ <aBase:attribute aBase:value="key2_value"/>
+ <aBase:attribute aBase:value="key3_value"/>
+ </aBase:key>
+ ********************************************************************************/
+ static void
+ createIndexKeyElement(
+ store::Item_t& result,
+ store::IndexKey& aKey,
+ const zstring& aBase)
+ {
+ store::Item_t lKeyNodeName;
+ GENV_ITEMFACTORY->createQName(lKeyNodeName,
+ aBase, "", "key");
+
+ zstring lBase = aBase;
+
+ store::Item_t lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
+
+ const store::NsBindings lBindings;
+
+ GENV_ITEMFACTORY->createElementNode(
+ result, NULL, lKeyNodeName, lTypeName,
+ true, false, lBindings, lBase);
+
+ for (store::ItemVector::iterator lIter = aKey.begin();
+ lIter != aKey.end();
+ ++lIter)
+ {
+ store::Item_t lAttrElem, lAttrNodeName;
+ store::Item_t lNameAttr, lValueAttr, lValueAttrName;
+
+ GENV_ITEMFACTORY->createQName(lAttrNodeName,
+ lBase, "", "attribute");
+
+ GENV_ITEMFACTORY->createQName(lValueAttrName,
+ "", "", "value");
+
+ lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
+
+ GENV_ITEMFACTORY->createElementNode(
+ lAttrElem, result, lAttrNodeName, lTypeName,
+ true, false, lBindings, lBase);
+
+ lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
+ GENV_ITEMFACTORY->createAttributeNode(
+ lValueAttr, lAttrElem.getp(), lValueAttrName, lTypeName, (*lIter));
+ }
+ }
+}; /* class IndexUtil */
+
+} // namespace zorba
+/* vim:set et sw=2 ts=2: */
+#endif
=== added file 'src/runtime/indexing/pregenerated/index_func.cpp'
--- src/runtime/indexing/pregenerated/index_func.cpp 1970-01-01 00:00:00 +0000
+++ src/runtime/indexing/pregenerated/index_func.cpp 2012-01-18 01:10:33 +0000
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2006-2008 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ******************************************
+// * *
+// * THIS IS A GENERATED FILE. DO NOT EDIT! *
+// * SEE .xml FILE WITH SAME NAME *
+// * *
+// ******************************************
+
+#include "stdafx.h"
+#include "zorbatypes/rchandle.h"
+#include "zorbatypes/zstring.h"
+#include "runtime/visitors/planiter_visitor.h"
+#include "runtime/indexing/index_func.h"
+#include "system/globalenv.h"
+
+
+#include "store/api/iterator.h"
+
+namespace zorba {
+
+// <IndexKeysIterator>
+const char* IndexKeysIterator::class_name_str = "IndexKeysIterator";
+IndexKeysIterator::class_factory<IndexKeysIterator>
+IndexKeysIterator::g_class_factory;
+
+const serialization::ClassVersion
+IndexKeysIterator::class_versions[] ={{ 1, 0x000905, false}};
+
+const int IndexKeysIterator::class_versions_count =
+sizeof(IndexKeysIterator::class_versions)/sizeof(struct serialization::ClassVersion);
+
+void IndexKeysIterator::accept(PlanIterVisitor& v) const {
+ v.beginVisit(*this);
+
+ std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin();
+ std::vector<PlanIter_t>::const_iterator lEnd = theChildren.end();
+ for ( ; lIter != lEnd; ++lIter ){
+ (*lIter)->accept(v);
+ }
+
+ v.endVisit(*this);
+}
+
+IndexKeysIterator::~IndexKeysIterator() {}
+
+IndexKeysIteratorState::IndexKeysIteratorState() {}
+
+IndexKeysIteratorState::~IndexKeysIteratorState() {}
+
+
+void IndexKeysIteratorState::init(PlanState& planState) {
+ PlanIteratorState::init(planState);
+}
+
+void IndexKeysIteratorState::reset(PlanState& planState) {
+ PlanIteratorState::reset(planState);
+}
+// </IndexKeysIterator>
+
+
+
+}
+
+
=== added file 'src/runtime/indexing/pregenerated/index_func.h'
--- src/runtime/indexing/pregenerated/index_func.h 1970-01-01 00:00:00 +0000
+++ src/runtime/indexing/pregenerated/index_func.h 2012-01-18 01:10:33 +0000
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2006-2008 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// ******************************************
+// * *
+// * THIS IS A GENERATED FILE. DO NOT EDIT! *
+// * SEE .xml FILE WITH SAME NAME *
+// * *
+// ******************************************
+#ifndef ZORBA_RUNTIME_INDEXING_INDEX_FUNC_H
+#define ZORBA_RUNTIME_INDEXING_INDEX_FUNC_H
+
+
+#include "common/shared_types.h"
+
+
+
+#include "runtime/base/narybase.h"
+#include "store/api/index.h"
+
+
+namespace zorba {
+
+/**
+ *
+ * keys($iindexName as xs:QName) as ()
+ *
+ * Author: Zorba Team
+ */
+class IndexKeysIteratorState : public PlanIteratorState
+{
+public:
+ store::Index::KeyIterator_t theIter; //
+
+ IndexKeysIteratorState();
+
+ ~IndexKeysIteratorState();
+
+ void init(PlanState&);
+ void reset(PlanState&);
+};
+
+class IndexKeysIterator : public NaryBaseIterator<IndexKeysIterator, IndexKeysIteratorState>
+{
+protected:
+ store::NsBindings theNSBindings; //
+public:
+ SERIALIZABLE_CLASS(IndexKeysIterator);
+
+ SERIALIZABLE_CLASS_CONSTRUCTOR2T(IndexKeysIterator,
+ NaryBaseIterator<IndexKeysIterator, IndexKeysIteratorState>);
+
+ void serialize( ::zorba::serialization::Archiver& ar)
+ {
+ serialize_baseclass(ar,
+ (NaryBaseIterator<IndexKeysIterator, IndexKeysIteratorState>*)this);
+
+ ar & theNSBindings;
+ }
+
+ IndexKeysIterator(
+ static_context* sctx,
+ const QueryLoc& loc,
+ std::vector<PlanIter_t>& children)
+ :
+ NaryBaseIterator<IndexKeysIterator, IndexKeysIteratorState>(sctx, loc, children),
+ theNSBindings()
+ {}
+
+ virtual ~IndexKeysIterator();
+
+ void accept(PlanIterVisitor& v) const;
+
+ bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;
+};
+
+
+}
+#endif
+/*
+ * Local variables:
+ * mode: c++
+ * End:
+ */
=== added file 'src/runtime/spec/indexing/index_func.xml'
--- src/runtime/spec/indexing/index_func.xml 1970-01-01 00:00:00 +0000
+++ src/runtime/spec/indexing/index_func.xml 2012-01-18 01:10:33 +0000
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+////////////////////////////////////////////////////////////////////////////////
+// //
+// //
+////////////////////////////////////////////////////////////////////////////////
+-->
+<zorba:iterators
+ xmlns:zorba="http://www.zorba-xquery.com"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.zorba-xquery.com ../runtime.xsd">
+
+<zorba:source>
+ <zorba:include form="Quoted">store/api/iterator.h</zorba:include>
+</zorba:source>
+
+<zorba:header>
+ <zorba:include form="Quoted">store/api/index.h</zorba:include>
+</zorba:header>
+
+<!--
+/*******************************************************************************
+*******************************************************************************/
+-->
+<zorba:iterator name="IndexKeysIterator" arity="nary">
+
+ <zorba:description author="Zorba Team">
+ keys($iindexName as xs:QName) as ()
+ </zorba:description>
+
+ <zorba:function>
+
+ <zorba:signature localname="keys"
+ prefix="zorba-store-indexes-static-dml">
+ <zorba:param>xs:QName</zorba:param>
+ <zorba:output>node()*</zorba:output>
+ </zorba:signature>
+
+ <zorba:methods>
+ <zorba:accessesDynCtx returnValue="true"/>
+ </zorba:methods>
+
+ </zorba:function>
+
+ <zorba:state>
+ <zorba:member type="store::Index::KeyIterator_t" name="theIter"/>
+ </zorba:state>
+
+ <zorba:member type="store::NsBindings" name="theNSBindings" brief=""/>
+
+</zorba:iterator>
+
+</zorba:iterators>
+
=== modified file 'src/runtime/store/maps_impl.cpp'
--- src/runtime/store/maps_impl.cpp 2011-10-26 21:13:53 +0000
+++ src/runtime/store/maps_impl.cpp 2012-01-18 01:10:33 +0000
@@ -23,6 +23,7 @@
#include "system/globalenv.h"
#include "runtime/store/maps.h"
+#include "runtime/indexing/index_util.h"
#include "context/static_context.h"
#include "context/namespace_context.h"
@@ -444,11 +445,6 @@
zstring lBaseURI =
static_context::ZORBA_STORE_DYNAMIC_UNORDERED_MAP_FN_NS;
- store::Item_t lKeyNodeName;
- GENV_ITEMFACTORY->createQName(lKeyNodeName,
- static_context::ZORBA_STORE_DYNAMIC_UNORDERED_MAP_FN_NS,
- "", "key");
-
MapKeysIteratorState* state;
DEFAULT_STACK_INIT(MapKeysIteratorState, state, aPlanState);
@@ -477,36 +473,9 @@
// </key>
while (state->theIter->next(lKey))
{
- lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
-
- GENV_ITEMFACTORY->createElementNode(
- result, NULL, lKeyNodeName, lTypeName,
- true, false, theNSBindings, lBaseURI);
-
- for (store::ItemVector::iterator lIter = lKey.begin();
- lIter != lKey.end();
- ++lIter)
- {
- store::Item_t lAttrElem, lAttrNodeName;
- store::Item_t lNameAttr, lValueAttr, lValueAttrName;
-
- GENV_ITEMFACTORY->createQName(lAttrNodeName,
- static_context::ZORBA_STORE_DYNAMIC_UNORDERED_MAP_FN_NS,
- "", "attribute");
-
- GENV_ITEMFACTORY->createQName(lValueAttrName,
- "", "", "value");
-
- lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
-
- GENV_ITEMFACTORY->createElementNode(
- lAttrElem, result, lAttrNodeName, lTypeName,
- true, false, theNSBindings, lBaseURI);
-
- lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
- GENV_ITEMFACTORY->createAttributeNode(
- lValueAttr, lAttrElem.getp(), lValueAttrName, lTypeName, (*lIter));
- }
+ IndexUtil::createIndexKeyElement(result, lKey,
+ static_context::ZORBA_STORE_DYNAMIC_UNORDERED_MAP_FN_NS
+ );
STACK_PUSH(true, state);
}
=== modified file 'src/runtime/visitors/pregenerated/planiter_visitor.h'
--- src/runtime/visitors/pregenerated/planiter_visitor.h 2012-01-11 17:30:25 +0000
+++ src/runtime/visitors/pregenerated/planiter_visitor.h 2012-01-18 01:10:33 +0000
@@ -201,6 +201,8 @@
class CheckICIterator;
+ class IndexKeysIterator;
+
class StaticNamespacesIterator;
class DefaultFunctionNamespaceIterator;
@@ -854,6 +856,9 @@
virtual void beginVisit ( const CheckICIterator& ) = 0;
virtual void endVisit ( const CheckICIterator& ) = 0;
+ virtual void beginVisit ( const IndexKeysIterator& ) = 0;
+ virtual void endVisit ( const IndexKeysIterator& ) = 0;
+
virtual void beginVisit ( const StaticNamespacesIterator& ) = 0;
virtual void endVisit ( const StaticNamespacesIterator& ) = 0;
=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.cpp'
--- src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-01-11 17:30:25 +0000
+++ src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-01-18 01:10:33 +0000
@@ -49,6 +49,7 @@
#include "runtime/fnput/fnput.h"
#include "runtime/function_item/function_item_iter.h"
#include "runtime/indexing/ic_ddl.h"
+#include "runtime/indexing/index_func.h"
#include "runtime/introspection/sctx.h"
#include "runtime/maths/maths.h"
#include "runtime/nodes/node_position.h"
@@ -1300,6 +1301,20 @@
// </CheckICIterator>
+// <IndexKeysIterator>
+void PrinterVisitor::beginVisit ( const IndexKeysIterator& a) {
+ thePrinter.startBeginVisit("IndexKeysIterator", ++theId);
+ printCommons( &a, theId );
+ thePrinter.endBeginVisit( theId );
+}
+
+void PrinterVisitor::endVisit ( const IndexKeysIterator& ) {
+ thePrinter.startEndVisit();
+ thePrinter.endEndVisit();
+}
+// </IndexKeysIterator>
+
+
// <StaticNamespacesIterator>
void PrinterVisitor::beginVisit ( const StaticNamespacesIterator& a) {
thePrinter.startBeginVisit("StaticNamespacesIterator", ++theId);
=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.h'
--- src/runtime/visitors/pregenerated/printer_visitor.h 2012-01-11 17:30:25 +0000
+++ src/runtime/visitors/pregenerated/printer_visitor.h 2012-01-18 01:10:33 +0000
@@ -304,6 +304,9 @@
void beginVisit( const CheckICIterator& );
void endVisit ( const CheckICIterator& );
+ void beginVisit( const IndexKeysIterator& );
+ void endVisit ( const IndexKeysIterator& );
+
void beginVisit( const StaticNamespacesIterator& );
void endVisit ( const StaticNamespacesIterator& );
=== modified file 'src/store/naive/simple_index_value.cpp'
--- src/store/naive/simple_index_value.cpp 2012-01-11 17:30:25 +0000
+++ src/store/naive/simple_index_value.cpp 2012-01-18 01:10:33 +0000
@@ -519,6 +519,13 @@
/******************************************************************************
********************************************************************************/
+ValueTreeIndex::KeyIterator::KeyIterator(const IndexMap& aMap)
+ :
+ theMap(aMap)
+{
+}
+
+
ValueTreeIndex::KeyIterator::~KeyIterator()
{
};
@@ -526,21 +533,29 @@
void ValueTreeIndex::KeyIterator::open()
{
- assert(false);
+ theIterator = theMap.begin();
}
-bool ValueTreeIndex::KeyIterator::next(store::IndexKey&)
+bool ValueTreeIndex::KeyIterator::next(store::IndexKey& aKey)
{
- assert(false);
+ if (theIterator != theMap.end())
+ {
+ const store::IndexKey* lKey = (*theIterator).first;
+ aKey = *lKey;
+
+ ++theIterator;
+ return true;
+ }
return false;
}
void ValueTreeIndex::KeyIterator::close()
{
- assert(false);
-}
+ theIterator = theMap.end();
+};
+
/******************************************************************************
@@ -596,8 +611,7 @@
********************************************************************************/
store::Index::KeyIterator_t ValueTreeIndex::keys() const
{
- assert(false);
- return 0;
+ return new KeyIterator(theMap);
}
=== modified file 'src/store/naive/simple_index_value.h'
--- src/store/naive/simple_index_value.h 2012-01-11 17:30:25 +0000
+++ src/store/naive/simple_index_value.h 2012-01-18 01:10:33 +0000
@@ -198,7 +198,12 @@
class KeyIterator : public Index::KeyIterator
{
+ protected:
+ IndexMap::const_iterator theIterator;
+ const IndexMap & theMap;
+
public:
+ KeyIterator(const IndexMap& aMap);
~KeyIterator();
void open();
=== added file 'test/rbkt/ExpQueryResults/zorba/index/keys1.xml.res'
--- test/rbkt/ExpQueryResults/zorba/index/keys1.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/index/keys1.xml.res 2012-01-18 01:10:33 +0000
@@ -0,0 +1,1 @@
+<keys typeIsInteger="true"><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="10"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="5"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="6"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="1"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="7"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="2"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="8"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="3"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="9"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="4"/></key></keys>
=== added file 'test/rbkt/ExpQueryResults/zorba/index/keys2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/index/keys2.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/index/keys2.xml.res 2012-01-18 01:10:33 +0000
@@ -0,0 +1,1 @@
+<keys><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="1"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="2"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="3"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="4"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="5"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="6"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="7"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="8"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="9"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="10"/></key></keys>
=== added file 'test/rbkt/Queries/zorba/index/keys1.xq'
--- test/rbkt/Queries/zorba/index/keys1.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/index/keys1.xq 2012-01-18 01:10:33 +0000
@@ -0,0 +1,22 @@
+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 index_ddl = "http://www.zorba-xquery.com/modules/store/static/indexes/ddl";
+import module namespace index_dml = "http://www.zorba-xquery.com/modules/store/static/indexes/dml";
+
+import module namespace keys-lib = "http://www.example.com/" at "keys_mod.xqlib";
+
+ddl:create(xs:QName("keys-lib:foo"));
+index_ddl:create(xs:QName("keys-lib:FooIdx"));
+
+for $i in 1 to 10
+return
+ dml:insert-nodes(xs:QName("keys-lib:foo"),
+ <foo id="{$i}"/>
+ );
+
+let $keys := index_dml:keys(xs:QName("keys-lib:FooIdx"))
+let $attr := $keys[1]/self::*:key/*:attribute/@*:value
+return
+ <keys typeIsInteger="{data($attr) instance of xs:integer}">{
+ $keys
+ }</keys>
=== added file 'test/rbkt/Queries/zorba/index/keys2.xq'
--- test/rbkt/Queries/zorba/index/keys2.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/index/keys2.xq 2012-01-18 01:10:33 +0000
@@ -0,0 +1,22 @@
+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 index_ddl = "http://www.zorba-xquery.com/modules/store/static/indexes/ddl";
+import module namespace index_dml = "http://www.zorba-xquery.com/modules/store/static/indexes/dml";
+
+import module namespace keys-lib = "http://www.example.com/" at "keys_mod.xqlib";
+
+ddl:create(xs:QName("keys-lib:foo"));
+index_ddl:create(xs:QName("keys-lib:FooIdx2"));
+
+for $i in 1 to 10
+return
+ dml:insert-nodes(xs:QName("keys-lib:foo"),
+ <foo id="{$i}"/>
+ );
+
+let $keys := index_dml:keys(xs:QName("keys-lib:FooIdx2"))
+return
+ <keys>{
+ $keys
+ }</keys>
+
=== added file 'test/rbkt/Queries/zorba/index/keys_mod.xqlib'
--- test/rbkt/Queries/zorba/index/keys_mod.xqlib 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/index/keys_mod.xqlib 2012-01-18 01:10:33 +0000
@@ -0,0 +1,15 @@
+module namespace keys-lib = "http://www.example.com/";
+
+import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
+
+declare namespace ann = "http://www.zorba-xquery.com/annotations";
+
+declare %ann:unordered collection keys-lib:foo as node()*;
+
+declare %ann:automatic %ann:value-equality index keys-lib:FooIdx
+ on nodes dml:collection(xs:QName("keys-lib:foo"))
+ by xs:integer(./@id) as xs:integer;
+
+declare %ann:automatic %ann:value-range index keys-lib:FooIdx2
+ on nodes dml:collection(xs:QName("keys-lib:foo"))
+ by xs:integer(./@id) as xs:integer;
Follow ups
-
Re: [Merge] lp:~zorba-coders/zorba/bug900677 into lp:zorba
From: Markos Zaharioudakis, 2012-07-13
-
Re: [Merge] lp:~zorba-coders/zorba/bug900677 into lp:zorba
From: Markos Zaharioudakis, 2012-07-13
-
Re: [Merge] lp:~zorba-coders/zorba/bug900677 into lp:zorba
From: Markos Zaharioudakis, 2012-07-13
-
Re: [Merge] lp:~zorba-coders/zorba/bug900677 into lp:zorba
From: Markos Zaharioudakis, 2012-01-20
-
Re: [Merge] lp:~zorba-coders/zorba/bug900677 into lp:zorba
From: William Candillon, 2012-01-20
-
Re: [Merge] lp:~zorba-coders/zorba/bug900677 into lp:zorba
From: William Candillon, 2012-01-18
-
[Merge] lp:~zorba-coders/zorba/bug900677 into lp:zorba
From: Zorba Build Bot, 2012-01-18
-
Re: [Merge] lp:~zorba-coders/zorba/bug900677 into lp:zorba
From: Zorba Build Bot, 2012-01-18
-
[Merge] lp:~zorba-coders/zorba/bug900677 into lp:zorba
From: Zorba Build Bot, 2012-01-18
-
[Merge] lp:~zorba-coders/zorba/bug900677 into lp:zorba
From: Zorba Build Bot, 2012-01-18
-
[Merge] lp:~zorba-coders/zorba/bug900677 into lp:zorba
From: Matthias Brantner, 2012-01-18
-
[Merge] lp:~zorba-coders/zorba/bug900677 into lp:zorba
From: Matthias Brantner, 2012-01-18