Merge lp:~zorba-coders/zorba/bug900677 into lp:zorba

Proposed by Matthias Brantner
Status: Superseded
Proposed branch: lp:~zorba-coders/zorba/bug900677
Merge into: lp:zorba
Diff against target: 970 lines (+702/-42)
22 files modified
ChangeLog (+2/-0)
modules/com/zorba-xquery/www/modules/store/static/indexes/dml.xq (+25/-0)
src/functions/library.cpp (+2/-0)
src/functions/pregenerated/func_index_func.cpp (+63/-0)
src/functions/pregenerated/func_index_func.h (+66/-0)
src/functions/pregenerated/function_enum.h (+1/-0)
src/runtime/indexing/index_func_impl.cpp (+103/-0)
src/runtime/indexing/index_util.h (+95/-0)
src/runtime/indexing/pregenerated/index_func.cpp (+79/-0)
src/runtime/indexing/pregenerated/index_func.h (+97/-0)
src/runtime/spec/indexing/index_func.xml (+55/-0)
src/runtime/store/maps_impl.cpp (+4/-35)
src/runtime/visitors/pregenerated/planiter_visitor.h (+5/-0)
src/runtime/visitors/pregenerated/printer_visitor.cpp (+15/-0)
src/runtime/visitors/pregenerated/printer_visitor.h (+3/-0)
src/store/naive/simple_index_value.cpp (+21/-7)
src/store/naive/simple_index_value.h (+5/-0)
test/rbkt/ExpQueryResults/zorba/index/keys1.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/index/keys2.xml.res (+1/-0)
test/rbkt/Queries/zorba/index/keys1.xq (+22/-0)
test/rbkt/Queries/zorba/index/keys2.xq (+22/-0)
test/rbkt/Queries/zorba/index/keys_mod.xqlib (+15/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug900677
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Pending
William Candillon Pending
Review via email: mp+88972@code.launchpad.net

This proposal has been superseded by a proposal from 2012-01-18.

Commit message

Added a keys() function to the index dml module. This fixes bug #900677.

Description of the change

Added a keys() function to the index dml module. This fixes bug #900677.

To post a comment you must log in.
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:~zorba-coders/zorba/bug900677 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:273 (message):
  Validation queue job bug900677-2012-01-18T01-02-56.733Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

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

lp:~zorba-coders/zorba/bug900677 updated
10622. By Matthias Brantner

Fixed a bug when a key attribute in an index is the empty sequence. Also, improved the
documentation for the idml:keys function.

10623. By Matthias Brantner

merge

10624. By David Graf

merged trunk

10625. By David Graf

regenerated stuff

10626. By David Graf

fixed merge bug

10627. By David Graf

commit of work in progress - keys function for general indices does work. Cleanup and more tests needed.

10628. By David Graf

index-keys function test for general index

10629. By David Graf

added some comments

10630. By Matthias Brantner

merge with trunk

10631. By Matthias Brantner

minor cleanup

10632. By David Graf

merged trunk

10633. By David Graf

merged trunk

10634. By David Graf

merged trunk

10635. By David Graf

fixed segfault

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2012-01-11 17:30:25 +0000
3+++ ChangeLog 2012-01-18 01:11:25 +0000
4@@ -21,6 +21,8 @@
5 support.
6 * zerr is not predeclared anymore to be http://www.zorba-xquery.com/errors
7 * Added API method Item::getNamespaceBindings().
8+ * Added a function to the http://www.zorba-xquery.com/modules/store/static/indexes/dml module which returns
9+ the value of all keys contained in an index.
10
11 version 2.1
12
13
14=== modified file 'modules/com/zorba-xquery/www/modules/store/static/indexes/dml.xq'
15--- modules/com/zorba-xquery/www/modules/store/static/indexes/dml.xq 2011-11-01 15:59:24 +0000
16+++ modules/com/zorba-xquery/www/modules/store/static/indexes/dml.xq 2012-01-18 01:11:25 +0000
17@@ -268,3 +268,28 @@
18 :)
19 declare updating function idml:refresh-index($name as xs:QName) external;
20
21+(:~
22+ : The keys function returns a sequence of all keys contained in the
23+ : index with the given name.
24+ :
25+ : @param $name The QName of the index
26+ : @return The result of the function is sequence of elements each representing
27+ : one key contained in the index. Each element has the following
28+ : structure:
29+ : <pre>
30+ : &lt;key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml">
31+ : &lt;attribute value="key1_value"/>
32+ : &lt;attribute value="key2_value"/>
33+ : &lt;attribute value="key3_value"/>
34+ : &lt;/key>
35+ : </pre>
36+ :
37+ : Note that the order of the attribute elements reflects the order of
38+ : the keys in the index specification. Also note that the values in
39+ : these attributes have the type that is declared in the corresponding
40+ : index specification.
41+ :
42+ : @error zerr:ZDDY0021 if the index with name $name is not declared.
43+ : @error zerr:ZDDY0023 if the index with name $name does not exist.
44+ :)
45+declare function idml:keys($name as xs:QName) as node()* external;
46
47=== modified file 'src/functions/library.cpp'
48--- src/functions/library.cpp 2011-10-14 07:35:51 +0000
49+++ src/functions/library.cpp 2012-01-18 01:11:25 +0000
50@@ -41,6 +41,7 @@
51 #include "functions/func_fnput.h"
52 #include "functions/func_hoist.h"
53 #include "functions/func_index_ddl.h"
54+#include "functions/func_index_func.h"
55 #include "functions/func_ic_ddl.h"
56 #include "functions/func_maths.h"
57 #include "functions/func_nodes.h"
58@@ -106,6 +107,7 @@
59 populate_context_errors_and_diagnostics(sctx);
60 populate_context_fnput(sctx);
61 populate_context_index_ddl(sctx);
62+ populate_context_index_func(sctx);
63 populate_context_ic_ddl(sctx);
64 populate_context_maths(sctx);
65 populate_context_nodes(sctx);
66
67=== added file 'src/functions/pregenerated/func_index_func.cpp'
68--- src/functions/pregenerated/func_index_func.cpp 1970-01-01 00:00:00 +0000
69+++ src/functions/pregenerated/func_index_func.cpp 2012-01-18 01:11:25 +0000
70@@ -0,0 +1,63 @@
71+/*
72+ * Copyright 2006-2008 The FLWOR Foundation.
73+ *
74+ * Licensed under the Apache License, Version 2.0 (the "License");
75+ * you may not use this file except in compliance with the License.
76+ * You may obtain a copy of the License at
77+ *
78+ * http://www.apache.org/licenses/LICENSE-2.0
79+ *
80+ * Unless required by applicable law or agreed to in writing, software
81+ * distributed under the License is distributed on an "AS IS" BASIS,
82+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
83+ * See the License for the specific language governing permissions and
84+ * limitations under the License.
85+ */
86+
87+// ******************************************
88+// * *
89+// * THIS IS A GENERATED FILE. DO NOT EDIT! *
90+// * SEE .xml FILE WITH SAME NAME *
91+// * *
92+// ******************************************
93+
94+
95+#include "stdafx.h"
96+#include "runtime/indexing/index_func.h"
97+#include "functions/func_index_func.h"
98+
99+
100+namespace zorba{
101+
102+
103+
104+PlanIter_t zorba_store_indexes_static_dml_keys::codegen(
105+ CompilerCB*,
106+ static_context* sctx,
107+ const QueryLoc& loc,
108+ std::vector<PlanIter_t>& argv,
109+ AnnotationHolder& ann) const
110+{
111+ return new IndexKeysIterator(sctx, loc, argv);
112+}
113+
114+void populate_context_index_func(static_context* sctx)
115+{
116+ {
117+
118+
119+ DECL_WITH_KIND(sctx, zorba_store_indexes_static_dml_keys,
120+ (createQName("http://www.zorba-xquery.com/modules/store/static/indexes/dml","","keys"),
121+ GENV_TYPESYSTEM.QNAME_TYPE_ONE,
122+ GENV_TYPESYSTEM.ANY_NODE_TYPE_STAR),
123+ FunctionConsts::ZORBA_STORE_INDEXES_STATIC_DML_KEYS_1);
124+
125+ }
126+
127+}
128+
129+
130+}
131+
132+
133+
134
135=== added file 'src/functions/pregenerated/func_index_func.h'
136--- src/functions/pregenerated/func_index_func.h 1970-01-01 00:00:00 +0000
137+++ src/functions/pregenerated/func_index_func.h 2012-01-18 01:11:25 +0000
138@@ -0,0 +1,66 @@
139+/*
140+ * Copyright 2006-2008 The FLWOR Foundation.
141+ *
142+ * Licensed under the Apache License, Version 2.0 (the "License");
143+ * you may not use this file except in compliance with the License.
144+ * You may obtain a copy of the License at
145+ *
146+ * http://www.apache.org/licenses/LICENSE-2.0
147+ *
148+ * Unless required by applicable law or agreed to in writing, software
149+ * distributed under the License is distributed on an "AS IS" BASIS,
150+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
151+ * See the License for the specific language governing permissions and
152+ * limitations under the License.
153+ */
154+
155+// ******************************************
156+// * *
157+// * THIS IS A GENERATED FILE. DO NOT EDIT! *
158+// * SEE .xml FILE WITH SAME NAME *
159+// * *
160+// ******************************************
161+
162+
163+#ifndef ZORBA_FUNCTIONS_INDEX_FUNC_H
164+#define ZORBA_FUNCTIONS_INDEX_FUNC_H
165+
166+
167+#include "common/shared_types.h"
168+#include "functions/function_impl.h"
169+
170+
171+namespace zorba {
172+
173+
174+void populate_context_index_func(static_context* sctx);
175+
176+
177+
178+
179+//zorba-store-indexes-static-dml:keys
180+class zorba_store_indexes_static_dml_keys : public function
181+{
182+public:
183+ zorba_store_indexes_static_dml_keys(const signature& sig, FunctionConsts::FunctionKind kind)
184+ :
185+ function(sig, kind)
186+ {
187+
188+ }
189+
190+ bool accessesDynCtx() const { return true; }
191+
192+ CODEGEN_DECL();
193+};
194+
195+
196+} //namespace zorba
197+
198+
199+#endif
200+/*
201+ * Local variables:
202+ * mode: c++
203+ * End:
204+ */
205
206=== modified file 'src/functions/pregenerated/function_enum.h'
207--- src/functions/pregenerated/function_enum.h 2012-01-11 17:30:25 +0000
208+++ src/functions/pregenerated/function_enum.h 2012-01-18 01:11:25 +0000
209@@ -141,6 +141,7 @@
210 ZORBA_STORE_INTEGRITY_CONSTRAINTS_STATIC_DDL_ACTIVATE_1,
211 ZORBA_STORE_INTEGRITY_CONSTRAINTS_STATIC_DDL_DEACTIVATE_1,
212 ZORBA_STORE_INTEGRITY_CONSTRAINTS_STATIC_DML_CHECK_INTEGRITY_CONSTRAINT_1,
213+ ZORBA_STORE_INDEXES_STATIC_DML_KEYS_1,
214 FN_ZORBA_INTROSPECT_SCTX_STATICALLY_KNOWN_NAMESPACES_0,
215 FN_ZORBA_INTROSPECT_SCTX_DEFAULT_FUNCTION_NAMESPACE_0,
216 FN_ZORBA_INTROSPECT_SCTX_BASE_URI_0,
217
218=== added file 'src/runtime/indexing/index_func_impl.cpp'
219--- src/runtime/indexing/index_func_impl.cpp 1970-01-01 00:00:00 +0000
220+++ src/runtime/indexing/index_func_impl.cpp 2012-01-18 01:11:25 +0000
221@@ -0,0 +1,103 @@
222+/*
223+ * Copyright 2006-2012 The FLWOR Foundation.
224+ *
225+ * Licensed under the Apache License, Version 2.0 (the "License");
226+ * you may not use this file except in compliance with the License.
227+ * You may obtain a copy of the License at
228+ *
229+ * http://www.apache.org/licenses/LICENSE-2.0
230+ *
231+ * Unless required by applicable law or agreed to in writing, software
232+ * distributed under the License is distributed on an "AS IS" BASIS,
233+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
234+ * See the License for the specific language governing permissions and
235+ * limitations under the License.
236+ */
237+#include "stdafx.h"
238+
239+#include "diagnostics/assert.h"
240+#include "diagnostics/xquery_diagnostics.h"
241+
242+#include "zorbatypes/URI.h"
243+
244+#include "system/globalenv.h"
245+
246+#include "runtime/indexing/index_func.h"
247+#include "runtime/indexing/index_util.h"
248+
249+#include "context/namespace_context.h"
250+#include "context/static_context.h"
251+
252+#include "store/api/item.h"
253+#include "store/api/index.h"
254+
255+#include "compiler/xqddf/value_index.h"
256+
257+namespace zorba {
258+
259+/*******************************************************************************
260+********************************************************************************/
261+bool
262+IndexKeysIterator::nextImpl(
263+ store::Item_t& result,
264+ PlanState& aPlanState) const
265+{
266+ store::Item_t lQName;
267+ IndexDecl_t indexDecl;
268+ store::Index* lIndex;
269+ store::IndexKey lKey;
270+
271+ store::Item_t lKeyNodeName;
272+ GENV_ITEMFACTORY->createQName(lKeyNodeName,
273+ static_context::ZORBA_STORE_DYNAMIC_UNORDERED_MAP_FN_NS,
274+ "", "key");
275+
276+ IndexKeysIteratorState* state;
277+ DEFAULT_STACK_INIT(IndexKeysIteratorState, state, aPlanState);
278+
279+ consumeNext(lQName, theChildren[0].getp(), aPlanState);
280+
281+ if ((indexDecl = theSctx->lookup_index(lQName)) == NULL)
282+ {
283+ throw XQUERY_EXCEPTION(
284+ zerr::ZDDY0021_INDEX_NOT_DECLARED,
285+ ERROR_PARAMS( lQName->getStringValue() ),
286+ ERROR_LOC( loc )
287+ );
288+ }
289+
290+ lIndex = GENV_STORE.getIndex(lQName);
291+
292+ if (!lIndex)
293+ {
294+ throw XQUERY_EXCEPTION(
295+ zerr::ZDDY0023_INDEX_DOES_NOT_EXIST,
296+ ERROR_PARAMS( lQName->getStringValue() ),
297+ ERROR_LOC( loc )
298+ );
299+ }
300+
301+ state->theIter = lIndex->keys();
302+
303+ state->theIter->open();
304+
305+ // generate result elements of the form
306+ // <key>
307+ // <attribute value="key1_value"/>
308+ // <attribute value="key2_value"/>
309+ // <attribute value="key3_value"/>
310+ // </key>
311+ while (state->theIter->next(lKey))
312+ {
313+ IndexUtil::createIndexKeyElement(
314+ result, lKey, static_context::ZORBA_STORE_STATIC_INDEXES_DML_FN_NS
315+ );
316+ STACK_PUSH(true, state);
317+ }
318+
319+ STACK_END(state);
320+}
321+
322+} // namespace zorba
323+/* vim:set et sw=2 ts=2: */
324+
325
326=== added file 'src/runtime/indexing/index_util.h'
327--- src/runtime/indexing/index_util.h 1970-01-01 00:00:00 +0000
328+++ src/runtime/indexing/index_util.h 2012-01-18 01:11:25 +0000
329@@ -0,0 +1,95 @@
330+/*
331+ * Copyright 2006-2012 The FLWOR Foundation.
332+ *
333+ * Licensed under the Apache License, Version 2.0 (the "License");
334+ * you may not use this file except in compliance with the License.
335+ * You may obtain a copy of the License at
336+ *
337+ * http://www.apache.org/licenses/LICENSE-2.0
338+ *
339+ * Unless required by applicable law or agreed to in writing, software
340+ * distributed under the License is distributed on an "AS IS" BASIS,
341+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
342+ * See the License for the specific language governing permissions and
343+ * limitations under the License.
344+ */
345+#ifndef ZORBA_INDEX_UTIL_H
346+#define ZORBA_INDEX_UTIL_H
347+
348+#include "stdafx.h"
349+
350+#include "context/namespace_context.h"
351+
352+#include "store/api/pul.h"
353+#include "store/api/store.h"
354+#include "store/api/item.h"
355+#include "store/api/item_factory.h"
356+#include "store/api/iterator.h"
357+#include "store/api/index.h"
358+
359+#include "types/typeimpl.h"
360+#include "types/typeops.h"
361+#include "types/casting.h"
362+
363+namespace zorba {
364+
365+class IndexUtil
366+{
367+public:
368+ /*******************************************************************************
369+ generate result elements of the form
370+ <aBase:key>
371+ <aBase:attribute aBase:value="key1_value"/>
372+ <aBase:attribute aBase:value="key2_value"/>
373+ <aBase:attribute aBase:value="key3_value"/>
374+ </aBase:key>
375+ ********************************************************************************/
376+ static void
377+ createIndexKeyElement(
378+ store::Item_t& result,
379+ store::IndexKey& aKey,
380+ const zstring& aBase)
381+ {
382+ store::Item_t lKeyNodeName;
383+ GENV_ITEMFACTORY->createQName(lKeyNodeName,
384+ aBase, "", "key");
385+
386+ zstring lBase = aBase;
387+
388+ store::Item_t lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
389+
390+ const store::NsBindings lBindings;
391+
392+ GENV_ITEMFACTORY->createElementNode(
393+ result, NULL, lKeyNodeName, lTypeName,
394+ true, false, lBindings, lBase);
395+
396+ for (store::ItemVector::iterator lIter = aKey.begin();
397+ lIter != aKey.end();
398+ ++lIter)
399+ {
400+ store::Item_t lAttrElem, lAttrNodeName;
401+ store::Item_t lNameAttr, lValueAttr, lValueAttrName;
402+
403+ GENV_ITEMFACTORY->createQName(lAttrNodeName,
404+ lBase, "", "attribute");
405+
406+ GENV_ITEMFACTORY->createQName(lValueAttrName,
407+ "", "", "value");
408+
409+ lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
410+
411+ GENV_ITEMFACTORY->createElementNode(
412+ lAttrElem, result, lAttrNodeName, lTypeName,
413+ true, false, lBindings, lBase);
414+
415+ lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
416+ GENV_ITEMFACTORY->createAttributeNode(
417+ lValueAttr, lAttrElem.getp(), lValueAttrName, lTypeName, (*lIter));
418+ }
419+ }
420+}; /* class IndexUtil */
421+
422+} // namespace zorba
423+/* vim:set et sw=2 ts=2: */
424+#endif
425
426=== added file 'src/runtime/indexing/pregenerated/index_func.cpp'
427--- src/runtime/indexing/pregenerated/index_func.cpp 1970-01-01 00:00:00 +0000
428+++ src/runtime/indexing/pregenerated/index_func.cpp 2012-01-18 01:11:25 +0000
429@@ -0,0 +1,79 @@
430+/*
431+ * Copyright 2006-2008 The FLWOR Foundation.
432+ *
433+ * Licensed under the Apache License, Version 2.0 (the "License");
434+ * you may not use this file except in compliance with the License.
435+ * You may obtain a copy of the License at
436+ *
437+ * http://www.apache.org/licenses/LICENSE-2.0
438+ *
439+ * Unless required by applicable law or agreed to in writing, software
440+ * distributed under the License is distributed on an "AS IS" BASIS,
441+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
442+ * See the License for the specific language governing permissions and
443+ * limitations under the License.
444+ */
445+
446+// ******************************************
447+// * *
448+// * THIS IS A GENERATED FILE. DO NOT EDIT! *
449+// * SEE .xml FILE WITH SAME NAME *
450+// * *
451+// ******************************************
452+
453+#include "stdafx.h"
454+#include "zorbatypes/rchandle.h"
455+#include "zorbatypes/zstring.h"
456+#include "runtime/visitors/planiter_visitor.h"
457+#include "runtime/indexing/index_func.h"
458+#include "system/globalenv.h"
459+
460+
461+#include "store/api/iterator.h"
462+
463+namespace zorba {
464+
465+// <IndexKeysIterator>
466+const char* IndexKeysIterator::class_name_str = "IndexKeysIterator";
467+IndexKeysIterator::class_factory<IndexKeysIterator>
468+IndexKeysIterator::g_class_factory;
469+
470+const serialization::ClassVersion
471+IndexKeysIterator::class_versions[] ={{ 1, 0x000905, false}};
472+
473+const int IndexKeysIterator::class_versions_count =
474+sizeof(IndexKeysIterator::class_versions)/sizeof(struct serialization::ClassVersion);
475+
476+void IndexKeysIterator::accept(PlanIterVisitor& v) const {
477+ v.beginVisit(*this);
478+
479+ std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin();
480+ std::vector<PlanIter_t>::const_iterator lEnd = theChildren.end();
481+ for ( ; lIter != lEnd; ++lIter ){
482+ (*lIter)->accept(v);
483+ }
484+
485+ v.endVisit(*this);
486+}
487+
488+IndexKeysIterator::~IndexKeysIterator() {}
489+
490+IndexKeysIteratorState::IndexKeysIteratorState() {}
491+
492+IndexKeysIteratorState::~IndexKeysIteratorState() {}
493+
494+
495+void IndexKeysIteratorState::init(PlanState& planState) {
496+ PlanIteratorState::init(planState);
497+}
498+
499+void IndexKeysIteratorState::reset(PlanState& planState) {
500+ PlanIteratorState::reset(planState);
501+}
502+// </IndexKeysIterator>
503+
504+
505+
506+}
507+
508+
509
510=== added file 'src/runtime/indexing/pregenerated/index_func.h'
511--- src/runtime/indexing/pregenerated/index_func.h 1970-01-01 00:00:00 +0000
512+++ src/runtime/indexing/pregenerated/index_func.h 2012-01-18 01:11:25 +0000
513@@ -0,0 +1,97 @@
514+/*
515+ * Copyright 2006-2008 The FLWOR Foundation.
516+ *
517+ * Licensed under the Apache License, Version 2.0 (the "License");
518+ * you may not use this file except in compliance with the License.
519+ * You may obtain a copy of the License at
520+ *
521+ * http://www.apache.org/licenses/LICENSE-2.0
522+ *
523+ * Unless required by applicable law or agreed to in writing, software
524+ * distributed under the License is distributed on an "AS IS" BASIS,
525+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
526+ * See the License for the specific language governing permissions and
527+ * limitations under the License.
528+ */
529+
530+// ******************************************
531+// * *
532+// * THIS IS A GENERATED FILE. DO NOT EDIT! *
533+// * SEE .xml FILE WITH SAME NAME *
534+// * *
535+// ******************************************
536+#ifndef ZORBA_RUNTIME_INDEXING_INDEX_FUNC_H
537+#define ZORBA_RUNTIME_INDEXING_INDEX_FUNC_H
538+
539+
540+#include "common/shared_types.h"
541+
542+
543+
544+#include "runtime/base/narybase.h"
545+#include "store/api/index.h"
546+
547+
548+namespace zorba {
549+
550+/**
551+ *
552+ * keys($iindexName as xs:QName) as ()
553+ *
554+ * Author: Zorba Team
555+ */
556+class IndexKeysIteratorState : public PlanIteratorState
557+{
558+public:
559+ store::Index::KeyIterator_t theIter; //
560+
561+ IndexKeysIteratorState();
562+
563+ ~IndexKeysIteratorState();
564+
565+ void init(PlanState&);
566+ void reset(PlanState&);
567+};
568+
569+class IndexKeysIterator : public NaryBaseIterator<IndexKeysIterator, IndexKeysIteratorState>
570+{
571+protected:
572+ store::NsBindings theNSBindings; //
573+public:
574+ SERIALIZABLE_CLASS(IndexKeysIterator);
575+
576+ SERIALIZABLE_CLASS_CONSTRUCTOR2T(IndexKeysIterator,
577+ NaryBaseIterator<IndexKeysIterator, IndexKeysIteratorState>);
578+
579+ void serialize( ::zorba::serialization::Archiver& ar)
580+ {
581+ serialize_baseclass(ar,
582+ (NaryBaseIterator<IndexKeysIterator, IndexKeysIteratorState>*)this);
583+
584+ ar & theNSBindings;
585+ }
586+
587+ IndexKeysIterator(
588+ static_context* sctx,
589+ const QueryLoc& loc,
590+ std::vector<PlanIter_t>& children)
591+ :
592+ NaryBaseIterator<IndexKeysIterator, IndexKeysIteratorState>(sctx, loc, children),
593+ theNSBindings()
594+ {}
595+
596+ virtual ~IndexKeysIterator();
597+
598+ void accept(PlanIterVisitor& v) const;
599+
600+ bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;
601+};
602+
603+
604+}
605+#endif
606+/*
607+ * Local variables:
608+ * mode: c++
609+ * End:
610+ */
611
612=== added file 'src/runtime/spec/indexing/index_func.xml'
613--- src/runtime/spec/indexing/index_func.xml 1970-01-01 00:00:00 +0000
614+++ src/runtime/spec/indexing/index_func.xml 2012-01-18 01:11:25 +0000
615@@ -0,0 +1,55 @@
616+<?xml version="1.0" encoding="UTF-8"?>
617+
618+<!--
619+////////////////////////////////////////////////////////////////////////////////
620+// //
621+// //
622+////////////////////////////////////////////////////////////////////////////////
623+-->
624+<zorba:iterators
625+ xmlns:zorba="http://www.zorba-xquery.com"
626+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
627+ xsi:schemaLocation="http://www.zorba-xquery.com ../runtime.xsd">
628+
629+<zorba:source>
630+ <zorba:include form="Quoted">store/api/iterator.h</zorba:include>
631+</zorba:source>
632+
633+<zorba:header>
634+ <zorba:include form="Quoted">store/api/index.h</zorba:include>
635+</zorba:header>
636+
637+<!--
638+/*******************************************************************************
639+*******************************************************************************/
640+-->
641+<zorba:iterator name="IndexKeysIterator" arity="nary">
642+
643+ <zorba:description author="Zorba Team">
644+ keys($iindexName as xs:QName) as ()
645+ </zorba:description>
646+
647+ <zorba:function>
648+
649+ <zorba:signature localname="keys"
650+ prefix="zorba-store-indexes-static-dml">
651+ <zorba:param>xs:QName</zorba:param>
652+ <zorba:output>node()*</zorba:output>
653+ </zorba:signature>
654+
655+ <zorba:methods>
656+ <zorba:accessesDynCtx returnValue="true"/>
657+ </zorba:methods>
658+
659+ </zorba:function>
660+
661+ <zorba:state>
662+ <zorba:member type="store::Index::KeyIterator_t" name="theIter"/>
663+ </zorba:state>
664+
665+ <zorba:member type="store::NsBindings" name="theNSBindings" brief=""/>
666+
667+</zorba:iterator>
668+
669+</zorba:iterators>
670+
671
672=== modified file 'src/runtime/store/maps_impl.cpp'
673--- src/runtime/store/maps_impl.cpp 2011-10-26 21:13:53 +0000
674+++ src/runtime/store/maps_impl.cpp 2012-01-18 01:11:25 +0000
675@@ -23,6 +23,7 @@
676 #include "system/globalenv.h"
677
678 #include "runtime/store/maps.h"
679+#include "runtime/indexing/index_util.h"
680
681 #include "context/static_context.h"
682 #include "context/namespace_context.h"
683@@ -444,11 +445,6 @@
684 zstring lBaseURI =
685 static_context::ZORBA_STORE_DYNAMIC_UNORDERED_MAP_FN_NS;
686
687- store::Item_t lKeyNodeName;
688- GENV_ITEMFACTORY->createQName(lKeyNodeName,
689- static_context::ZORBA_STORE_DYNAMIC_UNORDERED_MAP_FN_NS,
690- "", "key");
691-
692 MapKeysIteratorState* state;
693 DEFAULT_STACK_INIT(MapKeysIteratorState, state, aPlanState);
694
695@@ -477,36 +473,9 @@
696 // </key>
697 while (state->theIter->next(lKey))
698 {
699- lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
700-
701- GENV_ITEMFACTORY->createElementNode(
702- result, NULL, lKeyNodeName, lTypeName,
703- true, false, theNSBindings, lBaseURI);
704-
705- for (store::ItemVector::iterator lIter = lKey.begin();
706- lIter != lKey.end();
707- ++lIter)
708- {
709- store::Item_t lAttrElem, lAttrNodeName;
710- store::Item_t lNameAttr, lValueAttr, lValueAttrName;
711-
712- GENV_ITEMFACTORY->createQName(lAttrNodeName,
713- static_context::ZORBA_STORE_DYNAMIC_UNORDERED_MAP_FN_NS,
714- "", "attribute");
715-
716- GENV_ITEMFACTORY->createQName(lValueAttrName,
717- "", "", "value");
718-
719- lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
720-
721- GENV_ITEMFACTORY->createElementNode(
722- lAttrElem, result, lAttrNodeName, lTypeName,
723- true, false, theNSBindings, lBaseURI);
724-
725- lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
726- GENV_ITEMFACTORY->createAttributeNode(
727- lValueAttr, lAttrElem.getp(), lValueAttrName, lTypeName, (*lIter));
728- }
729+ IndexUtil::createIndexKeyElement(result, lKey,
730+ static_context::ZORBA_STORE_DYNAMIC_UNORDERED_MAP_FN_NS
731+ );
732 STACK_PUSH(true, state);
733 }
734
735
736=== modified file 'src/runtime/visitors/pregenerated/planiter_visitor.h'
737--- src/runtime/visitors/pregenerated/planiter_visitor.h 2012-01-11 17:30:25 +0000
738+++ src/runtime/visitors/pregenerated/planiter_visitor.h 2012-01-18 01:11:25 +0000
739@@ -201,6 +201,8 @@
740
741 class CheckICIterator;
742
743+ class IndexKeysIterator;
744+
745 class StaticNamespacesIterator;
746
747 class DefaultFunctionNamespaceIterator;
748@@ -854,6 +856,9 @@
749 virtual void beginVisit ( const CheckICIterator& ) = 0;
750 virtual void endVisit ( const CheckICIterator& ) = 0;
751
752+ virtual void beginVisit ( const IndexKeysIterator& ) = 0;
753+ virtual void endVisit ( const IndexKeysIterator& ) = 0;
754+
755 virtual void beginVisit ( const StaticNamespacesIterator& ) = 0;
756 virtual void endVisit ( const StaticNamespacesIterator& ) = 0;
757
758
759=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.cpp'
760--- src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-01-11 17:30:25 +0000
761+++ src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-01-18 01:11:25 +0000
762@@ -49,6 +49,7 @@
763 #include "runtime/fnput/fnput.h"
764 #include "runtime/function_item/function_item_iter.h"
765 #include "runtime/indexing/ic_ddl.h"
766+#include "runtime/indexing/index_func.h"
767 #include "runtime/introspection/sctx.h"
768 #include "runtime/maths/maths.h"
769 #include "runtime/nodes/node_position.h"
770@@ -1300,6 +1301,20 @@
771 // </CheckICIterator>
772
773
774+// <IndexKeysIterator>
775+void PrinterVisitor::beginVisit ( const IndexKeysIterator& a) {
776+ thePrinter.startBeginVisit("IndexKeysIterator", ++theId);
777+ printCommons( &a, theId );
778+ thePrinter.endBeginVisit( theId );
779+}
780+
781+void PrinterVisitor::endVisit ( const IndexKeysIterator& ) {
782+ thePrinter.startEndVisit();
783+ thePrinter.endEndVisit();
784+}
785+// </IndexKeysIterator>
786+
787+
788 // <StaticNamespacesIterator>
789 void PrinterVisitor::beginVisit ( const StaticNamespacesIterator& a) {
790 thePrinter.startBeginVisit("StaticNamespacesIterator", ++theId);
791
792=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.h'
793--- src/runtime/visitors/pregenerated/printer_visitor.h 2012-01-11 17:30:25 +0000
794+++ src/runtime/visitors/pregenerated/printer_visitor.h 2012-01-18 01:11:25 +0000
795@@ -304,6 +304,9 @@
796 void beginVisit( const CheckICIterator& );
797 void endVisit ( const CheckICIterator& );
798
799+ void beginVisit( const IndexKeysIterator& );
800+ void endVisit ( const IndexKeysIterator& );
801+
802 void beginVisit( const StaticNamespacesIterator& );
803 void endVisit ( const StaticNamespacesIterator& );
804
805
806=== modified file 'src/store/naive/simple_index_value.cpp'
807--- src/store/naive/simple_index_value.cpp 2012-01-11 17:30:25 +0000
808+++ src/store/naive/simple_index_value.cpp 2012-01-18 01:11:25 +0000
809@@ -519,6 +519,13 @@
810 /******************************************************************************
811
812 ********************************************************************************/
813+ValueTreeIndex::KeyIterator::KeyIterator(const IndexMap& aMap)
814+ :
815+ theMap(aMap)
816+{
817+}
818+
819+
820 ValueTreeIndex::KeyIterator::~KeyIterator()
821 {
822 };
823@@ -526,21 +533,29 @@
824
825 void ValueTreeIndex::KeyIterator::open()
826 {
827- assert(false);
828+ theIterator = theMap.begin();
829 }
830
831
832-bool ValueTreeIndex::KeyIterator::next(store::IndexKey&)
833+bool ValueTreeIndex::KeyIterator::next(store::IndexKey& aKey)
834 {
835- assert(false);
836+ if (theIterator != theMap.end())
837+ {
838+ const store::IndexKey* lKey = (*theIterator).first;
839+ aKey = *lKey;
840+
841+ ++theIterator;
842+ return true;
843+ }
844 return false;
845 }
846
847
848 void ValueTreeIndex::KeyIterator::close()
849 {
850- assert(false);
851-}
852+ theIterator = theMap.end();
853+};
854+
855
856
857 /******************************************************************************
858@@ -596,8 +611,7 @@
859 ********************************************************************************/
860 store::Index::KeyIterator_t ValueTreeIndex::keys() const
861 {
862- assert(false);
863- return 0;
864+ return new KeyIterator(theMap);
865 }
866
867
868
869=== modified file 'src/store/naive/simple_index_value.h'
870--- src/store/naive/simple_index_value.h 2012-01-11 17:30:25 +0000
871+++ src/store/naive/simple_index_value.h 2012-01-18 01:11:25 +0000
872@@ -198,7 +198,12 @@
873
874 class KeyIterator : public Index::KeyIterator
875 {
876+ protected:
877+ IndexMap::const_iterator theIterator;
878+ const IndexMap & theMap;
879+
880 public:
881+ KeyIterator(const IndexMap& aMap);
882 ~KeyIterator();
883
884 void open();
885
886=== added file 'test/rbkt/ExpQueryResults/zorba/index/keys1.xml.res'
887--- test/rbkt/ExpQueryResults/zorba/index/keys1.xml.res 1970-01-01 00:00:00 +0000
888+++ test/rbkt/ExpQueryResults/zorba/index/keys1.xml.res 2012-01-18 01:11:25 +0000
889@@ -0,0 +1,1 @@
890+<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>
891
892=== added file 'test/rbkt/ExpQueryResults/zorba/index/keys2.xml.res'
893--- test/rbkt/ExpQueryResults/zorba/index/keys2.xml.res 1970-01-01 00:00:00 +0000
894+++ test/rbkt/ExpQueryResults/zorba/index/keys2.xml.res 2012-01-18 01:11:25 +0000
895@@ -0,0 +1,1 @@
896+<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>
897
898=== added file 'test/rbkt/Queries/zorba/index/keys1.xq'
899--- test/rbkt/Queries/zorba/index/keys1.xq 1970-01-01 00:00:00 +0000
900+++ test/rbkt/Queries/zorba/index/keys1.xq 2012-01-18 01:11:25 +0000
901@@ -0,0 +1,22 @@
902+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";
903+import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
904+import module namespace index_ddl = "http://www.zorba-xquery.com/modules/store/static/indexes/ddl";
905+import module namespace index_dml = "http://www.zorba-xquery.com/modules/store/static/indexes/dml";
906+
907+import module namespace keys-lib = "http://www.example.com/" at "keys_mod.xqlib";
908+
909+ddl:create(xs:QName("keys-lib:foo"));
910+index_ddl:create(xs:QName("keys-lib:FooIdx"));
911+
912+for $i in 1 to 10
913+return
914+ dml:insert-nodes(xs:QName("keys-lib:foo"),
915+ <foo id="{$i}"/>
916+ );
917+
918+let $keys := index_dml:keys(xs:QName("keys-lib:FooIdx"))
919+let $attr := $keys[1]/self::*:key/*:attribute/@*:value
920+return
921+ <keys typeIsInteger="{data($attr) instance of xs:integer}">{
922+ $keys
923+ }</keys>
924
925=== added file 'test/rbkt/Queries/zorba/index/keys2.xq'
926--- test/rbkt/Queries/zorba/index/keys2.xq 1970-01-01 00:00:00 +0000
927+++ test/rbkt/Queries/zorba/index/keys2.xq 2012-01-18 01:11:25 +0000
928@@ -0,0 +1,22 @@
929+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";
930+import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
931+import module namespace index_ddl = "http://www.zorba-xquery.com/modules/store/static/indexes/ddl";
932+import module namespace index_dml = "http://www.zorba-xquery.com/modules/store/static/indexes/dml";
933+
934+import module namespace keys-lib = "http://www.example.com/" at "keys_mod.xqlib";
935+
936+ddl:create(xs:QName("keys-lib:foo"));
937+index_ddl:create(xs:QName("keys-lib:FooIdx2"));
938+
939+for $i in 1 to 10
940+return
941+ dml:insert-nodes(xs:QName("keys-lib:foo"),
942+ <foo id="{$i}"/>
943+ );
944+
945+let $keys := index_dml:keys(xs:QName("keys-lib:FooIdx2"))
946+return
947+ <keys>{
948+ $keys
949+ }</keys>
950+
951
952=== added file 'test/rbkt/Queries/zorba/index/keys_mod.xqlib'
953--- test/rbkt/Queries/zorba/index/keys_mod.xqlib 1970-01-01 00:00:00 +0000
954+++ test/rbkt/Queries/zorba/index/keys_mod.xqlib 2012-01-18 01:11:25 +0000
955@@ -0,0 +1,15 @@
956+module namespace keys-lib = "http://www.example.com/";
957+
958+import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
959+
960+declare namespace ann = "http://www.zorba-xquery.com/annotations";
961+
962+declare %ann:unordered collection keys-lib:foo as node()*;
963+
964+declare %ann:automatic %ann:value-equality index keys-lib:FooIdx
965+ on nodes dml:collection(xs:QName("keys-lib:foo"))
966+ by xs:integer(./@id) as xs:integer;
967+
968+declare %ann:automatic %ann:value-range index keys-lib:FooIdx2
969+ on nodes dml:collection(xs:QName("keys-lib:foo"))
970+ by xs:integer(./@id) as xs:integer;

Subscribers

People subscribed via source and target branches