[
https://issues.apache.org/jira/browse/OAK-7131?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16327001#comment-16327001
]
Thomas Mueller commented on OAK-7131:
-------------------------------------
Possible patch (to be tested). I think query options are affected as well
(needs more tests):
{noformat}
Index:
oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/Statement.java
===================================================================
--- oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/Statement.java
(revision 1817341)
+++ oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/Statement.java
(working copy)
@@ -301,7 +301,13 @@
// no change
return this;
}
- return new UnionStatement(s1b, s2b);
+ UnionStatement union = new UnionStatement(s1b, s2b);
+ union.explain = explain;
+ union.measure = measure;
+ union.orderList = orderList;
+ union.queryOptions = queryOptions;
+ union.xpathQuery = xpathQuery;
+ return union;
}
@Override
Index:
oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java
===================================================================
---
oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java
(revision 1817341)
+++
oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java
(working copy)
@@ -1150,6 +1150,7 @@
Statement result = null;
ArrayList<Order> orderList = null;
QueryOptions queryOptions = null;
+ String xpathQuery = null;
for(String p : parts) {
String q = begin + p + end;
converter = new XPathToSQL2Converter();
@@ -1156,11 +1157,13 @@
Statement stat = converter.convertToStatement(q);
orderList = stat.orderList;
queryOptions = stat.queryOptions;
+ xpathQuery = stat.xpathQuery;
// reset fields that are used in the union,
// but no longer in the individual statements
// (can not use clear, because it is shared)
stat.orderList = new ArrayList<Order>();
stat.queryOptions = null;
+ stat.xpathQuery = null;
if (result == null) {
result = stat;
} else {
@@ -1172,6 +1175,7 @@
result.queryOptions = queryOptions;
result.setExplain(statement.explain);
result.setMeasure(statement.measure);
+ result.xpathQuery = xpathQuery;
return result;
}
Index: oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt
===================================================================
--- oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt
(revision 1817341)
+++ oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt
(working copy)
@@ -26,6 +26,54 @@
# OAK-6792
+xpath2sql /jcr:root/content[@a=1 or @b=2] order by @foo
+select [jcr:path], [jcr:score], *
+ from [nt:base] as a
+ where issamenode(a, '/content')
+ and [a] = 1
+ union select [jcr:path], [jcr:score], *
+ from [nt:base] as a
+ where issamenode(a, '/content')
+ and [b] = 2
+ order by [foo]
+ /* xpath ... */
+
+xpath2sql /jcr:root/(content | dam)[@a=1 or @b=2] order by @foo
+select [jcr:path], [jcr:score], *
+ from [nt:base] as a
+ where issamenode(a, '/content')
+ and [a] = 1
+ union select [jcr:path], [jcr:score], *
+ from [nt:base] as a
+ where issamenode(a, '/content')
+ and [b] = 2
+ union select [jcr:path], [jcr:score], *
+ from [nt:base] as a
+ where issamenode(a, '/dam')
+ and [a] = 1
+ union select [jcr:path], [jcr:score], *
+ from [nt:base] as a
+ where issamenode(a, '/dam')
+ and [b] = 2
+ order by [foo]
+ /* xpath ... */
+
+xpath2sql //(element(*, type1) | element(*, type2))[@a='b' or @c='d'] order by
@foo
+select [jcr:path], [jcr:score], *
+ from [type1] as a
+ where [a] = 'b'
+ union select [jcr:path], [jcr:score], *
+ from [type1] as a
+ where [c] = 'd'
+ union select [jcr:path], [jcr:score], *
+ from [type2] as a
+ where [a] = 'b'
+ union select [jcr:path], [jcr:score], *
+ from [type2] as a
+ where [c] = 'd'
+ order by [foo]
+ /* xpath ... */
+
xpath2sql /jcr:root//*/(rep:facet(jcr:data/jcr:createdBy))
select [jcr:path], [jcr:score], [rep:facet(jcr:data/jcr:createdBy)]
from [nt:base] as a
@@ -45,12 +93,18 @@
explain select [jcr:path], [jcr:score], *
from [acme:Asset] as a
where isdescendantnode(a, '/content/activities')
+ union select [jcr:path], [jcr:score], *
+ from [acme:Asset] as a
+ where isdescendantnode(a, '/content/people')
/* xpath ... */
-
+
xpath2sql explain measure /jcr:root/content/(activities|people)//element(*,
acme:Asset)
explain measure select [jcr:path], [jcr:score], *
from [acme:Asset] as a
where isdescendantnode(a, '/content/activities')
+ union select [jcr:path], [jcr:score], *
+ from [acme:Asset] as a
+ where isdescendantnode(a, '/content/people')
/* xpath ... */
# OAK-937
{noformat}
> xpath to sql2 conversion drops order by clause for some cases
> -------------------------------------------------------------
>
> Key: OAK-7131
> URL: https://issues.apache.org/jira/browse/OAK-7131
> Project: Jackrabbit Oak
> Issue Type: Bug
> Components: query
> Reporter: Vikas Saurabh
> Assignee: Vikas Saurabh
> Priority: Critical
> Fix For: 1.10
>
>
> When xpath has OR-ed primary type and a couple of OR-ed property constraint
> (e.g. \[0]), the converted sql statement doesn't get ordering clause.
> \[0]:
> {noformat}
> //(element(*, type1) | element(*, type2))[@a='b' or @c='d'] order by @foo
> {noformat}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)