You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Matt Solnit <ms...@soasta.com> on 2009/03/04 22:22:28 UTC
Unable to group by certain functions
Hi all. I'm trying to use GROUP BY with Derby, and it looks like certain
functions work and certain ones don't.
For example, the following:
ij> CREATE TABLE foo (a INT);
ij> SELECT ABS(a) FROM foo GROUP BY ABS(a);
works fine. But if I use CEIL or FLOOR, I get an error:
ij> SELECT CEIL(a) FROM foo GROUP BY CEIL(a);
ERROR 42Y30: The SELECT list of a grouped query contains at least one
invalid expression.
If a SELECT list has a GROUP BY, the list may only contain valid grouping
expressions and
valid aggregate expressions.
I'm not sure what the difference is, but I came across DERBY-592
(JDBC-escaped functions) and I'm wondering if this is part of the issue.
Am I doing something incorrectly, or is this a bug?
-- Matt
Re: Unable to group by certain functions
Posted by "Dag H. Wanvik" <Da...@Sun.COM>.
Maybe you can use a rewriting trick, e.g. something like this:
select max(c) from (select ceil(i) c from t) tt group by c
Thanks,
Dag
Re: Unable to group by certain functions
Posted by Matt Solnit <ms...@soasta.com>.
On 3/6/09 3:46 AM, "Knut Anders Hatlen" <Kn...@Sun.COM> wrote:
> Bryan Pendleton <bp...@amberpoint.com> writes:
>
>>>> but rather is intentional, and has to do with the fact that CEIL
>>>> and FLOOR are implemented differently than ABS.
>>>
>>> What's next? Should I submit an issue to JIRA?
>>
>> Yes, please. I think that would be very helpful. Please include your
>> test programs/scripts, and pointers to the various email threads
>> that you located, as they are definitely quite helpful.
>>
>> Here's a few more pointers regarding filing an issue:
>> http://db.apache.org/derby/DerbyBugGuidelines.html
>
> There is a JIRA for allowing user-defined functions in GROUP BY:
> https://issues.apache.org/jira/browse/DERBY-4003
Hi Knut. Thanks for letting me know about this. I'll add my additional
comments to the JIRA issue.
-- Matt
Re: Unable to group by certain functions
Posted by Knut Anders Hatlen <Kn...@Sun.COM>.
Bryan Pendleton <bp...@amberpoint.com> writes:
>>> but rather is intentional, and has to do with the fact that CEIL
>>> and FLOOR are implemented differently than ABS.
>>
>> What's next? Should I submit an issue to JIRA?
>
> Yes, please. I think that would be very helpful. Please include your
> test programs/scripts, and pointers to the various email threads
> that you located, as they are definitely quite helpful.
>
> Here's a few more pointers regarding filing an issue:
> http://db.apache.org/derby/DerbyBugGuidelines.html
There is a JIRA for allowing user-defined functions in GROUP BY:
https://issues.apache.org/jira/browse/DERBY-4003
--
Knut Anders
Re: Unable to group by certain functions
Posted by Bryan Pendleton <bp...@amberpoint.com>.
>> but rather is intentional, and has to do with the fact that CEIL
>> and FLOOR are implemented differently than ABS.
>
> What's next? Should I submit an issue to JIRA?
Yes, please. I think that would be very helpful. Please include your
test programs/scripts, and pointers to the various email threads
that you located, as they are definitely quite helpful.
Here's a few more pointers regarding filing an issue:
http://db.apache.org/derby/DerbyBugGuidelines.html
thanks,
bryan
Re: Unable to group by certain functions
Posted by Matt Solnit <ms...@soasta.com>.
> > ij> SELECT ABS(a) FROM foo GROUP BY ABS(a);
> >
> > works fine. But if I use CEIL or FLOOR, I get an error:
> I'm truly speculating here, but I wonder if this behavior is
> because CEIL and FLOOR return floating point values, and therefore
> have a certain amount of inexactness in them, which is unacceptable
> for GROUP BY processing?
Hi Bryan. Thanks for your response. This precisely one of the subjects
that were debated in the 2006 thread
(http://markmail.org/message/pggvaqh6ejg2dtf3). Here are some snippets:
Daniel Debrunner: "Grouping by DOUBLE should be allowed since they can be
compared. It's probably not advisable, but Derby's SQL should allow it."
Bernt Johnsen: "A double is just a finite set of bits ... so it should
work, even if it is not the most reasonable thing to do."
And of course, it works fine in MySQL and PostgreSQL ;-).
> I'm afraid all I can really do is to confirm that I see the
> same behavior that you see, and it doesn't appear to be random,
> but rather is intentional, and has to do with the fact that CEIL
> and FLOOR are implemented differently than ABS.
What's next? Should I submit an issue to JIRA?
> bryan
Re: Unable to group by certain functions
Posted by Bryan Pendleton <bp...@amberpoint.com>.
> ij> SELECT ABS(a) FROM foo GROUP BY ABS(a);
>
> works fine. But if I use CEIL or FLOOR, I get an error:
I'm not completely sure I understand this, but I think that
the issue involves the internal implementation of the CEIL
and FLOOR functions.
At the point where the error is generated, there is a comment
which says:
// disallow any expression which involves native java computation.
// Not possible to consider java expressions for equivalence.
And I think that the implementation of the CEIL function is
internally based on calling java.lang.StrictMath.ceil.
I think you're right that DERBY-592, and DERBY-475, are related
to the behavior that you are seeing. I see that there's a comment
in DERBY-475 which notes that using java.lang.StrictMath was
done to improve cross-JVM portability.
I'm truly speculating here, but I wonder if this behavior is
because CEIL and FLOOR return floating point values, and therefore
have a certain amount of inexactness in them, which is unacceptable
for GROUP BY processing?
I'm afraid all I can really do is to confirm that I see the
same behavior that you see, and it doesn't appear to be random,
but rather is intentional, and has to do with the fact that CEIL
and FLOOR are implemented differently than ABS.
bryan
Re: Unable to group by certain functions
Posted by Matt Solnit <ms...@soasta.com>.
One last comment (and I apologize for flooding the list): it looks like this was discussed extensively in 2006. See http://markmail.org/message/pggvaqh6ejg2dtf3. But it does not appear that the issue was ever resolved.
-- Matt
On 3/4/09 1:25 PM, "Matt Solnit" <ms...@soasta.com> wrote:
P.S. I forgot to include the following:
Derby version 10.4.2.0
Java version 1.5.0_16
Mac OS X 10.5.6 (32-bit)
On 3/4/09 1:22 PM, "Matt Solnit" <ms...@soasta.com> wrote:
> Hi all. I'm trying to use GROUP BY with Derby, and it looks like certain
> functions work and certain ones don't.
>
> For example, the following:
>
> ij> CREATE TABLE foo (a INT);
> ij> SELECT ABS(a) FROM foo GROUP BY ABS(a);
>
> works fine. But if I use CEIL or FLOOR, I get an error:
>
> ij> SELECT CEIL(a) FROM foo GROUP BY CEIL(a);
> ERROR 42Y30: The SELECT list of a grouped query contains at least one invalid
> expression.
> If a SELECT list has a GROUP BY, the list may only contain valid grouping
> expressions and
> valid aggregate expressions.
>
> I'm not sure what the difference is, but I came across DERBY-592 (JDBC-escaped
> functions) and I'm wondering if this is part of the issue.
>
> Am I doing something incorrectly, or is this a bug?
>
> -- Matt
Re: Unable to group by certain functions
Posted by Matt Solnit <ms...@soasta.com>.
P.S. I forgot to include the following:
Derby version 10.4.2.0
Java version 1.5.0_16
Mac OS X 10.5.6 (32-bit)
On 3/4/09 1:22 PM, "Matt Solnit" <ms...@soasta.com> wrote:
> Hi all. I'm trying to use GROUP BY with Derby, and it looks like certain
> functions work and certain ones don't.
>
> For example, the following:
>
> ij> CREATE TABLE foo (a INT);
> ij> SELECT ABS(a) FROM foo GROUP BY ABS(a);
>
> works fine. But if I use CEIL or FLOOR, I get an error:
>
> ij> SELECT CEIL(a) FROM foo GROUP BY CEIL(a);
> ERROR 42Y30: The SELECT list of a grouped query contains at least one invalid
> expression.
> If a SELECT list has a GROUP BY, the list may only contain valid grouping
> expressions and
> valid aggregate expressions.
>
> I'm not sure what the difference is, but I came across DERBY-592 (JDBC-escaped
> functions) and I'm wondering if this is part of the issue.
>
> Am I doing something incorrectly, or is this a bug?
>
> -- Matt