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

Proposed by Matthias Brantner on 2012-01-18
Status: Superseded
Proposed branch: lp:~zorba-coders/zorba/bug900677
Merge into: lp:zorba
Diff against target: 1250 lines (+905/-16)
31 files modified
ChangeLog (+2/-0)
doc/zorba/xqddf.dox (+21/-0)
modules/com/zorba-xquery/www/modules/store/static/indexes/dml.xq (+24/-0)
src/diagnostics/diagnostic_en.xml (+1/-1)
src/diagnostics/pregenerated/dict_en.cpp (+1/-1)
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 (+105/-0)
src/runtime/indexing/index_util.h (+114/-0)
src/runtime/indexing/pregenerated/index_func.cpp (+81/-0)
src/runtime/indexing/pregenerated/index_func.h (+91/-0)
src/runtime/pregenerated/iterator_enum.h (+1/-0)
src/runtime/spec/indexing/index_func.xml (+55/-0)
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_general.cpp (+51/-7)
src/store/naive/simple_index_general.h (+11/-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/keys1g.xml.res (+32/-0)
test/rbkt/ExpQueryResults/zorba/index/keys2.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/index/keys3.xml.res (+1/-0)
test/rbkt/Queries/zorba/index/keys1.xq (+22/-0)
test/rbkt/Queries/zorba/index/keys1g.xq (+26/-0)
test/rbkt/Queries/zorba/index/keys2.xq (+22/-0)
test/rbkt/Queries/zorba/index/keys3.xq (+21/-0)
test/rbkt/Queries/zorba/index/keys_mod.xqlib (+40/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug900677
Reviewer Review Type Date Requested Status
Markos Zaharioudakis 2012-01-18 Needs Fixing on 2012-07-13
Matthias Brantner Needs Information on 2012-01-18
William Candillon 2012-01-18 Needs Information on 2012-01-18
Review via email: mp+88973@code.launchpad.net

This proposal supersedes 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.
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

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

Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug900677-2012-01-18T01-16-57.605Z is finished. The final status was:

All tests succeeded!

Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1. Got: 3 Pending.

William Candillon (wcandillon) wrote :

It looks very good.

Should the actual atomic type be present in the attribute element?
If you have "by @id" where @id can be 1 or "1", you might want to create two index keys?
If a key returns (), you might want to distinguish with empty string for probing later?

By using keys(), I got the following output:
<key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="hello"></attribute><attribute value="4"></attribute></key>

Is the namespace useful or does it just make the life of the user harder?
Why isn't it:
<keys><key value="hello" /><key value="4" /></keys>
Again, could you explain me how I'm supposed to probe from such XDM if one of the actual key returned empty sequence? Should the keys have a position attribute or something?

The doc/zorba/xqddf.dox doesn't seem to mention the function, it should no?

The xqdoc seems to have a formatting problem: the output example for keys() goes out of its box.

review: Needs Information

> Should the actual atomic type be present in the attribute element?
What's the use case for this? The type is declared in the index which should be know by the user. It could be done but it's not clear how this would look like. Do you want the QName of the atomic type of the sequence type?

> If you have "by @id" where @id can be 1 or "1", you might want to create two
> index keys?
I don't understand this.

> If a key returns (), you might want to distinguish with empty string for
> probing later?
I have made a fix such that the value attribute is only present if the entry is not the empty sequence.

> By using keys(), I got the following output:
> <key xmlns="http://www.zorba-
> xquery.com/modules/store/static/indexes/dml"><attribute
> value="hello"></attribute><attribute value="4"></attribute></key>
>
> Is the namespace useful or does it just make the life of the user harder?
It's consistent with the keys function of the maps module. We can remove it but should remove it for both then (which is a backwards incompatible change).

> Why isn't it:
> <keys><key value="hello" /><key value="4" /></keys>
> Again, could you explain me how I'm supposed to probe from such XDM if one of
> the actual key returned empty sequence?
Is there a way to probe for entries where one of the keys is the empty sequence? I don't think there
is. We should have a separate bug for this.

> Should the keys have a position attribute or something?
The index of the attribute elements determines the position. Is an additional attribute really needed?

> The doc/zorba/xqddf.dox doesn't seem to mention the function, it should no?
Yes, that's done.

> > The xqdoc seems to have a formatting problem: the output example for keys()
> goes out of its box.
Fixed.

review: Needs Information
lp:~zorba-coders/zorba/bug900677 updated on 2012-01-18
10622. By Matthias Brantner on 2012-01-18

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

William Candillon (wcandillon) wrote :

> > Should the actual atomic type be present in the attribute element?
> What's the use case for this? The type is declared in the index which should
> be know by the user. It could be done but it's not clear how this would look
> like. Do you want the QName of the atomic type of the sequence type?
>
> > If you have "by @id" where @id can be 1 or "1", you might want to create two
> > index keys?
> I don't understand this.
Is it possible to have an index key as xs:anyAtomicType?
If yes, you might have an index key of value xs:string("1") and another key of value xs:integer(1).
Is this use case possible?

>
> > If a key returns (), you might want to distinguish with empty string for
> > probing later?
> I have made a fix such that the value attribute is only present if the entry
> is not the empty sequence.
Cool.
Consider the following index key declaration:
by xs:string(@team) as xs:string,
   xs:string(@country) as xs:string?,
   xs:string(@league) as xs:string?;

If keys() returns:
<keys>
  <key value="Foo" />
  <key value="Bar" />
</keys>
It's not good because I cannot probe the index with this info.
Does it makes sense?

>
>
> > By using keys(), I got the following output:
> > <key xmlns="http://www.zorba-
> > xquery.com/modules/store/static/indexes/dml"><attribute
> > value="hello"></attribute><attribute value="4"></attribute></key>
> >
> > Is the namespace useful or does it just make the life of the user harder?
> It's consistent with the keys function of the maps module. We can remove it
> but should remove it for both then (which is a backwards incompatible change).
I would fix it here and fix it for map() in 3.0.
Except if the local name attribute means something.

>
> > Why isn't it:
> > <keys><key value="hello" /><key value="4" /></keys>
> > Again, could you explain me how I'm supposed to probe from such XDM if one
> of
> > the actual key returned empty sequence?
> Is there a way to probe for entries where one of the keys is the empty
> sequence? I don't think there
> is. We should have a separate bug for this.
In Sausalito it's possible.
It was the only way to replace a particular query with an index.
How do we go forward on this?

>
> > Should the keys have a position attribute or something?
> The index of the attribute elements determines the position. Is an additional
> attribute really needed?
>
> > The doc/zorba/xqddf.dox doesn't seem to mention the function, it should no?
> Yes, that's done.
>
> > > The xqdoc seems to have a formatting problem: the output example for
> keys()
> > goes out of its box.
> Fixed.

William Candillon (wcandillon) wrote :

I hope that these comments are a little bit more clear.
I'm just trying to make sure of a single thing which is:
- Anything that is returned by keys() must be easily fed back in probe-index-point()

Therefore I'm wondering about index key types and index keys with empty sequence.

Markos Zaharioudakis (markos-za) wrote :

Matthias, the function is not implemented for general indexes, right? If yes, you should say this in the documentation and raise appropriate error in the code, unless you plan to extend it to general indexes before the next release.

Markos Zaharioudakis (markos-za) wrote :

> > > Should the actual atomic type be present in the attribute element?
> > What's the use case for this? The type is declared in the index which should
> > be know by the user. It could be done but it's not clear how this would look
> > like. Do you want the QName of the atomic type of the sequence type?
> >
> > > If you have "by @id" where @id can be 1 or "1", you might want to create
> two
> > > index keys?
> > I don't understand this.
> Is it possible to have an index key as xs:anyAtomicType?
> If yes, you might have an index key of value xs:string("1") and another key of
> value xs:integer(1).
> Is this use case possible?
>

It is not for value indexes, but it is for general indexes. Currently, the keys() function is not implemented for general indexes. If it is implemented for general indexes, then the type info should be included.

> >
> > > If a key returns (), you might want to distinguish with empty string for
> > > probing later?
> > I have made a fix such that the value attribute is only present if the entry
> > is not the empty sequence.
> Cool.
> Consider the following index key declaration:
> by xs:string(@team) as xs:string,
> xs:string(@country) as xs:string?,
> xs:string(@league) as xs:string?;
>
> If keys() returns:
> <keys>
> <key value="Foo" />
> <key value="Bar" />
> </keys>
> It's not good because I cannot probe the index with this info.
> Does it makes sense?
>
Yes, William is right. I think we need an extra attribute per key item. The attribute name would be something like "is_empty", and its value "true" or "false". The is_empty attribute could be optional; if it is not there, "false" is implied.

By the way, I really dislike "attribute" as the tag name of an element. Something like "key_item" would have been much better.

> >
> >
> > > By using keys(), I got the following output:
> > > <key xmlns="http://www.zorba-
> > > xquery.com/modules/store/static/indexes/dml"><attribute
> > > value="hello"></attribute><attribute value="4"></attribute></key>
> > >
> > > Is the namespace useful or does it just make the life of the user harder?
> > It's consistent with the keys function of the maps module. We can remove it
> > but should remove it for both then (which is a backwards incompatible
> change).
> I would fix it here and fix it for map() in 3.0.
> Except if the local name attribute means something.
>

I don't have a strong preference for this. Either way looks ok to me.

William Candillon (wcandillon) wrote :

> > > > Should the actual atomic type be present in the attribute element?
> > > What's the use case for this? The type is declared in the index which
> should
> > > be know by the user. It could be done but it's not clear how this would
> look
> > > like. Do you want the QName of the atomic type of the sequence type?
> > >
> > > > If you have "by @id" where @id can be 1 or "1", you might want to create
> > two
> > > > index keys?
> > > I don't understand this.
> > Is it possible to have an index key as xs:anyAtomicType?
> > If yes, you might have an index key of value xs:string("1") and another key
> of
> > value xs:integer(1).
> > Is this use case possible?
> >
>
> It is not for value indexes, but it is for general indexes. Currently, the
> keys() function is not implemented for general indexes. If it is implemented
> for general indexes, then the type info should be included.
>
>
> > >
> > > > If a key returns (), you might want to distinguish with empty string for
> > > > probing later?
> > > I have made a fix such that the value attribute is only present if the
> entry
> > > is not the empty sequence.
> > Cool.
> > Consider the following index key declaration:
> > by xs:string(@team) as xs:string,
> > xs:string(@country) as xs:string?,
> > xs:string(@league) as xs:string?;
> >
> > If keys() returns:
> > <keys>
> > <key value="Foo" />
> > <key value="Bar" />
> > </keys>
> > It's not good because I cannot probe the index with this info.
> > Does it makes sense?
> >
> Yes, William is right. I think we need an extra attribute per key item. The
> attribute name would be something like "is_empty", and its value "true" or
> "false". The is_empty attribute could be optional; if it is not there, "false"
> is implied.
>
> By the way, I really dislike "attribute" as the tag name of an element.
> Something like "key_item" would have been much better.
>
> > >
> > >
> > > > By using keys(), I got the following output:
> > > > <key xmlns="http://www.zorba-
> > > > xquery.com/modules/store/static/indexes/dml"><attribute
> > > > value="hello"></attribute><attribute value="4"></attribute></key>
> > > >
> > > > Is the namespace useful or does it just make the life of the user
> harder?
> > > It's consistent with the keys function of the maps module. We can remove
> it
> > > but should remove it for both then (which is a backwards incompatible
> > change).
> > I would fix it here and fix it for map() in 3.0.
> > Except if the local name attribute means something.
> >
>
> I don't have a strong preference for this. Either way looks ok to me.
So sorry it's a mistake from me, I meant to write about the local-name attribute, I'm fine with the namespace.

lp:~zorba-coders/zorba/bug900677 updated on 2012-07-12
10623. By Matthias Brantner on 2012-05-11

merge

10624. By David Graf on 2012-07-12

merged trunk

10625. By David Graf on 2012-07-12

regenerated stuff

10626. By David Graf on 2012-07-12

fixed merge bug

Markos Zaharioudakis (markos-za) wrote :

1. The function::producesDistinctNodes() and function::producesSortedNodes() methods must be redefined for the keys function.

2. Why not use element()* as the return type of keys?

3. IndexKeysIterator::nextImpl() create a new QName (lKeyNodeName) every time it is called, and the same QName is created again (!) in createIndexKeyElement(). The QName must be created only once, in the IndexKeysIterator constructor and stored as a data member. Same for the other constant qnames used in the constructed XML tree.

4. No need for a new file and class to implement function createIndexKeyElement(). You can just add it as a static function in index_func_impl.cpp

5. The type of the value attribute should be xs:untypedAtomic, not xs:untyped

review: Needs Fixing
Markos Zaharioudakis (markos-za) wrote :

Also, the documentation should say that the function is not yet implemented for general indexes, and the implementation should throw an error in this case.

lp:~zorba-coders/zorba/bug900677 updated on 2012-08-03
10627. By David Graf on 2012-07-13

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

10628. By David Graf on 2012-07-13

index-keys function test for general index

10629. By David Graf on 2012-07-16

added some comments

10630. By Matthias Brantner on 2012-07-20

merge with trunk

10631. By Matthias Brantner on 2012-07-20

minor cleanup

10632. By David Graf on 2012-08-02

merged trunk

10633. By David Graf on 2012-08-02

merged trunk

10634. By David Graf on 2012-08-03

merged trunk

10635. By David Graf on 2012-08-03

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-07-20 02:54:05 +0000
3+++ ChangeLog 2012-07-20 23:53:19 +0000
4@@ -17,6 +17,8 @@
5 http://www.zorba-xquery.com/modules/store/data-structures/unordered-map module.
6 * Added support for fragments to fn:path
7 * Positional pagination support for collections
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 * Incremental maintenance for general indexes.
11
12 Optimizations:
13
14=== modified file 'doc/zorba/xqddf.dox'
15--- doc/zorba/xqddf.dox 2012-07-12 17:29:55 +0000
16+++ doc/zorba/xqddf.dox 2012-07-20 23:53:19 +0000
17@@ -1984,6 +1984,27 @@
18 </li>
19 </ul>
20
21+\subsection index_keys Retrieving Index Keys
22+In addition to probing an index, the <tt>idml</tt> module also provides a function that allows listing all the keys contained in an index.
23+
24+\code
25+ idml:keys($indexName as xs:QName) as item()*
26+\endcode
27+
28+This function returns a sequence of element nodes.
29+Each node in the sequence represents one key contained in the index and has the following structure:
30+
31+\code
32+ <key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml">
33+ <attribute value="key_1"/>
34+ ...
35+ <attribute value="key_n"/>
36+ </key>
37+\endcode
38+
39+The order of the attribute elements reflects the order of the key specifications in the declaration of the index.
40+Also, the types of the values of the attributes are the types of the keys as they are declared.
41+If a value attribute is not present, this means that the value of the corresponding key in the index is the empty sequence.
42
43 \subsection index_maintenance Index Maintenance
44
45
46=== modified file 'modules/com/zorba-xquery/www/modules/store/static/indexes/dml.xq'
47--- modules/com/zorba-xquery/www/modules/store/static/indexes/dml.xq 2012-07-12 17:29:55 +0000
48+++ modules/com/zorba-xquery/www/modules/store/static/indexes/dml.xq 2012-07-20 23:53:19 +0000
49@@ -268,3 +268,27 @@
50 :)
51 declare updating function idml:refresh-index($name as xs:QName) external;
52
53+(:~
54+ : The keys function returns a sequence of all keys contained in the
55+ : index with the given name. Each element has the following structure:
56+ : <pre class="brush: xml;">
57+ : &lt;key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"&gt;
58+ : &lt;attribute value="key1_value"/&gt;
59+ : &lt;attribute value="key2_value"/&gt;
60+ : &lt;attribute value="key3_value"/&gt;
61+ : &lt;/key&gt;
62+ : </pre>
63+ :
64+ : @param $name The QName of the index
65+ : @return The result of the function is sequence of elements each representing
66+ : one key contained in the index.
67+ :
68+ : Note that the order of the attribute elements reflects the order of
69+ : the keys in the index specification. Also note that the values in
70+ : these attributes have the type that is declared in the corresponding
71+ : index specification.
72+ :
73+ : @error zerr:ZDDY0021 if the index with name $name is not declared.
74+ : @error zerr:ZDDY0023 if the index with name $name does not exist.
75+ :)
76+declare function idml:keys($name as xs:QName) as node()* external;
77
78=== modified file 'src/diagnostics/diagnostic_en.xml'
79--- src/diagnostics/diagnostic_en.xml 2012-07-17 13:37:41 +0000
80+++ src/diagnostics/diagnostic_en.xml 2012-07-20 23:53:19 +0000
81@@ -2254,7 +2254,7 @@
82 </diagnostic>
83
84 <diagnostic code="ZDST0035" name="INDEX_GENERAL_MULTIKEY">
85- <value>"$1": index general multikey</value>
86+ <value>"$1": number of key expressions for general indexes is restricted to one expression</value>
87 </diagnostic>
88
89 <diagnostic code="ZDST0036" name="INDEX_DECL_IN_FOREIGN_MODULE">
90
91=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
92--- src/diagnostics/pregenerated/dict_en.cpp 2012-07-17 13:37:41 +0000
93+++ src/diagnostics/pregenerated/dict_en.cpp 2012-07-20 23:53:19 +0000
94@@ -380,7 +380,7 @@
95 { "ZDST0032", "\"$1\": index references context item" },
96 { "ZDST0033", "\"$1\": index non-simple expression" },
97 { "ZDST0034", "\"$1\": index can not do automatic maintenance" },
98- { "ZDST0035", "\"$1\": index general multikey" },
99+ { "ZDST0035", "\"$1\": number of key expressions for general indexes is restricted one expression" },
100 { "ZDST0036", "\"$1\": index declaration in foreign module" },
101 { "ZDST0041", "\"$1\": integrity constraint already declared" },
102 { "ZDST0044", "\"$1\": integrity constraint declaration not allowed in main module" },
103
104=== modified file 'src/functions/library.cpp'
105--- src/functions/library.cpp 2012-07-12 17:29:55 +0000
106+++ src/functions/library.cpp 2012-07-20 23:53:19 +0000
107@@ -41,6 +41,7 @@
108 #include "functions/func_fnput.h"
109 #include "functions/func_hoist.h"
110 #include "functions/func_index_ddl.h"
111+#include "functions/func_index_func.h"
112 #include "functions/func_ic_ddl.h"
113 #include "functions/func_maths.h"
114 #include "functions/func_nodes.h"
115@@ -122,6 +123,7 @@
116 populate_context_errors_and_diagnostics(sctx);
117 populate_context_fnput(sctx);
118 populate_context_index_ddl(sctx);
119+ populate_context_index_func(sctx);
120 populate_context_ic_ddl(sctx);
121 populate_context_json(sctx);
122 populate_context_maths(sctx);
123
124=== added file 'src/functions/pregenerated/func_index_func.cpp'
125--- src/functions/pregenerated/func_index_func.cpp 1970-01-01 00:00:00 +0000
126+++ src/functions/pregenerated/func_index_func.cpp 2012-07-20 23:53:19 +0000
127@@ -0,0 +1,63 @@
128+/*
129+ * Copyright 2006-2008 The FLWOR Foundation.
130+ *
131+ * Licensed under the Apache License, Version 2.0 (the "License");
132+ * you may not use this file except in compliance with the License.
133+ * You may obtain a copy of the License at
134+ *
135+ * http://www.apache.org/licenses/LICENSE-2.0
136+ *
137+ * Unless required by applicable law or agreed to in writing, software
138+ * distributed under the License is distributed on an "AS IS" BASIS,
139+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
140+ * See the License for the specific language governing permissions and
141+ * limitations under the License.
142+ */
143+
144+// ******************************************
145+// * *
146+// * THIS IS A GENERATED FILE. DO NOT EDIT! *
147+// * SEE .xml FILE WITH SAME NAME *
148+// * *
149+// ******************************************
150+
151+
152+#include "stdafx.h"
153+#include "runtime/indexing/index_func.h"
154+#include "functions/func_index_func.h"
155+
156+
157+namespace zorba{
158+
159+
160+
161+PlanIter_t zorba_store_indexes_static_dml_keys::codegen(
162+ CompilerCB*,
163+ static_context* sctx,
164+ const QueryLoc& loc,
165+ std::vector<PlanIter_t>& argv,
166+ expr& ann) const
167+{
168+ return new IndexKeysIterator(sctx, loc, argv);
169+}
170+
171+void populate_context_index_func(static_context* sctx)
172+{
173+
174+
175+ {
176+ DECL_WITH_KIND(sctx, zorba_store_indexes_static_dml_keys,
177+ (createQName("http://www.zorba-xquery.com/modules/store/static/indexes/dml","","keys"),
178+ GENV_TYPESYSTEM.QNAME_TYPE_ONE,
179+ GENV_TYPESYSTEM.ANY_NODE_TYPE_STAR),
180+ FunctionConsts::ZORBA_STORE_INDEXES_STATIC_DML_KEYS_1);
181+
182+ }
183+
184+}
185+
186+
187+}
188+
189+
190+
191
192=== added file 'src/functions/pregenerated/func_index_func.h'
193--- src/functions/pregenerated/func_index_func.h 1970-01-01 00:00:00 +0000
194+++ src/functions/pregenerated/func_index_func.h 2012-07-20 23:53:19 +0000
195@@ -0,0 +1,66 @@
196+/*
197+ * Copyright 2006-2008 The FLWOR Foundation.
198+ *
199+ * Licensed under the Apache License, Version 2.0 (the "License");
200+ * you may not use this file except in compliance with the License.
201+ * You may obtain a copy of the License at
202+ *
203+ * http://www.apache.org/licenses/LICENSE-2.0
204+ *
205+ * Unless required by applicable law or agreed to in writing, software
206+ * distributed under the License is distributed on an "AS IS" BASIS,
207+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
208+ * See the License for the specific language governing permissions and
209+ * limitations under the License.
210+ */
211+
212+// ******************************************
213+// * *
214+// * THIS IS A GENERATED FILE. DO NOT EDIT! *
215+// * SEE .xml FILE WITH SAME NAME *
216+// * *
217+// ******************************************
218+
219+
220+#ifndef ZORBA_FUNCTIONS_INDEX_FUNC_H
221+#define ZORBA_FUNCTIONS_INDEX_FUNC_H
222+
223+
224+#include "common/shared_types.h"
225+#include "functions/function_impl.h"
226+
227+
228+namespace zorba {
229+
230+
231+void populate_context_index_func(static_context* sctx);
232+
233+
234+
235+
236+//zorba-store-indexes-static-dml:keys
237+class zorba_store_indexes_static_dml_keys : public function
238+{
239+public:
240+ zorba_store_indexes_static_dml_keys(const signature& sig, FunctionConsts::FunctionKind kind)
241+ :
242+ function(sig, kind)
243+ {
244+
245+ }
246+
247+ bool accessesDynCtx() const { return true; }
248+
249+ CODEGEN_DECL();
250+};
251+
252+
253+} //namespace zorba
254+
255+
256+#endif
257+/*
258+ * Local variables:
259+ * mode: c++
260+ * End:
261+ */
262
263=== modified file 'src/functions/pregenerated/function_enum.h'
264--- src/functions/pregenerated/function_enum.h 2012-07-12 17:29:55 +0000
265+++ src/functions/pregenerated/function_enum.h 2012-07-20 23:53:19 +0000
266@@ -197,6 +197,7 @@
267 ZORBA_STORE_INTEGRITY_CONSTRAINTS_STATIC_DDL_ACTIVATE_1,
268 ZORBA_STORE_INTEGRITY_CONSTRAINTS_STATIC_DDL_DEACTIVATE_1,
269 ZORBA_STORE_INTEGRITY_CONSTRAINTS_STATIC_DML_CHECK_INTEGRITY_CONSTRAINT_1,
270+ ZORBA_STORE_INDEXES_STATIC_DML_KEYS_1,
271 FN_ZORBA_INTROSPECT_SCTX_STATICALLY_KNOWN_NAMESPACES_0,
272 FN_ZORBA_INTROSPECT_SCTX_DEFAULT_FUNCTION_NAMESPACE_0,
273 FN_ZORBA_INTROSPECT_SCTX_BASE_URI_0,
274
275=== added file 'src/runtime/indexing/index_func_impl.cpp'
276--- src/runtime/indexing/index_func_impl.cpp 1970-01-01 00:00:00 +0000
277+++ src/runtime/indexing/index_func_impl.cpp 2012-07-20 23:53:19 +0000
278@@ -0,0 +1,105 @@
279+/*
280+ * Copyright 2006-2012 The FLWOR Foundation.
281+ *
282+ * Licensed under the Apache License, Version 2.0 (the "License");
283+ * you may not use this file except in compliance with the License.
284+ * You may obtain a copy of the License at
285+ *
286+ * http://www.apache.org/licenses/LICENSE-2.0
287+ *
288+ * Unless required by applicable law or agreed to in writing, software
289+ * distributed under the License is distributed on an "AS IS" BASIS,
290+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
291+ * See the License for the specific language governing permissions and
292+ * limitations under the License.
293+ */
294+#include "stdafx.h"
295+
296+#include "diagnostics/assert.h"
297+#include "diagnostics/xquery_diagnostics.h"
298+
299+#include "zorbatypes/URI.h"
300+
301+#include "system/globalenv.h"
302+
303+#include "runtime/indexing/index_func.h"
304+#include "runtime/indexing/index_util.h"
305+
306+#include "context/namespace_context.h"
307+#include "context/static_context.h"
308+
309+#include "store/api/item.h"
310+#include "store/api/index.h"
311+
312+#include "compiler/xqddf/value_index.h"
313+
314+namespace zorba {
315+
316+/*******************************************************************************
317+********************************************************************************/
318+bool
319+IndexKeysIterator::nextImpl(
320+ store::Item_t& result,
321+ PlanState& aPlanState) const
322+{
323+ store::Item_t lQName;
324+ IndexDecl_t indexDecl;
325+ store::Index* lIndex;
326+ store::IndexKey lKey;
327+
328+ store::Item_t lKeyNodeName;
329+ GENV_ITEMFACTORY->createQName(lKeyNodeName,
330+ static_context::ZORBA_STORE_DYNAMIC_UNORDERED_MAP_FN_NS,
331+ "", "key");
332+
333+ IndexKeysIteratorState* state;
334+ DEFAULT_STACK_INIT(IndexKeysIteratorState, state, aPlanState);
335+
336+ consumeNext(lQName, theChildren[0].getp(), aPlanState);
337+
338+ if ((indexDecl = theSctx->lookup_index(lQName)) == NULL)
339+ {
340+ throw XQUERY_EXCEPTION(
341+ zerr::ZDDY0021_INDEX_NOT_DECLARED,
342+ ERROR_PARAMS( lQName->getStringValue() ),
343+ ERROR_LOC( loc )
344+ );
345+ }
346+
347+ lIndex = GENV_STORE.getIndex(lQName);
348+
349+ if (!lIndex)
350+ {
351+ throw XQUERY_EXCEPTION(
352+ zerr::ZDDY0023_INDEX_DOES_NOT_EXIST,
353+ ERROR_PARAMS( lQName->getStringValue() ),
354+ ERROR_LOC( loc )
355+ );
356+ }
357+
358+ state->theIter = lIndex->keys();
359+
360+ state->theIter->open();
361+
362+ // generate result elements of the form
363+ // <key>
364+ // <attribute value="key1_value"/>
365+ // <attribute value="key2_value"/>
366+ // <attribute value="key3_value"/>
367+ // </key>
368+ while (state->theIter->next(lKey))
369+ {
370+ std::cout << "hallo " << lIndex->getSpecification().theIsGeneral << std::endl;
371+ IndexUtil::createIndexKeyElement(
372+ lIndex->getSpecification().theIsGeneral,
373+ result, lKey, static_context::ZORBA_STORE_STATIC_INDEXES_DML_FN_NS
374+ );
375+ STACK_PUSH(true, state);
376+ }
377+
378+ STACK_END(state);
379+}
380+
381+} // namespace zorba
382+/* vim:set et sw=2 ts=2: */
383+
384
385=== added file 'src/runtime/indexing/index_util.h'
386--- src/runtime/indexing/index_util.h 1970-01-01 00:00:00 +0000
387+++ src/runtime/indexing/index_util.h 2012-07-20 23:53:19 +0000
388@@ -0,0 +1,114 @@
389+/*
390+ * Copyright 2006-2012 The FLWOR Foundation.
391+ *
392+ * Licensed under the Apache License, Version 2.0 (the "License");
393+ * you may not use this file except in compliance with the License.
394+ * You may obtain a copy of the License at
395+ *
396+ * http://www.apache.org/licenses/LICENSE-2.0
397+ *
398+ * Unless required by applicable law or agreed to in writing, software
399+ * distributed under the License is distributed on an "AS IS" BASIS,
400+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
401+ * See the License for the specific language governing permissions and
402+ * limitations under the License.
403+ */
404+#ifndef ZORBA_INDEX_UTIL_H
405+#define ZORBA_INDEX_UTIL_H
406+
407+#include "stdafx.h"
408+
409+#include "context/namespace_context.h"
410+
411+#include "store/api/pul.h"
412+#include "store/api/store.h"
413+#include "store/api/item.h"
414+#include "store/api/item_factory.h"
415+#include "store/api/iterator.h"
416+#include "store/api/index.h"
417+
418+#include "types/typeimpl.h"
419+#include "types/typeops.h"
420+#include "types/casting.h"
421+
422+namespace zorba {
423+
424+class IndexUtil
425+{
426+public:
427+ /*******************************************************************************
428+ generate result elements of the form
429+ <aBase:key>
430+ <aBase:attribute aBase:value="key1_value"/>
431+ <aBase:attribute aBase:value="key2_value"/>
432+ <aBase:attribute aBase:value="key3_value"/>
433+ </aBase:key>
434+ ********************************************************************************/
435+ static void
436+ createIndexKeyElement(
437+ bool aIsGeneralIndex,
438+ store::Item_t& result,
439+ store::IndexKey& aKey,
440+ const zstring& aBase)
441+ {
442+ store::Item_t lKeyNodeName;
443+ GENV_ITEMFACTORY->createQName(lKeyNodeName,
444+ aBase, "", "key");
445+
446+ zstring lBase = aBase;
447+
448+ store::Item_t lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
449+
450+ const store::NsBindings lBindings;
451+
452+ GENV_ITEMFACTORY->createElementNode(
453+ result, NULL, lKeyNodeName, lTypeName,
454+ true, false, lBindings, lBase);
455+
456+ for (store::ItemVector::iterator lIter = aKey.begin();
457+ lIter != aKey.end();
458+ ++lIter)
459+ {
460+ store::Item_t lAttrElem, lAttrNodeName;
461+ store::Item_t lNameAttr, lValueAttr, lValueAttrName;
462+ store::Item_t lTypeAttr, lTypeAttrName;
463+
464+ GENV_ITEMFACTORY->createQName(lAttrNodeName,
465+ lBase, "", "attribute");
466+
467+ lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
468+ GENV_ITEMFACTORY->createElementNode(
469+ lAttrElem, result, lAttrNodeName, lTypeName,
470+ true, false, lBindings, lBase);
471+
472+ if (*lIter != NULL)
473+ {
474+
475+ if (aIsGeneralIndex)
476+ {
477+ // for general indices, the type of index key values
478+ // is returned too
479+ GENV_ITEMFACTORY->createQName(lTypeAttrName,
480+ "", "", "type");
481+
482+ store::Item_t lType = (*lIter)->getType();
483+ GENV_ITEMFACTORY->createAttributeNode(
484+ lValueAttr, lAttrElem.getp(), lTypeAttrName,
485+ lTypeName, lType);
486+ }
487+
488+ GENV_ITEMFACTORY->createQName(lValueAttrName,
489+ "", "", "value");
490+
491+ lTypeName = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
492+ GENV_ITEMFACTORY->createAttributeNode(
493+ lValueAttr, lAttrElem.getp(), lValueAttrName, lTypeName, (*lIter));
494+
495+ }
496+ }
497+ }
498+}; /* class IndexUtil */
499+
500+} // namespace zorba
501+/* vim:set et sw=2 ts=2: */
502+#endif
503
504=== added file 'src/runtime/indexing/pregenerated/index_func.cpp'
505--- src/runtime/indexing/pregenerated/index_func.cpp 1970-01-01 00:00:00 +0000
506+++ src/runtime/indexing/pregenerated/index_func.cpp 2012-07-20 23:53:19 +0000
507@@ -0,0 +1,81 @@
508+/*
509+ * Copyright 2006-2008 The FLWOR Foundation.
510+ *
511+ * Licensed under the Apache License, Version 2.0 (the "License");
512+ * you may not use this file except in compliance with the License.
513+ * You may obtain a copy of the License at
514+ *
515+ * http://www.apache.org/licenses/LICENSE-2.0
516+ *
517+ * Unless required by applicable law or agreed to in writing, software
518+ * distributed under the License is distributed on an "AS IS" BASIS,
519+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
520+ * See the License for the specific language governing permissions and
521+ * limitations under the License.
522+ */
523+
524+// ******************************************
525+// * *
526+// * THIS IS A GENERATED FILE. DO NOT EDIT! *
527+// * SEE .xml FILE WITH SAME NAME *
528+// * *
529+// ******************************************
530+
531+#include "stdafx.h"
532+#include "zorbatypes/rchandle.h"
533+#include "zorbatypes/zstring.h"
534+#include "runtime/visitors/planiter_visitor.h"
535+#include "runtime/indexing/index_func.h"
536+#include "system/globalenv.h"
537+
538+
539+#include "store/api/iterator.h"
540+
541+namespace zorba {
542+
543+// <IndexKeysIterator>
544+SERIALIZABLE_CLASS_VERSIONS(IndexKeysIterator)
545+
546+void IndexKeysIterator::serialize(::zorba::serialization::Archiver& ar)
547+{
548+ serialize_baseclass(ar,
549+ (NaryBaseIterator<IndexKeysIterator, IndexKeysIteratorState>*)this);
550+
551+ ar & theNSBindings;
552+}
553+
554+
555+void IndexKeysIterator::accept(PlanIterVisitor& v) const
556+{
557+ v.beginVisit(*this);
558+
559+ std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin();
560+ std::vector<PlanIter_t>::const_iterator lEnd = theChildren.end();
561+ for ( ; lIter != lEnd; ++lIter ){
562+ (*lIter)->accept(v);
563+ }
564+
565+ v.endVisit(*this);
566+}
567+
568+IndexKeysIterator::~IndexKeysIterator() {}
569+
570+IndexKeysIteratorState::IndexKeysIteratorState() {}
571+
572+IndexKeysIteratorState::~IndexKeysIteratorState() {}
573+
574+
575+void IndexKeysIteratorState::init(PlanState& planState) {
576+ PlanIteratorState::init(planState);
577+}
578+
579+void IndexKeysIteratorState::reset(PlanState& planState) {
580+ PlanIteratorState::reset(planState);
581+}
582+// </IndexKeysIterator>
583+
584+
585+
586+}
587+
588+
589
590=== added file 'src/runtime/indexing/pregenerated/index_func.h'
591--- src/runtime/indexing/pregenerated/index_func.h 1970-01-01 00:00:00 +0000
592+++ src/runtime/indexing/pregenerated/index_func.h 2012-07-20 23:53:19 +0000
593@@ -0,0 +1,91 @@
594+/*
595+ * Copyright 2006-2008 The FLWOR Foundation.
596+ *
597+ * Licensed under the Apache License, Version 2.0 (the "License");
598+ * you may not use this file except in compliance with the License.
599+ * You may obtain a copy of the License at
600+ *
601+ * http://www.apache.org/licenses/LICENSE-2.0
602+ *
603+ * Unless required by applicable law or agreed to in writing, software
604+ * distributed under the License is distributed on an "AS IS" BASIS,
605+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
606+ * See the License for the specific language governing permissions and
607+ * limitations under the License.
608+ */
609+
610+// ******************************************
611+// * *
612+// * THIS IS A GENERATED FILE. DO NOT EDIT! *
613+// * SEE .xml FILE WITH SAME NAME *
614+// * *
615+// ******************************************
616+#ifndef ZORBA_RUNTIME_INDEXING_INDEX_FUNC_H
617+#define ZORBA_RUNTIME_INDEXING_INDEX_FUNC_H
618+
619+
620+#include "common/shared_types.h"
621+
622+
623+
624+#include "runtime/base/narybase.h"
625+#include "store/api/index.h"
626+
627+
628+namespace zorba {
629+
630+/**
631+ *
632+ * keys($iindexName as xs:QName) as ()
633+ *
634+ * Author: Zorba Team
635+ */
636+class IndexKeysIteratorState : public PlanIteratorState
637+{
638+public:
639+ store::Index::KeyIterator_t theIter; //
640+
641+ IndexKeysIteratorState();
642+
643+ ~IndexKeysIteratorState();
644+
645+ void init(PlanState&);
646+ void reset(PlanState&);
647+};
648+
649+class IndexKeysIterator : public NaryBaseIterator<IndexKeysIterator, IndexKeysIteratorState>
650+{
651+protected:
652+ store::NsBindings theNSBindings; //
653+public:
654+ SERIALIZABLE_CLASS(IndexKeysIterator);
655+
656+ SERIALIZABLE_CLASS_CONSTRUCTOR2T(IndexKeysIterator,
657+ NaryBaseIterator<IndexKeysIterator, IndexKeysIteratorState>);
658+
659+ void serialize( ::zorba::serialization::Archiver& ar);
660+
661+ IndexKeysIterator(
662+ static_context* sctx,
663+ const QueryLoc& loc,
664+ std::vector<PlanIter_t>& children)
665+ :
666+ NaryBaseIterator<IndexKeysIterator, IndexKeysIteratorState>(sctx, loc, children),
667+ theNSBindings()
668+ {}
669+
670+ virtual ~IndexKeysIterator();
671+
672+ void accept(PlanIterVisitor& v) const;
673+
674+ bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;
675+};
676+
677+
678+}
679+#endif
680+/*
681+ * Local variables:
682+ * mode: c++
683+ * End:
684+ */
685
686=== modified file 'src/runtime/pregenerated/iterator_enum.h'
687--- src/runtime/pregenerated/iterator_enum.h 2012-07-11 15:38:39 +0000
688+++ src/runtime/pregenerated/iterator_enum.h 2012-07-20 23:53:19 +0000
689@@ -123,6 +123,7 @@
690 TYPE_ActivateICIterator,
691 TYPE_DeactivateICIterator,
692 TYPE_CheckICIterator,
693+ TYPE_IndexKeysIterator,
694 TYPE_StaticNamespacesIterator,
695 TYPE_DefaultFunctionNamespaceIterator,
696 TYPE_SctxBaseUriIterator,
697
698=== added file 'src/runtime/spec/indexing/index_func.xml'
699--- src/runtime/spec/indexing/index_func.xml 1970-01-01 00:00:00 +0000
700+++ src/runtime/spec/indexing/index_func.xml 2012-07-20 23:53:19 +0000
701@@ -0,0 +1,55 @@
702+<?xml version="1.0" encoding="UTF-8"?>
703+
704+<!--
705+////////////////////////////////////////////////////////////////////////////////
706+// //
707+// //
708+////////////////////////////////////////////////////////////////////////////////
709+-->
710+<zorba:iterators
711+ xmlns:zorba="http://www.zorba-xquery.com"
712+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
713+ xsi:schemaLocation="http://www.zorba-xquery.com ../runtime.xsd">
714+
715+<zorba:source>
716+ <zorba:include form="Quoted">store/api/iterator.h</zorba:include>
717+</zorba:source>
718+
719+<zorba:header>
720+ <zorba:include form="Quoted">store/api/index.h</zorba:include>
721+</zorba:header>
722+
723+<!--
724+/*******************************************************************************
725+*******************************************************************************/
726+-->
727+<zorba:iterator name="IndexKeysIterator" arity="nary">
728+
729+ <zorba:description author="Zorba Team">
730+ keys($iindexName as xs:QName) as ()
731+ </zorba:description>
732+
733+ <zorba:function>
734+
735+ <zorba:signature localname="keys"
736+ prefix="zorba-store-indexes-static-dml">
737+ <zorba:param>xs:QName</zorba:param>
738+ <zorba:output>node()*</zorba:output>
739+ </zorba:signature>
740+
741+ <zorba:methods>
742+ <zorba:accessesDynCtx returnValue="true"/>
743+ </zorba:methods>
744+
745+ </zorba:function>
746+
747+ <zorba:state>
748+ <zorba:member type="store::Index::KeyIterator_t" name="theIter"/>
749+ </zorba:state>
750+
751+ <zorba:member type="store::NsBindings" name="theNSBindings" brief=""/>
752+
753+</zorba:iterator>
754+
755+</zorba:iterators>
756+
757
758=== modified file 'src/runtime/visitors/pregenerated/planiter_visitor.h'
759--- src/runtime/visitors/pregenerated/planiter_visitor.h 2012-07-12 17:29:55 +0000
760+++ src/runtime/visitors/pregenerated/planiter_visitor.h 2012-07-20 23:53:19 +0000
761@@ -252,6 +252,8 @@
762
763 class CheckICIterator;
764
765+ class IndexKeysIterator;
766+
767 class StaticNamespacesIterator;
768
769 class DefaultFunctionNamespaceIterator;
770@@ -1047,6 +1049,9 @@
771 virtual void beginVisit ( const CheckICIterator& ) = 0;
772 virtual void endVisit ( const CheckICIterator& ) = 0;
773
774+ virtual void beginVisit ( const IndexKeysIterator& ) = 0;
775+ virtual void endVisit ( const IndexKeysIterator& ) = 0;
776+
777 virtual void beginVisit ( const StaticNamespacesIterator& ) = 0;
778 virtual void endVisit ( const StaticNamespacesIterator& ) = 0;
779
780
781=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.cpp'
782--- src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-07-12 17:29:55 +0000
783+++ src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-07-20 23:53:19 +0000
784@@ -50,6 +50,7 @@
785 #include "runtime/full_text/ft_module.h"
786 #include "runtime/function_item/function_item_iter.h"
787 #include "runtime/indexing/ic_ddl.h"
788+#include "runtime/indexing/index_func.h"
789 #include "runtime/introspection/sctx.h"
790 #include "runtime/json/json.h"
791 #include "runtime/json/jsoniq_functions.h"
792@@ -1571,6 +1572,20 @@
793 // </CheckICIterator>
794
795
796+// <IndexKeysIterator>
797+void PrinterVisitor::beginVisit ( const IndexKeysIterator& a) {
798+ thePrinter.startBeginVisit("IndexKeysIterator", ++theId);
799+ printCommons( &a, theId );
800+ thePrinter.endBeginVisit( theId );
801+}
802+
803+void PrinterVisitor::endVisit ( const IndexKeysIterator& ) {
804+ thePrinter.startEndVisit();
805+ thePrinter.endEndVisit();
806+}
807+// </IndexKeysIterator>
808+
809+
810 // <StaticNamespacesIterator>
811 void PrinterVisitor::beginVisit ( const StaticNamespacesIterator& a) {
812 thePrinter.startBeginVisit("StaticNamespacesIterator", ++theId);
813
814=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.h'
815--- src/runtime/visitors/pregenerated/printer_visitor.h 2012-07-12 17:29:55 +0000
816+++ src/runtime/visitors/pregenerated/printer_visitor.h 2012-07-20 23:53:19 +0000
817@@ -388,6 +388,9 @@
818 void beginVisit( const CheckICIterator& );
819 void endVisit ( const CheckICIterator& );
820
821+ void beginVisit( const IndexKeysIterator& );
822+ void endVisit ( const IndexKeysIterator& );
823+
824 void beginVisit( const StaticNamespacesIterator& );
825 void endVisit ( const StaticNamespacesIterator& );
826
827
828=== modified file 'src/store/naive/simple_index_general.cpp'
829--- src/store/naive/simple_index_general.cpp 2012-07-12 17:29:55 +0000
830+++ src/store/naive/simple_index_general.cpp 2012-07-20 23:53:19 +0000
831@@ -1151,8 +1151,7 @@
832 *******************************************************************************/
833 store::Index::KeyIterator_t GeneralHashIndex::keys() const
834 {
835- assert(false);
836- return 0;
837+ return new KeyIterator(theMaps);
838 }
839
840
841@@ -1255,6 +1254,14 @@
842 // //
843 /////////////////////////////////////////////////////////////////////////////////
844
845+/*******************************************************************************
846+
847+********************************************************************************/
848+GeneralHashIndex::KeyIterator::KeyIterator(IndexMap* const* aMaps)
849+ :
850+ theMaps(aMaps)
851+{
852+}
853
854 /******************************************************************************
855
856@@ -1263,23 +1270,60 @@
857 {
858 }
859
860+/******************************************************************************
861+ * moves theIterator to the next available iterator from theMaps
862+*******************************************************************************/
863+void GeneralHashIndex::KeyIterator::setNextIter()
864+{
865+ for ( ;
866+ theCurType < store::XS_LAST && theMaps[theCurType] == 0;
867+ ++theCurType)
868+ {}
869+
870+ if (theCurType != store::XS_LAST)
871+ theIterator = theMaps[theCurType]->begin();
872+}
873
874 /******************************************************************************
875
876 *******************************************************************************/
877 void GeneralHashIndex::KeyIterator::open()
878 {
879- assert(false);
880+ // start with first type from zorba::store::SchemaTypeCode enum
881+ theCurType = 0;
882+ // Index doesn't contain keys from all atomic types -> we need to skip the
883+ // empty ones.
884+ setNextIter();
885 }
886
887
888 /******************************************************************************
889
890 *******************************************************************************/
891-bool GeneralHashIndex::KeyIterator::next(store::IndexKey&)
892+bool GeneralHashIndex::KeyIterator::next(store::IndexKey& aKey)
893 {
894- assert(false);
895- return false;
896+ // XS_LAST marks the end of the type list -> we stop
897+ if (theCurType == store::XS_LAST)
898+ return false;
899+
900+ const store::Item* lKeyItem = (*theIterator).first;
901+ // the general index doesn't return an IndexKey object because
902+ // it doesn't support multi-value keys -> we push the key directly
903+ // into the passed IndexKey.
904+ aKey.empty();
905+ aKey.push_back(const_cast<zorba::store::Item*>(lKeyItem));
906+
907+ ++theIterator;
908+
909+ if (theIterator == theMaps[theCurType]->end())
910+ {
911+ // iteration of the keys of the current type is done.
912+ // increase type and search for the next valid iterator.
913+ ++theCurType;
914+ setNextIter();
915+ }
916+
917+ return true;
918 }
919
920
921@@ -1288,7 +1332,7 @@
922 *******************************************************************************/
923 void GeneralHashIndex::KeyIterator::close()
924 {
925- assert(false);
926+ theCurType = store::XS_LAST;
927 }
928
929
930
931=== modified file 'src/store/naive/simple_index_general.h'
932--- src/store/naive/simple_index_general.h 2012-07-12 17:29:55 +0000
933+++ src/store/naive/simple_index_general.h 2012-07-20 23:53:19 +0000
934@@ -220,14 +220,25 @@
935
936 typedef IndexMap::iterator EntryIterator;
937
938+ /*
939+ * This iterator iterates over all index keys from all types
940+ */
941 class KeyIterator : public Index::KeyIterator
942 {
943+ protected:
944+ IndexMap::iterator theIterator;
945+ IndexMap* const* theMaps;
946+ ulong theCurType;
947 public:
948+ KeyIterator(IndexMap* const* aMaps);
949 ~KeyIterator();
950
951 void open();
952 bool next(store::IndexKey&);
953 void close();
954+
955+ private:
956+ void setNextIter();
957 };
958
959 typedef rchandle<KeyIterator> KeyIterator_t;
960
961=== modified file 'src/store/naive/simple_index_value.cpp'
962--- src/store/naive/simple_index_value.cpp 2012-07-12 17:29:55 +0000
963+++ src/store/naive/simple_index_value.cpp 2012-07-20 23:53:19 +0000
964@@ -563,6 +563,13 @@
965 /******************************************************************************
966
967 ********************************************************************************/
968+ValueTreeIndex::KeyIterator::KeyIterator(const IndexMap& aMap)
969+ :
970+ theMap(aMap)
971+{
972+}
973+
974+
975 ValueTreeIndex::KeyIterator::~KeyIterator()
976 {
977 };
978@@ -570,21 +577,29 @@
979
980 void ValueTreeIndex::KeyIterator::open()
981 {
982- assert(false);
983+ theIterator = theMap.begin();
984 }
985
986
987-bool ValueTreeIndex::KeyIterator::next(store::IndexKey&)
988+bool ValueTreeIndex::KeyIterator::next(store::IndexKey& aKey)
989 {
990- assert(false);
991+ if (theIterator != theMap.end())
992+ {
993+ const store::IndexKey* lKey = (*theIterator).first;
994+ aKey = *lKey;
995+
996+ ++theIterator;
997+ return true;
998+ }
999 return false;
1000 }
1001
1002
1003 void ValueTreeIndex::KeyIterator::close()
1004 {
1005- assert(false);
1006-}
1007+ theIterator = theMap.end();
1008+};
1009+
1010
1011
1012 /******************************************************************************
1013@@ -652,8 +667,7 @@
1014 ********************************************************************************/
1015 store::Index::KeyIterator_t ValueTreeIndex::keys() const
1016 {
1017- assert(false);
1018- return 0;
1019+ return new KeyIterator(theMap);
1020 }
1021
1022
1023
1024=== modified file 'src/store/naive/simple_index_value.h'
1025--- src/store/naive/simple_index_value.h 2012-07-12 17:29:55 +0000
1026+++ src/store/naive/simple_index_value.h 2012-07-20 23:53:19 +0000
1027@@ -208,7 +208,12 @@
1028
1029 class KeyIterator : public Index::KeyIterator
1030 {
1031+ protected:
1032+ IndexMap::const_iterator theIterator;
1033+ const IndexMap & theMap;
1034+
1035 public:
1036+ KeyIterator(const IndexMap& aMap);
1037 ~KeyIterator();
1038
1039 void open();
1040
1041=== added file 'test/rbkt/ExpQueryResults/zorba/index/keys1.xml.res'
1042--- test/rbkt/ExpQueryResults/zorba/index/keys1.xml.res 1970-01-01 00:00:00 +0000
1043+++ test/rbkt/ExpQueryResults/zorba/index/keys1.xml.res 2012-07-20 23:53:19 +0000
1044@@ -0,0 +1,1 @@
1045+<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>
1046
1047=== added file 'test/rbkt/ExpQueryResults/zorba/index/keys1g.xml.res'
1048--- test/rbkt/ExpQueryResults/zorba/index/keys1g.xml.res 1970-01-01 00:00:00 +0000
1049+++ test/rbkt/ExpQueryResults/zorba/index/keys1g.xml.res 2012-07-20 23:53:19 +0000
1050@@ -0,0 +1,32 @@
1051+<keys>
1052+ <key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml">
1053+ <attribute type="xs:string" value="2"></attribute>
1054+ </key>
1055+ <key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml">
1056+ <attribute type="xs:string" value="6"></attribute>
1057+ </key>
1058+ <key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml">
1059+ <attribute type="xs:string" value="4"></attribute>
1060+ </key>
1061+ <key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml">
1062+ <attribute type="xs:string" value="10"></attribute>
1063+ </key>
1064+ <key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml">
1065+ <attribute type="xs:string" value="8"></attribute>
1066+ </key>
1067+ <key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml">
1068+ <attribute type="xs:long" value="0"></attribute>
1069+ </key>
1070+ <key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml">
1071+ <attribute type="xs:long" value="6"></attribute>
1072+ </key>
1073+ <key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml">
1074+ <attribute type="xs:long" value="2"></attribute>
1075+ </key>
1076+ <key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml">
1077+ <attribute type="xs:long" value="8"></attribute>
1078+ </key>
1079+ <key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml">
1080+ <attribute type="xs:long" value="4"></attribute>
1081+ </key>
1082+</keys>
1083
1084=== added file 'test/rbkt/ExpQueryResults/zorba/index/keys2.xml.res'
1085--- test/rbkt/ExpQueryResults/zorba/index/keys2.xml.res 1970-01-01 00:00:00 +0000
1086+++ test/rbkt/ExpQueryResults/zorba/index/keys2.xml.res 2012-07-20 23:53:19 +0000
1087@@ -0,0 +1,1 @@
1088+<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>
1089
1090=== added file 'test/rbkt/ExpQueryResults/zorba/index/keys3.xml.res'
1091--- test/rbkt/ExpQueryResults/zorba/index/keys3.xml.res 1970-01-01 00:00:00 +0000
1092+++ test/rbkt/ExpQueryResults/zorba/index/keys3.xml.res 2012-07-20 23:53:19 +0000
1093@@ -0,0 +1,1 @@
1094+<keys><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="1"/><attribute/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="10"/><attribute value="me"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="2"/><attribute/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="3"/><attribute/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="4"/><attribute/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="5"/><attribute value="me"/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="6"/><attribute/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="7"/><attribute/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="8"/><attribute/></key><key xmlns="http://www.zorba-xquery.com/modules/store/static/indexes/dml"><attribute value="9"/><attribute/></key></keys>
1095
1096=== added file 'test/rbkt/Queries/zorba/index/keys1.xq'
1097--- test/rbkt/Queries/zorba/index/keys1.xq 1970-01-01 00:00:00 +0000
1098+++ test/rbkt/Queries/zorba/index/keys1.xq 2012-07-20 23:53:19 +0000
1099@@ -0,0 +1,22 @@
1100+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";
1101+import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
1102+import module namespace index_ddl = "http://www.zorba-xquery.com/modules/store/static/indexes/ddl";
1103+import module namespace index_dml = "http://www.zorba-xquery.com/modules/store/static/indexes/dml";
1104+
1105+import module namespace keys-lib = "http://www.example.com/" at "keys_mod.xqlib";
1106+
1107+ddl:create(xs:QName("keys-lib:foo"));
1108+index_ddl:create(xs:QName("keys-lib:FooIdx"));
1109+
1110+for $i in 1 to 10
1111+return
1112+ dml:insert-nodes(xs:QName("keys-lib:foo"),
1113+ <foo id="{$i}"/>
1114+ );
1115+
1116+let $keys := index_dml:keys(xs:QName("keys-lib:FooIdx"))
1117+let $attr := $keys[1]/self::*:key/*:attribute/@*:value
1118+return
1119+ <keys typeIsInteger="{data($attr) instance of xs:integer}">{
1120+ $keys
1121+ }</keys>
1122
1123=== added file 'test/rbkt/Queries/zorba/index/keys1g.xq'
1124--- test/rbkt/Queries/zorba/index/keys1g.xq 1970-01-01 00:00:00 +0000
1125+++ test/rbkt/Queries/zorba/index/keys1g.xq 2012-07-20 23:53:19 +0000
1126@@ -0,0 +1,26 @@
1127+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";
1128+import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
1129+import module namespace index_ddl = "http://www.zorba-xquery.com/modules/store/static/indexes/ddl";
1130+import module namespace index_dml = "http://www.zorba-xquery.com/modules/store/static/indexes/dml";
1131+
1132+import module namespace keys-lib = "http://www.example.com/" at "keys_mod.xqlib";
1133+
1134+ddl:create(xs:QName("keys-lib:foo"));
1135+index_ddl:create(xs:QName("keys-lib:FooIdx-general"));
1136+
1137+for $i in 1 to 10
1138+return
1139+ dml:insert-nodes(xs:QName("keys-lib:foo"),
1140+ if ($i mod 2 = 0) then
1141+ <foo id="{$i}"/>
1142+ else
1143+ <foo id="{$i - 1}" string="true"/>
1144+ );
1145+
1146+let $keys := index_dml:keys(xs:QName("keys-lib:FooIdx-general"))
1147+let $attr := $keys[1]/self::*:key/*:attribute/@*:value
1148+return
1149+ <keys>{
1150+ $keys
1151+ }</keys>
1152+
1153
1154=== added file 'test/rbkt/Queries/zorba/index/keys2.xq'
1155--- test/rbkt/Queries/zorba/index/keys2.xq 1970-01-01 00:00:00 +0000
1156+++ test/rbkt/Queries/zorba/index/keys2.xq 2012-07-20 23:53:19 +0000
1157@@ -0,0 +1,22 @@
1158+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";
1159+import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
1160+import module namespace index_ddl = "http://www.zorba-xquery.com/modules/store/static/indexes/ddl";
1161+import module namespace index_dml = "http://www.zorba-xquery.com/modules/store/static/indexes/dml";
1162+
1163+import module namespace keys-lib = "http://www.example.com/" at "keys_mod.xqlib";
1164+
1165+ddl:create(xs:QName("keys-lib:foo"));
1166+index_ddl:create(xs:QName("keys-lib:FooIdx2"));
1167+
1168+for $i in 1 to 10
1169+return
1170+ dml:insert-nodes(xs:QName("keys-lib:foo"),
1171+ <foo id="{$i}"/>
1172+ );
1173+
1174+let $keys := index_dml:keys(xs:QName("keys-lib:FooIdx2"))
1175+return
1176+ <keys>{
1177+ $keys
1178+ }</keys>
1179+
1180
1181=== added file 'test/rbkt/Queries/zorba/index/keys3.xq'
1182--- test/rbkt/Queries/zorba/index/keys3.xq 1970-01-01 00:00:00 +0000
1183+++ test/rbkt/Queries/zorba/index/keys3.xq 2012-07-20 23:53:19 +0000
1184@@ -0,0 +1,21 @@
1185+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";
1186+import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
1187+import module namespace index_ddl = "http://www.zorba-xquery.com/modules/store/static/indexes/ddl";
1188+import module namespace index_dml = "http://www.zorba-xquery.com/modules/store/static/indexes/dml";
1189+
1190+import module namespace keys-lib = "http://www.example.com/" at "keys_mod.xqlib";
1191+
1192+ddl:create(xs:QName("keys-lib:foo"));
1193+index_ddl:create(xs:QName("keys-lib:FooIdx3"));
1194+
1195+for $i in 1 to 10
1196+return
1197+ dml:insert-nodes(xs:QName("keys-lib:foo"),
1198+ if ($i mod 5 eq 0) then <foo id="{$i}" name="me"/> else <foo id="{$i}"/>
1199+ );
1200+
1201+let $keys := index_dml:keys(xs:QName("keys-lib:FooIdx3"))
1202+return
1203+ <keys>{
1204+ $keys
1205+ }</keys>
1206
1207=== added file 'test/rbkt/Queries/zorba/index/keys_mod.xqlib'
1208--- test/rbkt/Queries/zorba/index/keys_mod.xqlib 1970-01-01 00:00:00 +0000
1209+++ test/rbkt/Queries/zorba/index/keys_mod.xqlib 2012-07-20 23:53:19 +0000
1210@@ -0,0 +1,40 @@
1211+module namespace keys-lib = "http://www.example.com/";
1212+
1213+import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
1214+
1215+declare namespace ann = "http://www.zorba-xquery.com/annotations";
1216+
1217+declare %ann:unordered collection keys-lib:foo as node()*;
1218+
1219+declare %ann:automatic %ann:value-equality index keys-lib:FooIdx
1220+ on nodes dml:collection(xs:QName("keys-lib:foo"))
1221+ by xs:integer(./@id) as xs:integer;
1222+
1223+declare %ann:automatic %ann:value-range index keys-lib:FooIdx2
1224+ on nodes dml:collection(xs:QName("keys-lib:foo"))
1225+ by xs:integer(./@id) as xs:integer;
1226+
1227+declare %ann:automatic %ann:value-range index keys-lib:FooIdx3
1228+ on nodes dml:collection(xs:QName("keys-lib:foo"))
1229+ by xs:string(./@id) as xs:string, (if (./@name) then xs:string(./@name) else ()) as xs:string?;
1230+
1231+declare %ann:automatic %ann:general-equality index keys-lib:FooIdx-general
1232+ on nodes dml:collection(xs:QName("keys-lib:foo"))
1233+ by
1234+ (
1235+ let $val := fn:data(./@id)
1236+ return
1237+ if (./@string) then
1238+ xs:long($val)
1239+ else
1240+ xs:string($val)
1241+ )
1242+ as xs:anyAtomicType;
1243+
1244+declare %ann:automatic %ann:general-range index keys-lib:FooIdx2-general
1245+ on nodes dml:collection(xs:QName("keys-lib:foo"))
1246+ by xs:integer(./@id) as xs:integer;
1247+
1248+declare %ann:automatic %ann:general-range index keys-lib:FooIdx3-general
1249+ on nodes dml:collection(xs:QName("keys-lib:foo"))
1250+ by (if (./@name) then xs:string(./@name) else ()) as xs:string?;

Subscribers

People subscribed via source and target branches