You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by th...@apache.org on 2012/08/07 16:58:32 UTC

svn commit: r1370294 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt

Author: thomasm
Date: Tue Aug  7 14:58:32 2012
New Revision: 1370294

URL: http://svn.apache.org/viewvc?rev=1370294&view=rev
Log:
OAK-225 Sling I18N queries not supported by Oak (partial fix)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java
    jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt

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=1370294&r1=1370293&r2=1370294&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 Tue Aug  7 14:58:32 2012
@@ -381,10 +381,20 @@ public class XPathToSQL2Converter {
             Cast c = new Cast(expr, "date");
             read(")");
             return c;
+        } else if ("fn:lower-case".equals(functionName)) {
+            Function f = new Function("lower");
+            f.params.add(parseExpression());
+            read(")");
+            return f;
+        } else if ("fn:upper-case".equals(functionName)) {
+            Function f = new Function("upper");
+            f.params.add(parseExpression());
+            read(")");
+            return f;
         // } else if ("jcr:deref".equals(functionName)) {
             // TODO support jcr:deref?
         } else {
-            throw getSyntaxError("jcr:like | jcr:contains | jcr:score | jcr:deref");
+            throw getSyntaxError("jcr:like | jcr:contains | jcr:score | jcr:deref | fn:lower-case | fn:upper-case");
         }
     }
 
