-
-
Notifications
You must be signed in to change notification settings - Fork 179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes an issue with mixed types in a subsequence #2196
Fixes an issue with mixed types in a subsequence #2196
Conversation
@adamretter Does this also fix #1960 ? |
src/org/exist/xquery/PathExpr.java
Outdated
@@ -297,7 +297,7 @@ public Sequence eval(Sequence contextSequence, final Item contextItem) throws XP | |||
|
|||
final boolean allowMixedNodesInReturn; | |||
if(prev != null) { | |||
allowMixedNodesInReturn = prev.allowMixedNodesInReturn() | expr.allowMixedNodesInReturn(); | |||
allowMixedNodesInReturn = prev.allowMixedNodesInReturn() /*| expr.allowMixedNodesInReturn()*/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wolfgangmm it is unclear why this line needed to be changed for the test to succeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamretter running the test on my install, above comment was not needed. The test passed without it.
I did not contribute to the code calling allowMixedNodesInReturn
, but I can see some sense in it. It's not vital though. I would thus say, if your test passes without commenting out the test above, we should leave PathExpr
untouched. If it gets in your way though, we need to reconsider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wolfgangmm Sure the contributed test (FunSubSequenceTest#persistentSupsequence_toInMemory()
) is fine either way.
But... due to my override of Function#allowMixedNodesInReturn()
, the existing test XQueryTest#pathOperatorContainingNodesAndNonNodes()
fails without the rhs of the above boolean test commented out.
Does that make sense now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so the error expected by XQueryTest#pathOperatorContainingNodesAndNonNodes()
is in line with what saxon reports. I wonder why you had to overwrite Function#allowMixedNodesInReturn()
? It does not seem related to the original issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discard the question, I see it. This is quite a puzzle ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the one line I commented on, the PR looks good to me and I would merge it in.
src/org/exist/xquery/PathExpr.java
Outdated
@@ -297,7 +297,7 @@ public Sequence eval(Sequence contextSequence, final Item contextItem) throws XP | |||
|
|||
final boolean allowMixedNodesInReturn; | |||
if(prev != null) { | |||
allowMixedNodesInReturn = prev.allowMixedNodesInReturn() | expr.allowMixedNodesInReturn(); | |||
allowMixedNodesInReturn = prev.allowMixedNodesInReturn() /*| expr.allowMixedNodesInReturn()*/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamretter running the test on my install, above comment was not needed. The test passed without it.
I did not contribute to the code calling allowMixedNodesInReturn
, but I can see some sense in it. It's not vital though. I would thus say, if your test passes without commenting out the test above, we should leave PathExpr
untouched. If it gets in your way though, we need to reconsider.
@juri not intentionally! |
@adamretter wrong person in the mention, I think… |
moi @juri 👋 |
@line-o morjens! |
Are there doubts on the PR ? |
@dizzzz see the comments. I'm still banging my head against this. |
@adamretter ok, after some hours I think I found the correct fix. Please try to change @Override
public int getItemType() {
return sequence.getItemType();
} With this in place you do not need to overwrite |
@wolfgangmm So I don't think that will work for the very common Is there anything wrong with my proposed changes? No tests fail! |
You wanted me to look into this because you had to comment out the check in All in all returning the correct type seems a more correct approach. |
@wolfgangmm Okay, I had no idea I added that check. I guess I did so to fix some broken test. Regards |
See #1133, which introduced the changes in question to |
If the sequence is indeed mixed, it is correct to return |
@wolfgangmm I just spotted a problem with your suggestion to change When given code like: let $seq := (<a/>, <b/>, 3, 4)
return
subsequece($seq, 1, 2) Your change would mean that we return We cannot infer the type from the subequence without actually iterating all of the items in the subsequence and checking their common super type. We really want to avoid that, as a lazy approach is much more performant and memory kind. Thoughts? |
@adamretter ok, I assumed that due to the lazy approach, the underlying value sequence would only contain elements one and two, which are actually returned. We're only interested in the type of the result of the subsequence call, which would be So even if you have to iterate, you do not need to continue beyond item 2, which means the performance impact should be small? |
heh. Sure that works for a small subsequence, but what about a sequence of I guess I am trying to figure out if we have to take determine the type as you are suggesting, or if you think that the fix I proposed previously has a problem? |
In this case you only need to determine the type of the first 999, so there's no performance loss, right?
The whole issue was that using However, I think having correct type information returned by expressions where possible is always preferable to not having the information. |
I guess what I'm thinking is: if there is an easy and fast way to determine the type of the result of subsequence, we should rather go for it instead of having to modify the superclass But if it means a performance loss, I'm rather for speed. So if you tell me it's not possible without loss, I will merge the current PR. |
…ypes in a subsequence as suggested by @wolfgangmm, see eXist-db#2196 (comment)
…ypes in a subsequence as suggested by @wolfgangmm, see eXist-db#2196 (comment)
…ypes in a subsequence as suggested by @wolfgangmm, see eXist-db#2196 (comment)
@wolfgangmm I have committed the change you suggested. It looks good. Thank you :-) |
Closes #2195