Return-Path: Delivered-To: apmail-db-jdo-dev-archive@www.apache.org Received: (qmail 47043 invoked from network); 28 Oct 2006 21:53:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 Oct 2006 21:53:32 -0000 Received: (qmail 40765 invoked by uid 500); 28 Oct 2006 21:53:44 -0000 Mailing-List: contact jdo-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jdo-dev@db.apache.org Delivered-To: mailing list jdo-dev@db.apache.org Received: (qmail 40754 invoked by uid 99); 28 Oct 2006 21:53:44 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 Oct 2006 14:53:43 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [212.224.30.66] (HELO service-01.spree.de) (212.224.30.66) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 Oct 2006 14:53:31 -0700 Received: from [172.16.2.80] (vpn-server [192.168.16.104]) (authenticated bits=0) by service-01.spree.de (8.13.4/8.13.4/Debian-3) with ESMTP id k9SLr4XO017354 for ; Sat, 28 Oct 2006 23:53:08 +0200 Message-ID: <4543D141.2050302@spree.de> Date: Sat, 28 Oct 2006 23:53:05 +0200 From: Michael Bouschen Organization: Tech@Spree Engineering User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 To: jdo-dev@db.apache.org Subject: Re: JDOQL query problems (JPOX issues?) References: <4542764E.8020105@spree.de> <24878E87-227A-4A45-9217-3F6E56609417@SUN.com> <1162045186.454367021f005@webmail.jpox.org> <1162069604.4543c664e653e@webmail.jpox.org> In-Reply-To: <1162069604.4543c664e653e@webmail.jpox.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Hi Erik, my 0.02$: According to section "14.6.5 Variable declaration" a variable is a constrained variable, if there is a contains clause for this variable. W/o a contains clause this (so called unconstrained) variable is constrained by the extent of the pc class. An unconstrained variable of type String would not make sense, because there is no such extent. But the variable "str" in the example has a contains clause constraining it to the string collection field in A. Regards Michael > Craig, > > I understand that variables of PC get bound to a set of pc type, but strings... > What is it bound to? > > rgds > > Quoting Craig L Russell : > > >> Hi Erik, >> >> On Oct 28, 2006, at 7:19 AM, Erik Bengtson wrote: >> >> >>> Michael, >>> >>> I was reading Craig comments and noted that "str" is an unbound >>> variable >>> >> The variable "str" is bound by the filter q.setFilter >> ("this.stringCol.contains(str)"). >> >> Craig >> >>> a parameter, and now I think the query is invalid since there is no >>> value for >>> str. >>> >>> Unbound variables are not null values. >>> >>> Quoting Craig L Russell : >>> >>> >>>> Hi Michael, >>>> >>>> From the spec, >>>> >>>> The candidate tuples >>>> are the cartesian product of the candidate class and all variables >>>> used in the result. The re- >>>> sult tuples are the tuples of the candidate class and all variables >>>> used in the result that sat- >>>> isfy the filter. The result is the collection of result expressions >>>> projected from the result >>>> tuples. >>>> >>>> >>>> On Oct 27, 2006, at 2:12 PM, Michael Bouschen wrote: >>>> >>>> >>>>> Hi, >>>>> >>>>> I'm having problems running JDOQL queries that group by a variable. >>>>> I think the queries below are valid, but I would like to double >>>>> check this. If you agree that the queries are valid JDOQL, I will >>>>> check the TCK to add these queries to existing TCK tests or add new >>>>> test cases. I tried the queries with JPOX version 1.1.3 and with >>>>> the nightly build from Oct 27 (no difference). I will send a test >>>>> case to reproduce the problem to Erik and Andy, since I cannot >>>>> attach archives here. >>>>> >>>>> The class model is simple: pc class A has a field stringCol which >>>>> is a collection of strings and another field bCol which is a >>>>> collection of instances of class B. >>>>> >>>>> The following query groups the class A instances by the strings in >>>>> their string collection: >>>>> Query q = pm.newQuery(A.class); >>>>> q.declareVariables("java.lang.String str"); >>>>> q.setFilter("this.stringCol.contains(str)"); >>>>> q.setGrouping("str"); >>>>> q.setResult("str"); >>>>> >>>> The cartesian product of the candidate class and all variables is a >>>> the cartesian product of all A instances and all strings contained in >>>> any stringCol. The result tuples consist of tuples of (A, String) >>>> where the elements of stringCol are projected and associated with the >>>> instances of A whence they came. The result comes from grouping and >>>> projecting the String from the result tuple. So, >>>> >>>> This query should collect all of the unique strings in all instances >>>> of A stringCol. The result is a List. I don't know offhand >>>> how the implementation can do this trick (returning a List in >>>> which each element is a String is easy). >>>> >>>> >>>>> This results in an exception: >>>>> JDOUserException: Unable to find the field "str" in the candidate >>>>> class. It is possible that this field is a field in a subclass, but >>>>> it is illegal to reference fields directly when they are in a >>>>> subclass. >>>>> >>>>> I get a different exception when adding an aggregate to the result >>>>> clause >>>>> q.setResult("str, count(this)"); >>>>> JDOUserException: Unconstrained variable referenced: str >>>>> >>>> This query should collect all of the unique strings in all instances >>>> of A stringCol, count them, and return the string and count of >>>> occurrences. The result is a List Each element consists of >>>> an Object[ ] containing a String in element 0 and a Long in >>>> element 1. >>>> >>>>> The behavior is different when iterating a collection of pc >>>>> instances: >>>>> Query q = pm.newQuery(A.class); >>>>> q.declareVariables("model.B b"); >>>>> q.setFilter("this.bCol.contains(b)"); >>>>> q.setGrouping("b"); >>>>> q.setResult("count(this), b"); >>>>> This results in: >>>>> JDOUserException: The result clause has a field expression >>>>> "UnboundVariable "UNBOUND_B.ID"" that doesnt appear in the >>>>> grouping. Any result specification has to be present in the >>>>> grouping when grouping is specified. >>>>> >>>> This query should collect all of the unique B instances in all >>>> instances of A bCol, count them, and return the B and count of >>>> occurrences. The result is a List Each element consists of >>>> an Object[ ] containing a B in element 0 and a Long in element 1. >>>> >>>> Craig >>>> >>>>> Any help is appreciated. Thanks! >>>>> >>>>> Regards Michael >>>>> >>>>> -- >>>>> Michael Bouschen Tech@Spree Engineering GmbH >>>>> mailto:mbo.tech@spree.de http://www.tech.spree.de/ >>>>> Tel.:++49/30/235 520-33 Buelowstr. 66 >>>>> Fax.:++49/30/2175 2012 D-10783 Berlin >>>>> >>>>> >>>> Craig Russell >>>> Architect, Sun Java Enterprise System http://java.sun.com/products/ >>>> jdo >>>> 408 276-5638 mailto:Craig.Russell@sun.com >>>> P.S. A good JDO? O, Gasp! >>>> >>>> >>>> >>> >>> >> Craig Russell >> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo >> 408 276-5638 mailto:Craig.Russell@sun.com >> P.S. A good JDO? O, Gasp! >> >> >> > > > -- Michael Bouschen Tech@Spree Engineering GmbH mailto:mbo.tech@spree.de http://www.tech.spree.de/ Tel.:++49/30/235 520-33 Buelowstr. 66 Fax.:++49/30/2175 2012 D-10783 Berlin