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
=== modified file 'modules/ExternalModules.conf'
--- modules/ExternalModules.conf 2013-06-18 11:03:29 +0000
+++ modules/ExternalModules.conf 2013-06-18 18:57:39 +0000
@@ -52,4 +52,4 @@
52stack bzr lp:zorba/stack-module zorba-2.952stack bzr lp:zorba/stack-module zorba-2.9
53queue bzr lp:zorba/queue-module zorba-2.953queue bzr lp:zorba/queue-module zorba-2.9
54couchbase bzr lp:zorba/couchbase-module54couchbase bzr lp:zorba/couchbase-module
55#sqlite bzr lp:zorba/sqlite-module55sqlite bzr lp:zorba/sqlite-module
5656
=== modified file 'modules/org/jsoniq/www/functions.xq'
--- modules/org/jsoniq/www/functions.xq 2013-06-15 02:57:08 +0000
+++ modules/org/jsoniq/www/functions.xq 2013-06-18 18:57:39 +0000
@@ -184,11 +184,13 @@
184184
185185
186(:~186(:~
187 : Returns the names used in the object. 187 : Returns the set of keys belonging to the objects found inside a given
188 : The names will be returned in an implementation-defined order188 : sequence of items. The keys are returned in an implementation-defined
189 : order. Duplicate keys are eliminated.
189 :190 :
190 : @param $o A JSON Object.191 : @param $o A sequence of items. Only object items are actually processed;
191 : @return The names of pairs in the object.192 : items of any other kind are simply skipped.
193 : @return The distinct keys of the objects in the input sequence.
192 :)194 :)
193declare function jn:keys($o as item()*) as xs:string* external;195declare function jn:keys($o as item()*) as xs:string* external;
194196
@@ -235,17 +237,19 @@
235 : @param $p The position in the array.237 : @param $p The position in the array.
236 : @return The member at the specified position, or empty sequence.238 : @return The member at the specified position, or empty sequence.
237 :)239 :)
238(: obsolete - use $a($p) instead :)240(: obsolete - use $a($p) or $a[[$p]] instead :)
239declare function jn:member($a as item(), $p as item()?) as item()? external;241declare function jn:member($a as item(), $p as item()?) as item()? external;
240242
241243
242(:~244(:~
243 : Returns the members of an Array.245 : Returns the items belonging to the arrays found inside a given sequence
246 : of items. The items are returned in an implementation-defined order.
244 :247 :
245 : @param $a A JSON Array.248 : @param $a A sequence of items. Only array items are actually processed;
246 : @return The members of the specified array.249 : items of any other kind are simply skipped.
250 : @return The members of the arrays in the input sequence.
247 :)251 :)
248declare function jn:members($o as item()*) as item()* external;252declare function jn:members($a as item()*) as item()* external;
249253
250254
251(:~255(:~
252256
=== modified file 'src/runtime/json/jsoniq_functions_impl.cpp'
--- src/runtime/json/jsoniq_functions_impl.cpp 2013-06-15 02:57:08 +0000
+++ src/runtime/json/jsoniq_functions_impl.cpp 2013-06-18 18:57:39 +0000
@@ -48,11 +48,11 @@
4848
49#include <runtime/util/doc_uri_heuristics.h>49#include <runtime/util/doc_uri_heuristics.h>
5050
51#include <store/api/pul.h>51#include "store/api/pul.h"
52#include <store/api/item.h>52#include "store/api/item.h"
53#include <store/api/item_factory.h>53#include "store/api/item_factory.h"
54#include <store/api/store.h>54#include "store/api/store.h"
55#include <store/api/copymode.h>55#include "store/api/copymode.h"
5656
57#include "util/uri_util.h"57#include "util/uri_util.h"
58#include "util/stream_util.h"58#include "util/stream_util.h"
@@ -1126,11 +1126,26 @@
1126/*******************************************************************************1126/*******************************************************************************
1127 jn:names($o as item()*) as xs:string*1127 jn:names($o as item()*) as xs:string*
1128********************************************************************************/1128********************************************************************************/
1129
1130void JSONObjectNamesIteratorState::init(PlanState& planState)
1131{
1132 theNamesSet.reset(new HashSet<zstring, HashMapZStringCmp>(64, false));
1133}
1134
1135
1136void JSONObjectNamesIteratorState::reset(PlanState& planState)
1137{
1138 PlanIteratorState::reset(planState);
1139 theNamesSet->clear();
1140}
1141
1142
1129bool JSONObjectNamesIterator::nextImpl(1143bool JSONObjectNamesIterator::nextImpl(
1130 store::Item_t& result,1144 store::Item_t& result,
1131 PlanState& planState) const1145 PlanState& planState) const
1132{1146{
1133 store::Item_t input;1147 store::Item_t input;
1148 zstring name;
11341149
1135 JSONObjectNamesIteratorState* state;1150 JSONObjectNamesIteratorState* state;
1136 DEFAULT_STACK_INIT(JSONObjectNamesIteratorState, state, planState);1151 DEFAULT_STACK_INIT(JSONObjectNamesIteratorState, state, planState);
@@ -1144,7 +1159,12 @@
11441159
1145 while (state->theNames->next(result))1160 while (state->theNames->next(result))
1146 {1161 {
1147 STACK_PUSH (true, state);1162 name = result->getStringValue();
1163 if (!state->theNamesSet->exists(name))
1164 {
1165 state->theNamesSet->insert(name);
1166 STACK_PUSH(true, state);
1167 }
1148 }1168 }
1149 state->theNames = NULL;1169 state->theNames = NULL;
1150 }1170 }
@@ -1154,29 +1174,6 @@
1154}1174}
11551175
11561176
1157bool JSONObjectNamesIterator::count(
1158 store::Item_t& result,
1159 PlanState& planState) const
1160{
1161 store::Item_t obj;
1162 xs_integer count(0);
1163
1164 JSONObjectNamesIteratorState* state;
1165 DEFAULT_STACK_INIT(JSONObjectNamesIteratorState, state, planState);
1166
1167 while (consumeNext(obj, theChild.getp(), planState))
1168 {
1169 if (obj->isObject())
1170 {
1171 count += obj->getNumObjectPairs();
1172 }
1173 }
1174
1175 STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, count), state);
1176 STACK_END(state);
1177}
1178
1179
1180/*******************************************************************************1177/*******************************************************************************
1181 json:value($o as item(), $name as item()?) as item()?1178 json:value($o as item(), $name as item()?) as item()?
11821179
11831180
=== modified file 'src/runtime/json/pregenerated/jsoniq_functions.cpp'
--- src/runtime/json/pregenerated/jsoniq_functions.cpp 2013-06-08 05:33:57 +0000
+++ src/runtime/json/pregenerated/jsoniq_functions.cpp 2013-06-18 18:57:39 +0000
@@ -239,14 +239,6 @@
239239
240JSONObjectNamesIteratorState::~JSONObjectNamesIteratorState() {}240JSONObjectNamesIteratorState::~JSONObjectNamesIteratorState() {}
241241
242
243void JSONObjectNamesIteratorState::init(PlanState& planState) {
244 PlanIteratorState::init(planState);
245}
246
247void JSONObjectNamesIteratorState::reset(PlanState& planState) {
248 PlanIteratorState::reset(planState);
249}
250// </JSONObjectNamesIterator>242// </JSONObjectNamesIterator>
251243
252244
253245
=== modified file 'src/runtime/json/pregenerated/jsoniq_functions.h'
--- src/runtime/json/pregenerated/jsoniq_functions.h 2013-06-08 05:33:57 +0000
+++ src/runtime/json/pregenerated/jsoniq_functions.h 2013-06-18 18:57:39 +0000
@@ -31,6 +31,8 @@
31#include "runtime/base/narybase.h"31#include "runtime/base/narybase.h"
32#include <context/uri_resolver.h>32#include <context/uri_resolver.h>
33#include "runtime/json/json_loader.h"33#include "runtime/json/json_loader.h"
34#include "zorbautils/hashset.h"
35#include "zorbautils/hashmap_zstring.h"
3436
3537
36namespace zorba {38namespace zorba {
@@ -286,6 +288,7 @@
286{288{
287public:289public:
288 store::Iterator_t theNames; //290 store::Iterator_t theNames; //
291 std::auto_ptr<HashSet<zstring, HashMapZStringCmp> > theNamesSet; //
289292
290 JSONObjectNamesIteratorState();293 JSONObjectNamesIteratorState();
291294
@@ -315,8 +318,6 @@
315318
316 virtual ~JSONObjectNamesIterator();319 virtual ~JSONObjectNamesIterator();
317320
318public:
319 bool count(store::Item_t& result, PlanState& planState) const;
320 void accept(PlanIterVisitor& v) const;321 void accept(PlanIterVisitor& v) const;
321322
322 bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;323 bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;
323324
=== modified file 'src/runtime/sequences/sequences_impl.cpp'
--- src/runtime/sequences/sequences_impl.cpp 2013-06-15 23:20:00 +0000
+++ src/runtime/sequences/sequences_impl.cpp 2013-06-18 18:57:39 +0000
@@ -268,7 +268,7 @@
268{268{
269 PlanIteratorState::reset(planState);269 PlanIteratorState::reset(planState);
270 theHasNaN = false;270 theHasNaN = false;
271 if (theAlreadySeenMap.get () != NULL)271 if (theAlreadySeenMap.get() != NULL)
272 theAlreadySeenMap->clear();272 theAlreadySeenMap->clear();
273}273}
274274
275275
=== modified file 'src/runtime/spec/json/jsoniq_functions.xml'
--- src/runtime/spec/json/jsoniq_functions.xml 2013-06-08 05:33:57 +0000
+++ src/runtime/spec/json/jsoniq_functions.xml 2013-06-18 18:57:39 +0000
@@ -12,6 +12,8 @@
12<zorba:header>12<zorba:header>
13 <zorba:include form="Angle-bracket">context/uri_resolver.h</zorba:include>13 <zorba:include form="Angle-bracket">context/uri_resolver.h</zorba:include>
14 <zorba:include form="Quoted">runtime/json/json_loader.h</zorba:include>14 <zorba:include form="Quoted">runtime/json/json_loader.h</zorba:include>
15 <zorba:include form="Quoted">zorbautils/hashset.h</zorba:include>
16 <zorba:include form="Quoted">zorbautils/hashmap_zstring.h</zorba:include>
15</zorba:header>17</zorba:header>
16 18
17<!--19<!--
@@ -256,7 +258,7 @@
256 </zorba:function>258 </zorba:function>
257259
258 <zorba:state>260 <zorba:state>
259 <zorba:member type="store::Iterator_t" name="theIterator" brief=""/>261 <zorba:member type="store::Iterator_t" name="theIterator"/>
260 </zorba:state>262 </zorba:state>
261263
262</zorba:iterator>264</zorba:iterator>
@@ -285,15 +287,14 @@
285287
286 </zorba:function>288 </zorba:function>
287289
288 <zorba:state>290 <zorba:state generateInit="false" generateReset="false">
289 <zorba:member type="store::Iterator_t" name="theNames" brief=""/>291
292 <zorba:member type="store::Iterator_t" name="theNames"/>
293
294 <zorba:member type="std::auto_ptr&lt;HashSet&lt;zstring, HashMapZStringCmp> >"
295 name="theNamesSet"/>
290 </zorba:state>296 </zorba:state>
291297
292 <zorba:method name="count" const="true" return="bool">
293 <zorba:param name="result" type="store::Item_t&amp;"/>
294 <zorba:param name="planState" type="PlanState&amp;"/>
295 </zorba:method>
296
297</zorba:iterator>298</zorba:iterator>
298299
299300
300301
=== added file 'test/rbkt/ExpQueryResults/zorba/jsoniq/keys_05.xml.res'
--- test/rbkt/ExpQueryResults/zorba/jsoniq/keys_05.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/jsoniq/keys_05.xml.res 2013-06-18 18:57:39 +0000
@@ -0,0 +1,1 @@
1foo1 foo2
02
=== added file 'test/rbkt/Queries/zorba/jsoniq/keys_05.xq'
--- test/rbkt/Queries/zorba/jsoniq/keys_05.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/jsoniq/keys_05.xq 2013-06-18 18:57:39 +0000
@@ -0,0 +1,4 @@
1let $a :=
2 for $i in 1 to 10
3 return { if ($i mod 2 eq 0) then "foo2" else "foo1" : "bar" || $i }
4return jn:keys($a)

Subscribers

People subscribed via source and target branches