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

Proposed by Juan Zacarias
Status: Merged
Approved by: Till Westmann
Approved revision: 11355
Merged at revision: 11403
Proposed branch: lp:~zorba-coders/zorba/bug1082740_fn_subsequence
Merge into: lp:zorba
Diff against target: 125 lines (+31/-12)
6 files modified
ChangeLog (+1/-0)
src/runtime/sequences/sequences_impl.cpp (+27/-8)
src/runtime/spec/sequences/sequences.xml (+1/-0)
test/fots/CMakeLists.txt (+0/-4)
test/rbkt/ExpQueryResults/zorba/sequences/subsequence.xml.res (+1/-0)
test/rbkt/Queries/zorba/sequences/subsequence.xq (+1/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug1082740_fn_subsequence
Reviewer Review Type Date Requested Status
Till Westmann Approve
Chris Hillery Approve
Review via email: mp+157755@code.launchpad.net

Commit message

Added support for INF and -INF values in fn:subsequence function.

Description of the change

Added support for INF and -INF values in fn:subsequence function.

To post a comment you must log in.
Revision history for this message
Till Westmann (tillw) wrote :

Looks good, but I think that it would be nice to factor out the (virtual) calls to getDoubleValue().
Not sure if that's measurable, but I don't think that it hurts to give the compiler a hint :)

review: Needs Fixing
Revision history for this message
Chris Hillery (ceejatec) wrote :

Other than Till's comment, I approve. I'm still a bit wary about having to add a new flag and test logic to fn:subsequence(), since that's used a lot, so if you happen to think of a way to do this without such checks that would be ideal. But, if this flag is necessary, then so be it.

review: Approve
Revision history for this message
Chris Hillery (ceejatec) wrote :

Oh, actually, two quick things:

1. Add a test case that would have failed before and succeeds now
2. Add a note about the fixed bug to the Changelog.

review: Needs Fixing
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/bug1082740_fn_subsequence into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job bug1082740_fn_subsequence-2013-04-10T00-23-52.125Z is
  finished. The final status was:

  1 tests did not succeed - changes not commited.

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

Revision history for this message
Till Westmann (tillw) wrote :

Also it seems that the expected failures in the FOTS need to be updated.

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/bug1082740_fn_subsequence into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job bug1082740_fn_subsequence-2013-04-15T16-55-56.486Z is
  finished. The final status was:

  1 tests did not succeed - changes not commited.

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

Revision history for this message
Juan Zacarias (juan457) wrote :

Hi regarding the issue of not using the flag for INF values.

The thing is the following whenever you ask for the value of a INF or -INF number you will get the highest positive or negative number available 9223372036854775807 or -9223372036854775807 being the case for 32 bits.

So I though of using the flags to avoid unnecessary processing whenever a INF value is present. It will add 5 checks for INF values to the code that's 4 ifs that would be present in every call of the subsequence and 1 more if the length is INF each of them being done only once. A way to avoid this flags we could use the value equivalents of the INF, but even though we will need to add 2 flag checks since there is actually a bug with the implementation and whenever there is an INF in the start position (we will be moving along the whole sequence with no need since it should return an empty sequence.) other problem would be present if the length is set to INF since if we manage a numeric value for the INF it would be doing a decreasing value operation and an extra check in the while statement.

That's why I thought of using the extra flags since besides we do 3 more flag checks we do them only once during the whole operation of subsequence and doesn't do unnecessary operations for INF values.

Let me know your opinion.

Revision history for this message
Juan Zacarias (juan457) wrote :

I made some modifications and the current solution uses 1 less check which will make it 3 and 4 and the numeric solution would have 0 extra flag checks but it still has the problem that with INF values it will do extra operations.

Revision history for this message
Juan Zacarias (juan457) wrote :

I apologize I made a mistake the numeric Value for INF and -INF is the same -9223372036854775808 (0x8000000000000000) which would make solving this issue with flags more complex than what I described.

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/bug1082740_fn_subsequence into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job bug1082740_fn_subsequence-2013-04-15T21-01-08.051Z is
  finished. The final status was:

  1 tests did not succeed - changes not commited.

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

Revision history for this message
Chris Hillery (ceejatec) wrote :

I agree with your logic, Juan; thanks for spelling it out. I hadn't realized that your new flag were not checked in the inner loop of fn:subsequence(), but looking at the implementation it appears that is the case. So I have no problem with it.

Voting Approve now, although clearly the two failing FOTS tests will need to be addressed before it will merge.

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 bug1082740_fn_subsequence-2013-04-18T17-05-54.809Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1, Needs Information < 1, Resubmit < 1. Got: 1 Approve, 1 Needs Fixing.

