Return-Path: X-Original-To: apmail-jackrabbit-oak-dev-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-oak-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DADB0DB9F for ; Mon, 20 Aug 2012 14:21:25 +0000 (UTC) Received: (qmail 54693 invoked by uid 500); 20 Aug 2012 14:21:25 -0000 Delivered-To: apmail-jackrabbit-oak-dev-archive@jackrabbit.apache.org Received: (qmail 54654 invoked by uid 500); 20 Aug 2012 14:21:25 -0000 Mailing-List: contact oak-dev-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-dev@jackrabbit.apache.org Delivered-To: mailing list oak-dev@jackrabbit.apache.org Received: (qmail 54646 invoked by uid 99); 20 Aug 2012 14:21:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Aug 2012 14:21:25 +0000 X-ASF-Spam-Status: No, hits=-1.6 required=5.0 tests=RCVD_IN_DNSWL_MED,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [64.18.1.23] (HELO exprod6og109.obsmtp.com) (64.18.1.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Aug 2012 14:21:19 +0000 Received: from outbound-smtp-2.corp.adobe.com ([193.104.215.16]) by exprod6ob109.postini.com ([64.18.5.12]) with SMTP ID DSNKUDJHyjHr0FQhZgvKe2aXdfZDhpAu0y7a@postini.com; Mon, 20 Aug 2012 07:20:59 PDT Received: from inner-relay-4.eur.adobe.com (inner-relay-4b [10.128.4.237]) by outbound-smtp-2.corp.adobe.com (8.12.10/8.12.10) with ESMTP id q7KEKvbq020775 for ; Mon, 20 Aug 2012 07:20:57 -0700 (PDT) Received: from nacas01.corp.adobe.com (nacas01.corp.adobe.com [10.8.189.99]) by inner-relay-4.eur.adobe.com (8.12.10/8.12.9) with ESMTP id q7KEKuYr015317 for ; Mon, 20 Aug 2012 07:20:56 -0700 (PDT) Received: from eurhub01.eur.adobe.com (10.128.4.30) by nacas01.corp.adobe.com (10.8.189.99) with Microsoft SMTP Server (TLS) id 8.3.264.0; Mon, 20 Aug 2012 07:20:55 -0700 Received: from susi.corp.adobe.com (10.132.4.179) by eurhub01.eur.adobe.com (10.128.4.111) with Microsoft SMTP Server id 8.3.264.0; Mon, 20 Aug 2012 15:20:51 +0100 Message-ID: <503247C3.4090803@apache.org> Date: Mon, 20 Aug 2012 16:20:51 +0200 From: =?ISO-8859-1?Q?Michael_D=FCrig?= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: Subject: Re: Issue while converting from Xpath to Sql2 References: In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org On 20.8.12 16:05, Chetan Mehrotra wrote: > While trying to run Granite over Oak the User Admin UI was failing to load > because of problem in executing an XPath query > > Initial Query (in JSON) [4] is passed to > o.a.j.commons.jackrabbit.user.AuthorizableQueryManager which internally > converts it into XPath using a builder pattern and generates following > XPath query > > //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 > > This query when passed to o.a.j.oak.query.XPathToSQL2Converter results in > an exception > > Issue - #1 > --------------- > > Caused by: java.text.ParseException: Query: > //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; > expected: ( > at > org.apache.jackrabbit.oak.query.XPathToSQL2Converter.getSyntaxError(XPathToSQL2Converter.java:743) > at > org.apache.jackrabbit.oak.query.XPathToSQL2Converter.read(XPathToSQL2Converter.java:435) > > > On debugging issue is shown at char 183 and is around > jcr:like(rep:principalName,(*)'%%') . So it appears that > XPathQueryEvaluator.visit(XPathQueryBuilder.NodeCondition) [1] should add > '@' before appending the rep:principalName property name as its a property > condition Thanks for spotting this. It is a bug in XPathQueryEvaluator which seems to be also present in JR2. AFAIK JR2 is very lenient wrt. the presence of the @ for properties. Could you provide a patch for this for JR2 and Oak? I'll take care of the rest then. > > Issue - #2 > --------------- > Temp fixing the issue with principalName and moving further leads to second > issue > > java.text.ParseException: Query: > //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; > expected: ) > at > org.apache.jackrabbit.oak.query.XPathToSQL2Converter.getSyntaxError(XPathToSQL2Converter.java:743) > > Now here issue is at jcr:like(fn:name(.(*)),'%%'). And checking various > example it appears that fn:name does not take any argument. So again > possibly an issue with [1] Most probably this is the same situation like with #1 above. Could you check whether fixing this in XPathQueryEvaluator would also work with JR2? If so I suggest we fix it there (again both in JR2 and Oak). Michael > > Summary > ========= > Given above details it appears that issue exists in > XPathQueryEvaluator.visit(XPathQueryBuilder.NodeCondition) > [1] and [2]. However such a generated XPath works in JR2 but fails to get > converted in Oak. So my query is > > 1. Should it be fixed in [2] and possibly at [1] > 2. OR XPathToSQL2Converter is adapted to support such cases for backward > compatibility > > A test case is provided at [3] > > regards > Chetan > > [1] > https://github.com/apache/jackrabbit/blob/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.java#L135 > [2] > https://github.com/apache/jackrabbit-oak/blob/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/query/XPathQueryEvaluator.java#L132 > > [3] > @Test > public void testXpath2Sql2() throws ParseException { > String notWorking = > "//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"; > String working = > "//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"; > XPathToSQL2Converter xc = new XPathToSQL2Converter(); > xc.convert(notWorking); > } > > [4] { > "condition": [ > [ > { > "contains": { > "property": "profile\/@givenName", > "expression": "**" > } > }, > { > "contains": { > "property": "profile\/@familyName", > "expression": "**" > } > }, > { > "contains": { > "property": "profile\/@email", > "expression": "**" > } > }, > { > "named": "%%" > } > ] > ], > "selector": "authorizable", > "sort": { > "property": "@rep:principalName", > "direction": "asc" > } > } >