jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1376131 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/query/ test/java/org/apache/jackrabbit/oak/query/ test/resources/org/apache/jackrabbit/oak/query/
Date Wed, 22 Aug 2012 16:29:31 GMT
Author: thomasm
Date: Wed Aug 22 16:29:30 2012
New Revision: 1376131

URL: http://svn.apache.org/viewvc?rev=1376131&view=rev
Log:
OAK-262 Query: support pseudo properties like jcr:score() and rep:excerpt()

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java
    jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/sql2.txt
    jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java?rev=1376131&r1=1376130&r2=1376131&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
Wed Aug 22 16:29:30 2012
@@ -133,7 +133,13 @@ public class SQL2Parser {
         }
         Query q = new Query(source, constraint, orderings, columnArray, valueFactory);
         q.setExplain(explain);
-        q.init();
+        try {
+            q.init();
+        } catch (Exception e) {
+            ParseException e2 = new ParseException(query + ": " + e.getMessage(), 0);
+            e2.initCause(e);
+            throw e2;
+        }
         return q;
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java?rev=1376131&r1=1376130&r2=1376131&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java
Wed Aug 22 16:29:30 2012
@@ -430,7 +430,8 @@ public class XPathToSQL2Converter {
         } else if ("fn:name".equals(functionName)) {
             Function f = new Function("name");
             if (!readIf(")")) {
-                f.params.add(parseExpression());
+                // only name(.) and name() are currently supported
+                read(".");
                 read(")");
             }
             return f;
@@ -837,6 +838,9 @@ public class XPathToSQL2Converter {
 
         @Override
         public String toString() {
+            if (name.equals("*")) {
+                return name;
+            }
             return '[' + name + ']';
         }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java?rev=1376131&r1=1376130&r2=1376131&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java
Wed Aug 22 16:29:30 2012
@@ -103,16 +103,22 @@ public class QueryTest extends AbstractQ
                     w.println("xpath2sql " + line);
                     XPathToSQL2Converter c = new XPathToSQL2Converter();
                     String got;
+                    boolean failed;
                     try {
                         got = c.convert(line);
+                        failed = false;
                     } catch (ParseException e) {
                         got = "invalid: " + e.getMessage().replace('\n', ' ');
+                        failed = true;
                     }
                     line = r.readLine().trim();
                     w.println(got);
                     if (!line.equals(got)) {
                         errors = true;
                     }
+                    if (!failed) {
+                        executeQuery(got, QueryEngineImpl.SQL2, null);
+                    }
                 } else if (line.startsWith("select") || line.startsWith("explain") || line.startsWith("sql1"))
{
                     w.println(line);
                     String language = QueryEngineImpl.SQL2;

Modified: jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/sql2.txt
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/sql2.txt?rev=1376131&r1=1376130&r2=1376131&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/sql2.txt
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/sql2.txt
Wed Aug 22 16:29:30 2012
@@ -39,7 +39,7 @@ commit / - "test"
 # expected error on two selectors with the same name
 
 select * from [nt:base] as p inner join [nt:base] as p on ischildnode(p, p) where p.[jcr:path]
= '/'
-java.lang.IllegalArgumentException: Two selectors with the same name: p
+java.text.ParseException: select * from [nt:base] as p inner join [nt:base] as p on ischildnode(p,
p) where p.[jcr:path] = '/': Two selectors with the same name: p
 
 # combining 'not' and 'and'
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt?rev=1376131&r1=1376130&r2=1376131&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt
Wed Aug 22 16:29:30 2012
@@ -25,11 +25,14 @@
 
 # jackrabbit test queries
 
+xpath2sql /jcr:root/testroot/*[jcr:contains(., '"quick brown" -cat')]
+select [jcr:path], [jcr:score], * from [nt:base] where contains(*, '"quick brown" -cat')
and ischildnode('/testroot')
+
 xpath2sql //element(*,rep:Authorizable)[(((jcr:contains(profile/givenName,'**') or jcr:contains(profile/familyName,'**'))
or jcr:contains(profile/email,'**')) or (jcr:like(rep:principalName,'%%') or jcr:like(fn:name(.),'%%')))]
order by rep:principalName ascending
-select [jcr:path], [jcr:score], * from [rep:Authorizable] where ((contains([profile/givenName/*],
'**') or contains([profile/familyName/*], '**')) or contains([profile/email/*], '**')) or
(([rep:principalName/*] like '%%') or (name([*]) like '%%')) order by [rep:principalName/*]
+select [jcr:path], [jcr:score], * from [rep:Authorizable] where ((contains([profile/givenName/*],
'**') or contains([profile/familyName/*], '**')) or contains([profile/email/*], '**')) or
(([rep:principalName/*] like '%%') or (name() like '%%')) order by [rep:principalName/*]
 
 xpath2sql //element(*,rep:Authorizable)[(((jcr:contains(profile/@givenName,'**') or jcr:contains(profile/@familyName,'**'))
or jcr:contains(profile/@email,'**')) or (jcr:like(@rep:principalName,'%%') or jcr:like(fn:name(.),'%%')))]
order by @rep:principalName ascending
-select [jcr:path], [jcr:score], * from [rep:Authorizable] where ((contains([profile/givenName],
'**') or contains([profile/familyName], '**')) or contains([profile/email], '**')) or (([rep:principalName]
like '%%') or (name([*]) like '%%')) order by [rep:principalName]
+select [jcr:path], [jcr:score], * from [rep:Authorizable] where ((contains([profile/givenName],
'**') or contains([profile/familyName], '**')) or contains([profile/email], '**')) or (([rep:principalName]
like '%%') or (name() like '%%')) order by [rep:principalName]
 
 xpath2sql /jcr:root/testroot//*[jcr:contains(@jcr:data, 'lazy')]
 select [jcr:path], [jcr:score], * from [nt:base] where contains([jcr:data], 'lazy') and isdescendantnode('/testroot')
@@ -134,12 +137,6 @@ select [jcr:path], [jcr:score], * from [
 xpath2sql /jcr:root/test/text()
 select [jcr:path], [jcr:score], * from [nt:base] where issamenode('/test/jcr:xmltext')
 
-xpath2sql explain //*[@*='x']
-explain select [jcr:path], [jcr:score], * from [nt:base] where [*] = 'x'
-
-xpath2sql //*[@*='x']
-select [jcr:path], [jcr:score], * from [nt:base] where [*] = 'x'
-
 xpath2sql /jcr:root
 select [jcr:path], [jcr:score], * from [nt:base] where isdescendantnode('/')
 
@@ -162,10 +159,10 @@ xpath2sql /jcr:root/content//*[@name='He
 select [jcr:path], [jcr:score], * from [nt:base] where ([name] = 'Hello') and isdescendantnode('/content')
 
 xpath2sql //*[jcr:contains(., 'test')] order by @jcr:score
-select [jcr:path], [jcr:score], * from [nt:base] where contains([*], 'test') order by [jcr:score]
+select [jcr:path], [jcr:score], * from [nt:base] where contains(*, 'test') order by [jcr:score]
 
 xpath2sql /jcr:root//*[jcr:contains(., 'test')] order by @jcr:score
-select [jcr:path], [jcr:score], * from [nt:base] where contains([*], 'test') and isdescendantnode('/')
order by [jcr:score]
+select [jcr:path], [jcr:score], * from [nt:base] where contains(*, 'test') and isdescendantnode('/')
order by [jcr:score]
 
 xpath2sql /jcr:root//element(*, test)
 select [jcr:path], [jcr:score], * from [test] where isdescendantnode('/')
@@ -248,7 +245,7 @@ xpath2sql //element(*, my:type)[jcr:like
 select [jcr:path], [jcr:score], * from [my:type] where [title] like '%Java%'
 
 xpath2sql //element(*, my:type)[jcr:contains(., 'JSR 170')]
-select [jcr:path], [jcr:score], * from [my:type] where contains([*], 'JSR 170')
+select [jcr:path], [jcr:score], * from [my:type] where contains(*, 'JSR 170')
 
 xpath2sql //element(*, my:type)[@my:title]
 select [jcr:path], [jcr:score], * from [my:type] where [my:title] is not null
@@ -287,7 +284,7 @@ xpath2sql //element(*, my:type) order by
 select [jcr:path], [jcr:score], * from [my:type] order by [my:date] desc, [my:title]
 
 xpath2sql //element(*, my:type)[jcr:contains(., 'jcr')] order by jcr:score() descending
-select [jcr:path], [jcr:score], * from [my:type] where contains([*], 'jcr') order by score()
desc
+select [jcr:path], [jcr:score], * from [my:type] where contains(*, 'jcr') order by score()
desc
 
 xpath2sql //element(*, my:type)[jcr:contains(@my:title, 'jcr')] order by jcr:score() descending
 select [jcr:path], [jcr:score], * from [my:type] where contains([my:title], 'jcr') order
by score() desc



Mime
View raw message