@@ -537,7 +547,9 @@ public class XPathToSQL2Converter {
         case CHAR_NAME:
             while (true) {
                 type = types[i];
-                if (type != CHAR_NAME && type != CHAR_VALUE) {
+                // the '-' can be part of a name, 
+                // for example in "fn:lower-case"
+                if (type != CHAR_NAME && type != CHAR_VALUE && chars[i] != '-') {
                     c = chars[i];
                     break;
                 }

Modified: jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt?rev=1370294&r1=1370293&r2=1370294&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt Tue Aug  7 14:58:32 2012
@@ -18,6 +18,14 @@
 # * lines starting with "xpath" are xpath queries, followed by expected sql2 query
 # * use ascii character only
 
+# sling queries
+
+xpath //element(*,mix:language)[fn:lower-case(@jcr:language)='en']//element(*,sling:Message)[@sling:message]/(@sling:key|@sling:message)
+select [jcr:path], [jcr:score], [sling:key], [sling:message] from [sling:Message] where (lower([jcr:language]) = 'en') and ([sling:message] is not null)
+
+xpath //element(*,mix:language)[fn:upper-case(@jcr:language)='en']//element(*,sling:Message)[@sling:message]/(@sling:key|@sling:message)
+select [jcr:path], [jcr:score], [sling:key], [sling:message] from [sling:Message] where (upper([jcr:language]) = 'en') and ([sling:message] is not null)
+
 # jboss example queries
 
 xpath //*
@@ -229,7 +237,7 @@ xpath //element(*, my:type)[@my:value = 
 invalid: Query: //element(*, my:type)[@my:value = [(*)'x']; expected: @, true, false, -, +
 
 xpath //element(*, my:type)[jcr:strike(@title,'%Java%')]
-invalid: Query: //element(*, my:type)[jcr:strike(@(*)title,'%Java%')]; expected: jcr:like | jcr:contains | jcr:score | jcr:deref
+invalid: Query: //element(*, my:type)[jcr:strike(@(*)title,'%Java%')]; expected: jcr:like | jcr:contains | jcr:score | jcr:deref | fn:lower-case | fn:upper-case
 
 xpath //element(*, my:type)[
 invalid: Query: //element(*, my:type)(*)[; expected: not, (, @, true, false, -, +



Re: svn commit: r1370294 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt

Posted by Alex Parvulescu <al...@gmail.com>.
hi,

I've now seen the comment on  OAK-225 :)

we can continue the discussion there.

alex


On Wed, Aug 8, 2012 at 12:10 PM, Alex Parvulescu
<al...@gmail.com>wrote:

> Hi,
>
> I'm not sure the query translation for the following query is done
> properly:
>
>
> //element(*,mix:language)[fn:lower-case(@jcr:language)='en']//element(*,sling:Message)[@sling:message]/(@sling:key|@sling:message)
> as
>   select [jcr:path], [jcr:score], [sling:key], [sling:message] from
> [sling:Message] where (lower([jcr:language]) = 'en') and ([sling:message]
> is not null)
>
> The two, as far as I understand it, as not equal.
>
> The jcr:language property is on the mix:language node, not on the
> sling:Message one.
>
> This is how the node structure looks like:
>
> i18n
>     /de (jcr:mixinTypes = 'mix:language'; jcr:language = 'de')
>         /Advanced (jcr:mixinTypes = 'sling:Message'; sling:key = 'Advanced
> ((Title))'; sling:message = 'Erweitert' )
>         /Clear (jcr:mixinTypes = 'sling:Message'; sling:key = 'Clear
> ((Clear property action))'; sling:message = 'Löschen')
>
>     /fr (jcr:mixinTypes = 'mix:language'; jcr:language = 'fr')
>         /Advanced (jcr:mixinTypes = 'sling:Message'; sling:key = 'Advanced
> ((Title))'; sling:message = 'Avancé' )
>         /Clear (jcr:mixinTypes = 'sling:Message'; sling:key = 'Clear
> ((Clear property action))'; sling:message = 'Effacer')
>
> So if you want to maintain backwards compatibility I think this would look
> better as a join, but feel free to correct me if I'm wrong.
>
> best,
> alex
>
>
> On Tue, Aug 7, 2012 at 4:58 PM, <th...@apache.org> wrote:
>
>> Author: thomasm
>> Date: Tue Aug  7 14:58:32 2012
>> New Revision: 1370294
>>
>> URL: http://svn.apache.org/viewvc?rev=1370294&view=rev
>> Log:
>> OAK-225 Sling I18N queries not supported by Oak (partial fix)
>>
>> Modified:
>>
>> jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java
>>
>> jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt
>>
>> 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=1370294&r1=1370293&r2=1370294&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
>> Tue Aug  7 14:58:32 2012
>> @@ -381,10 +381,20 @@ public class XPathToSQL2Converter {
>>              Cast c = new Cast(expr, "date");
>>              read(")");
>>              return c;
>> +        } else if ("fn:lower-case".equals(functionName)) {
>> +            Function f = new Function("lower");
>> +            f.params.add(parseExpression());
>> +            read(")");
>> +            return f;
>> +        } else if ("fn:upper-case".equals(functionName)) {
>> +            Function f = new Function("upper");
>> +            f.params.add(parseExpression());
>> +            read(")");
>> +            return f;
>>          // } else if ("jcr:deref".equals(functionName)) {
>>              // TODO support jcr:deref?
>>          } else {
>> -            throw getSyntaxError("jcr:like | jcr:contains | jcr:score |
>> jcr:deref");
>> +            throw getSyntaxError("jcr:like | jcr:contains | jcr:score |
>> jcr:deref | fn:lower-case | fn:upper-case");
>>          }
>>      }
>>
>> @@ -537,7 +547,9 @@ public class XPathToSQL2Converter {
>>          case CHAR_NAME:
>>              while (true) {
>>                  type = types[i];
>> -                if (type != CHAR_NAME && type != CHAR_VALUE) {
>> +                // the '-' can be part of a name,
>> +                // for example in "fn:lower-case"
>> +                if (type != CHAR_NAME && type != CHAR_VALUE && chars[i]
>> != '-') {
>>                      c = chars[i];
>>                      break;
>>                  }
>>
>> Modified:
>> jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt
>> URL:
>> http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt?rev=1370294&r1=1370293&r2=1370294&view=diff
>>
>> ==============================================================================
>> ---
>> jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt
>> (original)
>> +++
>> jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt
>> Tue Aug  7 14:58:32 2012
>> @@ -18,6 +18,14 @@
>>  # * lines starting with "xpath" are xpath queries, followed by expected
>> sql2 query
>>  # * use ascii character only
>>
>> +# sling queries
>> +
>> +xpath
>> //element(*,mix:language)[fn:lower-case(@jcr:language)='en']//element(*,sling:Message)[@sling:message]/(@sling:key|@sling:message)
>> +select [jcr:path], [jcr:score], [sling:key], [sling:message] from
>> [sling:Message] where (lower([jcr:language]) = 'en') and ([sling:message]
>> is not null)
>> +
>> +xpath
>> //element(*,mix:language)[fn:upper-case(@jcr:language)='en']//element(*,sling:Message)[@sling:message]/(@sling:key|@sling:message)
>> +select [jcr:path], [jcr:score], [sling:key], [sling:message] from
>> [sling:Message] where (upper([jcr:language]) = 'en') and ([sling:message]
>> is not null)
>> +
>>  # jboss example queries
>>
>>  xpath //*
>> @@ -229,7 +237,7 @@ xpath //element(*, my:type)[@my:value =
>>  invalid: Query: //element(*, my:type)[@my:value = [(*)'x']; expected: @,
>> true, false, -, +
>>
>>  xpath //element(*, my:type)[jcr:strike(@title,'%Java%')]
>> -invalid: Query: //element(*, my:type)[jcr:strike(@(*)title,'%Java%')];
>> expected: jcr:like | jcr:contains | jcr:score | jcr:deref
>> +invalid: Query: //element(*, my:type)[jcr:strike(@(*)title,'%Java%')];
>> expected: jcr:like | jcr:contains | jcr:score | jcr:deref | fn:lower-case |
>> fn:upper-case
>>
>>  xpath //element(*, my:type)[
>>  invalid: Query: //element(*, my:type)(*)[; expected: not, (, @, true,
>> false, -, +
>>
>>
>>
>

Re: svn commit: r1370294 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt

Posted by Alex Parvulescu <al...@gmail.com>.
Hi,

I'm not sure the query translation for the following query is done properly:


//element(*,mix:language)[fn:lower-case(@jcr:language)='en']//element(*,sling:Message)[@sling:message]/(@sling:key|@sling:message)
as
  select [jcr:path], [jcr:score], [sling:key], [sling:message] from
[sling:Message] where (lower([jcr:language]) = 'en') and ([sling:message]
is not null)

The two, as far as I understand it, as not equal.

The jcr:language property is on the mix:language node, not on the
sling:Message one.

This is how the node structure looks like:

i18n
    /de (jcr:mixinTypes = 'mix:language'; jcr:language = 'de')
        /Advanced (jcr:mixinTypes = 'sling:Message'; sling:key = 'Advanced
((Title))'; sling:message = 'Erweitert' )
        /Clear (jcr:mixinTypes = 'sling:Message'; sling:key = 'Clear
((Clear property action))'; sling:message = 'Löschen')

    /fr (jcr:mixinTypes = 'mix:language'; jcr:language = 'fr')
        /Advanced (jcr:mixinTypes = 'sling:Message'; sling:key = 'Advanced
((Title))'; sling:message = 'Avancé' )
        /Clear (jcr:mixinTypes = 'sling:Message'; sling:key = 'Clear
((Clear property action))'; sling:message = 'Effacer')

So if you want to maintain backwards compatibility I think this would look
better as a join, but feel free to correct me if I'm wrong.

best,
alex


On Tue, Aug 7, 2012 at 4:58 PM, <th...@apache.org> wrote:

> Author: thomasm
> Date: Tue Aug  7 14:58:32 2012
> New Revision: 1370294
>
> URL: http://svn.apache.org/viewvc?rev=1370294&view=rev
> Log:
> OAK-225 Sling I18N queries not supported by Oak (partial fix)
>
> Modified:
>
> jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java
>
> jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt
>
> 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=1370294&r1=1370293&r2=1370294&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
> Tue Aug  7 14:58:32 2012
> @@ -381,10 +381,20 @@ public class XPathToSQL2Converter {
>              Cast c = new Cast(expr, "date");
>              read(")");
>              return c;
> +        } else if ("fn:lower-case".equals(functionName)) {
> +            Function f = new Function("lower");
> +            f.params.add(parseExpression());
> +            read(")");
> +            return f;
> +        } else if ("fn:upper-case".equals(functionName)) {
> +            Function f = new Function("upper");
> +            f.params.add(parseExpression());
> +            read(")");
> +            return f;
>          // } else if ("jcr:deref".equals(functionName)) {
>              // TODO support jcr:deref?
>          } else {
> -            throw getSyntaxError("jcr:like | jcr:contains | jcr:score |
> jcr:deref");
> +            throw getSyntaxError("jcr:like | jcr:contains | jcr:score |
> jcr:deref | fn:lower-case | fn:upper-case");
>          }
>      }
>
> @@ -537,7 +547,9 @@ public class XPathToSQL2Converter {
>          case CHAR_NAME:
>              while (true) {
>                  type = types[i];
> -                if (type != CHAR_NAME && type != CHAR_VALUE) {
> +                // the '-' can be part of a name,
> +                // for example in "fn:lower-case"
> +                if (type != CHAR_NAME && type != CHAR_VALUE && chars[i]
> != '-') {
>                      c = chars[i];
>                      break;
>                  }
>
> Modified:
> jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt
> URL:
> http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt?rev=1370294&r1=1370293&r2=1370294&view=diff
>
> ==============================================================================
> ---
> jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt
> (original)
> +++
> jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryXpathTest.txt
> Tue Aug  7 14:58:32 2012
> @@ -18,6 +18,14 @@
>  # * lines starting with "xpath" are xpath queries, followed by expected
> sql2 query
>  # * use ascii character only
>
> +# sling queries
> +
> +xpath
> //element(*,mix:language)[fn:lower-case(@jcr:language)='en']//element(*,sling:Message)[@sling:message]/(@sling:key|@sling:message)
> +select [jcr:path], [jcr:score], [sling:key], [sling:message] from
> [sling:Message] where (lower([jcr:language]) = 'en') and ([sling:message]
> is not null)
> +
> +xpath
> //element(*,mix:language)[fn:upper-case(@jcr:language)='en']//element(*,sling:Message)[@sling:message]/(@sling:key|@sling:message)
> +select [jcr:path], [jcr:score], [sling:key], [sling:message] from
> [sling:Message] where (upper([jcr:language]) = 'en') and ([sling:message]
> is not null)
> +
>  # jboss example queries
>
>  xpath //*
> @@ -229,7 +237,7 @@ xpath //element(*, my:type)[@my:value =
>  invalid: Query: //element(*, my:type)[@my:value = [(*)'x']; expected: @,
> true, false, -, +
>
>  xpath //element(*, my:type)[jcr:strike(@title,'%Java%')]
> -invalid: Query: //element(*, my:type)[jcr:strike(@(*)title,'%Java%')];
> expected: jcr:like | jcr:contains | jcr:score | jcr:deref
> +invalid: Query: //element(*, my:type)[jcr:strike(@(*)title,'%Java%')];
> expected: jcr:like | jcr:contains | jcr:score | jcr:deref | fn:lower-case |
> fn:upper-case
>
>  xpath //element(*, my:type)[
>  invalid: Query: //element(*, my:type)(*)[; expected: not, (, @, true,
> false, -, +
>
>
>