Merge lp:~zorba-coders/zorba/markos-scratch into lp:zorba

Proposed by Markos Zaharioudakis
Status: Merged
Approved by: Markos Zaharioudakis
Approved revision: 11154
Merged at revision: 11525
Proposed branch: lp:~zorba-coders/zorba/markos-scratch
Merge into: lp:zorba
Diff against target: 269 lines (+58/-58)
9 files modified
modules/ExternalModules.conf (+1/-1)
modules/org/jsoniq/www/functions.xq (+13/-9)
src/runtime/json/jsoniq_functions_impl.cpp (+26/-29)
src/runtime/json/pregenerated/jsoniq_functions.cpp (+0/-8)
src/runtime/json/pregenerated/jsoniq_functions.h (+3/-2)
src/runtime/sequences/sequences_impl.cpp (+1/-1)
src/runtime/spec/json/jsoniq_functions.xml (+9/-8)
test/rbkt/ExpQueryResults/zorba/jsoniq/keys_05.xml.res (+1/-0)
test/rbkt/Queries/zorba/jsoniq/keys_05.xq (+4/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/markos-scratch
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Approve
Review via email: mp+170167@code.launchpad.net

Commit message

duplicate elimination for the jn:keys() function

Description of the change

duplicate elimination for the jn:keys() function

To post a comment you must log in.
Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job markos-scratch-2013-06-18T19-09-54.451Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/ExternalModules.conf'
2--- modules/ExternalModules.conf 2013-06-18 11:03:29 +0000
3+++ modules/ExternalModules.conf 2013-06-18 18:57:39 +0000
4@@ -52,4 +52,4 @@
5 stack bzr lp:zorba/stack-module zorba-2.9
6 queue bzr lp:zorba/queue-module zorba-2.9
7 couchbase bzr lp:zorba/couchbase-module
8-#sqlite bzr lp:zorba/sqlite-module
9+sqlite bzr lp:zorba/sqlite-module
10
11=== modified file 'modules/org/jsoniq/www/functions.xq'
12--- modules/org/jsoniq/www/functions.xq 2013-06-15 02:57:08 +0000
13+++ modules/org/jsoniq/www/functions.xq 2013-06-18 18:57:39 +0000
14@@ -184,11 +184,13 @@
15
16
17 (:~
18- : Returns the names used in the object.
19- : The names will be returned in an implementation-defined order
20+ : Returns the set of keys belonging to the objects found inside a given
21+ : sequence of items. The keys are returned in an implementation-defined
22+ : order. Duplicate keys are eliminated.
23 :
24- : @param $o A JSON Object.
25- : @return The names of pairs in the object.
26+ : @param $o A sequence of items. Only object items are actually processed;
27+ : items of any other kind are simply skipped.
28+ : @return The distinct keys of the objects in the input sequence.
29 :)
30 declare function jn:keys($o as item()*) as xs:string* external;
31
32@@ -235,17 +237,19 @@
33 : @param $p The position in the array.
34 : @return The member at the specified position, or empty sequence.
35 :)
36-(: obsolete - use $a($p) instead :)
37+(: obsolete - use $a($p) or $a[[$p]] instead :)
38 declare function jn:member($a as item(), $p as item()?) as item()? external;
39
40
41 (:~
42- : Returns the members of an Array.
43+ : Returns the items belonging to the arrays found inside a given sequence
44+ : of items. The items are returned in an implementation-defined order.
45 :
46- : @param $a A JSON Array.
47- : @return The members of the specified array.
48+ : @param $a A sequence of items. Only array items are actually processed;
49+ : items of any other kind are simply skipped.
50+ : @return The members of the arrays in the input sequence.
51 :)
52-declare function jn:members($o as item()*) as item()* external;
53+declare function jn:members($a as item()*) as item()* external;
54
55
56 (:~
57
58=== modified file 'src/runtime/json/jsoniq_functions_impl.cpp'
59--- src/runtime/json/jsoniq_functions_impl.cpp 2013-06-15 02:57:08 +0000
60+++ src/runtime/json/jsoniq_functions_impl.cpp 2013-06-18 18:57:39 +0000
61@@ -48,11 +48,11 @@
62
63 #include <runtime/util/doc_uri_heuristics.h>
64
65-#include <store/api/pul.h>
66-#include <store/api/item.h>
67-#include <store/api/item_factory.h>
68-#include <store/api/store.h>
69-#include <store/api/copymode.h>
70+#include "store/api/pul.h"
71+#include "store/api/item.h"
72+#include "store/api/item_factory.h"
73+#include "store/api/store.h"
74+#include "store/api/copymode.h"
75
76 #include "util/uri_util.h"
77 #include "util/stream_util.h"
78@@ -1126,11 +1126,26 @@
79 /*******************************************************************************
80 jn:names($o as item()*) as xs:string*
81 ********************************************************************************/
82+
83+void JSONObjectNamesIteratorState::init(PlanState& planState)
84+{
85+ theNamesSet.reset(new HashSet<zstring, HashMapZStringCmp>(64, false));
86+}
87+
88+
89+void JSONObjectNamesIteratorState::reset(PlanState& planState)
90+{
91+ PlanIteratorState::reset(planState);
92+ theNamesSet->clear();
93+}
94+
95+
96 bool JSONObjectNamesIterator::nextImpl(
97 store::Item_t& result,
98 PlanState& planState) const
99 {
100 store::Item_t input;
101+ zstring name;
102
103 JSONObjectNamesIteratorState* state;
104 DEFAULT_STACK_INIT(JSONObjectNamesIteratorState, state, planState);
105@@ -1144,7 +1159,12 @@
106
107 while (state->theNames->next(result))
108 {
109- STACK_PUSH (true, state);
110+ name = result->getStringValue();
111+ if (!state->theNamesSet->exists(name))
112+ {
113+ state->theNamesSet->insert(name);
114+ STACK_PUSH(true, state);
115+ }
116 }
117 state->theNames = NULL;
118 }
119@@ -1154,29 +1174,6 @@
120 }
121
122
123-bool JSONObjectNamesIterator::count(
124- store::Item_t& result,
125- PlanState& planState) const
126-{
127- store::Item_t obj;
128- xs_integer count(0);
129-
130- JSONObjectNamesIteratorState* state;
131- DEFAULT_STACK_INIT(JSONObjectNamesIteratorState, state, planState);
132-
133- while (consumeNext(obj, theChild.getp(), planState))
134- {
135- if (obj->isObject())
136- {
137- count += obj->getNumObjectPairs();
138- }
139- }
140-
141- STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, count), state);
142- STACK_END(state);
143-}
144-
145-
146 /*******************************************************************************
147 json:value($o as item(), $name as item()?) as item()?
148
149
150=== modified file 'src/runtime/json/pregenerated/jsoniq_functions.cpp'
151--- src/runtime/json/pregenerated/jsoniq_functions.cpp 2013-06-08 05:33:57 +0000
152+++ src/runtime/json/pregenerated/jsoniq_functions.cpp 2013-06-18 18:57:39 +0000
153@@ -239,14 +239,6 @@
154
155 JSONObjectNamesIteratorState::~JSONObjectNamesIteratorState() {}
156
157-
158-void JSONObjectNamesIteratorState::init(PlanState& planState) {
159- PlanIteratorState::init(planState);
160-}
161-
162-void JSONObjectNamesIteratorState::reset(PlanState& planState) {
163- PlanIteratorState::reset(planState);
164-}
165 // </JSONObjectNamesIterator>
166
167
168
169=== modified file 'src/runtime/json/pregenerated/jsoniq_functions.h'
170--- src/runtime/json/pregenerated/jsoniq_functions.h 2013-06-08 05:33:57 +0000
171+++ src/runtime/json/pregenerated/jsoniq_functions.h 2013-06-18 18:57:39 +0000
172@@ -31,6 +31,8 @@
173 #include "runtime/base/narybase.h"
174 #include <context/uri_resolver.h>
175 #include "runtime/json/json_loader.h"
176+#include "zorbautils/hashset.h"
177+#include "zorbautils/hashmap_zstring.h"
178
179
180 namespace zorba {
181@@ -286,6 +288,7 @@
182 {
183 public:
184 store::Iterator_t theNames; //
185+ std::auto_ptr<HashSet<zstring, HashMapZStringCmp> > theNamesSet; //
186
187 JSONObjectNamesIteratorState();
188
189@@ -315,8 +318,6 @@
190
191 virtual ~JSONObjectNamesIterator();
192
193-public:
194- bool count(store::Item_t& result, PlanState& planState) const;
195 void accept(PlanIterVisitor& v) const;
196
197 bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;
198
199=== modified file 'src/runtime/sequences/sequences_impl.cpp'
200--- src/runtime/sequences/sequences_impl.cpp 2013-06-15 23:20:00 +0000
201+++ src/runtime/sequences/sequences_impl.cpp 2013-06-18 18:57:39 +0000
202@@ -268,7 +268,7 @@
203 {
204 PlanIteratorState::reset(planState);
205 theHasNaN = false;
206- if (theAlreadySeenMap.get () != NULL)
207+ if (theAlreadySeenMap.get() != NULL)
208 theAlreadySeenMap->clear();
209 }
210
211
212=== modified file 'src/runtime/spec/json/jsoniq_functions.xml'
213--- src/runtime/spec/json/jsoniq_functions.xml 2013-06-08 05:33:57 +0000
214+++ src/runtime/spec/json/jsoniq_functions.xml 2013-06-18 18:57:39 +0000
215@@ -12,6 +12,8 @@
216 <zorba:header>
217 <zorba:include form="Angle-bracket">context/uri_resolver.h</zorba:include>
218 <zorba:include form="Quoted">runtime/json/json_loader.h</zorba:include>
219+ <zorba:include form="Quoted">zorbautils/hashset.h</zorba:include>
220+ <zorba:include form="Quoted">zorbautils/hashmap_zstring.h</zorba:include>
221 </zorba:header>
222
223 <!--
224@@ -256,7 +258,7 @@
225 </zorba:function>
226
227 <zorba:state>
228- <zorba:member type="store::Iterator_t" name="theIterator" brief=""/>
229+ <zorba:member type="store::Iterator_t" name="theIterator"/>
230 </zorba:state>
231
232 </zorba:iterator>
233@@ -285,15 +287,14 @@
234
235 </zorba:function>
236
237- <zorba:state>
238- <zorba:member type="store::Iterator_t" name="theNames" brief=""/>
239+ <zorba:state generateInit="false" generateReset="false">
240+
241+ <zorba:member type="store::Iterator_t" name="theNames"/>
242+
243+ <zorba:member type="std::auto_ptr&lt;HashSet&lt;zstring, HashMapZStringCmp> >"
244+ name="theNamesSet"/>
245 </zorba:state>
246
247- <zorba:method name="count" const="true" return="bool">
248- <zorba:param name="result" type="store::Item_t&amp;"/>
249- <zorba:param name="planState" type="PlanState&amp;"/>
250- </zorba:method>
251-
252 </zorba:iterator>
253
254
255
256=== added file 'test/rbkt/ExpQueryResults/zorba/jsoniq/keys_05.xml.res'
257--- test/rbkt/ExpQueryResults/zorba/jsoniq/keys_05.xml.res 1970-01-01 00:00:00 +0000
258+++ test/rbkt/ExpQueryResults/zorba/jsoniq/keys_05.xml.res 2013-06-18 18:57:39 +0000
259@@ -0,0 +1,1 @@
260+foo1 foo2
261
262=== added file 'test/rbkt/Queries/zorba/jsoniq/keys_05.xq'
263--- test/rbkt/Queries/zorba/jsoniq/keys_05.xq 1970-01-01 00:00:00 +0000
264+++ test/rbkt/Queries/zorba/jsoniq/keys_05.xq 2013-06-18 18:57:39 +0000
265@@ -0,0 +1,4 @@
266+let $a :=
267+ for $i in 1 to 10
268+ return { if ($i mod 2 eq 0) then "foo2" else "foo1" : "bar" || $i }
269+return jn:keys($a)

Subscribers

People subscribed via source and target branches