Author: thomasm
Date: Wed Apr 26 13:51:55 2017
New Revision: 1792746
URL: http://svn.apache.org/viewvc?rev=1792746&view=rev
Log:
OAK-6116 SQL generated from xpath with 3 or more ORed paths along with order by
clause throws parseException
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/XPathTest.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java?rev=1792746&r1=1792745&r2=1792746&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java
Wed Apr 26 13:51:55 2017
@@ -1113,24 +1113,28 @@ public class XPathToSQL2Converter {
parts.add(or);
String end = partList.substring(parseIndex);
Statement result = null;
+ ArrayList<Order> orderList = null;
+ QueryOptions queryOptions = null;
for(String p : parts) {
String q = begin + p + end;
converter = new XPathToSQL2Converter();
Statement stat = converter.convertToStatement(q);
+ orderList = stat.orderList;
+ queryOptions = stat.queryOptions;
+ // 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 = new QueryOptions();
if (result == null) {
result = stat;
} else {
UnionStatement union = new UnionStatement(result, stat);
- union.orderList = stat.orderList;
- union.queryOptions = stat.queryOptions;
result = union;
}
- // 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 = new QueryOptions();
}
+ result.orderList = orderList;
+ result.queryOptions = queryOptions;
return result;
}
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/XPathTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/XPathTest.java?rev=1792746&r1=1792745&r2=1792746&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/XPathTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/XPathTest.java
Wed Apr 26 13:51:55 2017
@@ -36,6 +36,35 @@ public class XPathTest {
@Test
public void queryOptions() throws ParseException {
+ verify("(/jcr:root/a//* | /jcr:root/b//*) order by @jcr:score",
+ "select [jcr:path], [jcr:score], * " +
+ "from [nt:base] as a " +
+ "where isdescendantnode(a, '/a') " +
+ "/* xpath: /jcr:root/a//* \n" +
+ "order by @jcr:score */ " +
+ "union select [jcr:path], [jcr:score], * " +
+ "from [nt:base] as a " +
+ "where isdescendantnode(a, '/b') " +
+ "/* xpath: /jcr:root/b//* " +
+ "order by @jcr:score */ " +
+ "order by [jcr:score]");
+ verify("(/jcr:root/a//* | /jcr:root/b//* | /jcr:root/c//*) order by
@jcr:score",
+ "select [jcr:path], [jcr:score], * " +
+ "from [nt:base] as a " +
+ "where isdescendantnode(a, '/a') " +
+ "/* xpath: /jcr:root/a//* \n" +
+ "order by @jcr:score */ " +
+ "union select [jcr:path], [jcr:score], * " +
+ "from [nt:base] as a " +
+ "where isdescendantnode(a, '/b') " +
+ "/* xpath: /jcr:root/b//* \n" +
+ "order by @jcr:score */ " +
+ "union select [jcr:path], [jcr:score], * " +
+ "from [nt:base] as a " +
+ "where isdescendantnode(a, '/c') " +
+ "/* xpath: /jcr:root/c//* " +
+ "order by @jcr:score */ " +
+ "order by [jcr:score]");
verify("//(element(*, nt:address))",
"select [jcr:path], [jcr:score], * " +
"from [nt:address] as a " +
@@ -261,7 +290,7 @@ public class XPathTest {
}
static String formatSQL(String sql) {
- sql = sql.replace("\n", " ");
+ sql = sql.replace('\n', ' ');
sql = sql.replaceAll(" from ", "\nfrom ");
sql = sql.replaceAll(" where ", "\nwhere ");
sql = sql.replaceAll(" and ", "\nand ");