Revision history for this message
Till Westmann (tillw) :
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 bug1082740_fn_subsequence-2013-04-24T06-13-54.41Z 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 'ChangeLog'
2--- ChangeLog 2013-04-17 16:30:00 +0000
3+++ ChangeLog 2013-04-18 16:34:29 +0000
4@@ -91,6 +91,7 @@
5 * Raise XQST0046, if needed, from namespace declaration attribute inside
6 direct element constructor.
7 * Fixed bug #1023362 (xsi:type attribute ignored during validation)
8+ * Fixed bug #1082740 (support for INF and -INF values in fn:subsequence function).
9
10
11 version 2.8
12
13=== modified file 'src/runtime/sequences/sequences_impl.cpp'
14--- src/runtime/sequences/sequences_impl.cpp 2013-04-11 23:37:12 +0000
15+++ src/runtime/sequences/sequences_impl.cpp 2013-04-18 16:34:29 +0000
16@@ -473,27 +473,46 @@
17 store::Item_t startPosItem;
18 xs_long startPos;
19 store::Item_t lengthItem;
20+ xs_double startPosDouble;
21+ xs_double lengthDouble;
22
23 FnSubsequenceIteratorState* state;
24 DEFAULT_STACK_INIT(FnSubsequenceIteratorState, state, planState);
25
26 state->theIsChildReset = false;
27-
28+
29 CONSUME(startPosItem, 1);
30+ startPosDouble = startPosItem->getDoubleValue();
31+
32+ //If starting position is set to +INF return empty sequence
33+ if (startPosDouble.isPosInf() || startPosDouble.isNaN())
34+ goto done;
35+
36+ //Removed startpos - 1, since if a -INF is present it overflows it to a positive number
37 startPos =
38- static_cast<xs_long>(startPosItem->getDoubleValue().round().getNumber()) - 1;
39+ static_cast<xs_long>(startPosDouble.round().getNumber());
40
41 if (theChildren.size() == 3)
42 {
43 CONSUME(lengthItem, 2);
44- state->theRemaining =
45- static_cast<xs_long>(lengthItem->getDoubleValue().round().getNumber());
46+ lengthDouble = lengthItem->getDoubleValue();
47+ if (lengthDouble.isPosInf())
48+ {
49+ //if startPos is -INF and length is +INF return empty sequence because -INF + INF = NaN
50+ if (startPosDouble.isNegInf())
51+ goto done;
52+
53+ state->theRemaining = 1;
54+ }
55+ else
56+ state->theRemaining =
57+ static_cast<xs_long>(lengthDouble.round().getNumber());
58 }
59
60- if (startPos < 0)
61+ if (startPos < 1)
62 {
63 if (theChildren.size() >= 3)
64- state->theRemaining += startPos;
65+ state->theRemaining += startPos - 1;
66
67 startPos = 0;
68 }
69@@ -503,13 +522,13 @@
70 goto done;
71
72 // Consume and skip all input items that are before the startPos
73- for (; startPos > 0; --startPos)
74+ for (; startPos > 1; --startPos)
75 {
76 if (!CONSUME(result, 0))
77 goto done;
78 }
79
80- if (theChildren.size() < 3)
81+ if (theChildren.size() < 3 || lengthDouble.isPosInf())
82 {
83 while (CONSUME(result, 0))
84 {
85
86=== modified file 'src/runtime/spec/sequences/sequences.xml'
87--- src/runtime/spec/sequences/sequences.xml 2013-03-20 01:19:04 +0000
88+++ src/runtime/spec/sequences/sequences.xml 2013-04-18 16:34:29 +0000
89@@ -421,6 +421,7 @@
90 <zorba:member type="xs_long" name="theRemaining"
91 defaultValue="0" brief=""/>
92 <zorba:member type="bool" name="theIsChildReset" defaultValue="false"/>
93+
94
95 </zorba:state>
96
97
98=== modified file 'test/fots/CMakeLists.txt'
99--- test/fots/CMakeLists.txt 2013-04-18 14:41:27 +0000
100+++ test/fots/CMakeLists.txt 2013-04-18 16:34:29 +0000
101@@ -226,10 +226,6 @@
102 EXPECTED_FOTS_FAILURE (fn-serialize serialize-xml-008 0)
103 EXPECTED_FOTS_FAILURE (fn-string-length fn-string-length-22 0)
104 EXPECTED_FOTS_FAILURE (fn-string-length fn-string-length-24 0)
105-EXPECTED_FOTS_FAILURE (fn-subsequence cbcl-subsequence-004 0)
106-EXPECTED_FOTS_FAILURE (fn-subsequence cbcl-subsequence-017 0)
107-EXPECTED_FOTS_FAILURE (fn-subsequence cbcl-subsequence-018 0)
108-EXPECTED_FOTS_FAILURE (fn-subsequence cbcl-subsequence-024 0)
109 EXPECTED_FOTS_FAILURE (fn-tokenize fn-tokenize-31 0)
110 EXPECTED_FOTS_FAILURE (fn-tokenize fn-tokenize-32 0)
111 EXPECTED_FOTS_FAILURE (fn-unparsed-text fn-unparsed-text-037 0)
112
113=== added file 'test/rbkt/ExpQueryResults/zorba/sequences/subsequence.xml.res'
114--- test/rbkt/ExpQueryResults/zorba/sequences/subsequence.xml.res 1970-01-01 00:00:00 +0000
115+++ test/rbkt/ExpQueryResults/zorba/sequences/subsequence.xml.res 2013-04-18 16:34:29 +0000
116@@ -0,0 +1,1 @@
117+1 2
118\ No newline at end of file
119
120=== added file 'test/rbkt/Queries/zorba/sequences/subsequence.xq'
121--- test/rbkt/Queries/zorba/sequences/subsequence.xq 1970-01-01 00:00:00 +0000
122+++ test/rbkt/Queries/zorba/sequences/subsequence.xq 2013-04-18 16:34:29 +0000
123@@ -0,0 +1,1 @@
124+fn:subsequence(for $x in 1 to 2 return $x, 1.1, xs:double('INF'))
125\ No newline at end of file

Subscribers

People subscribed via source and target branches