Hi Andrus,

Thanks for the quick reply. I tried #1 but both constructors of
ASTAggregateFunctionCall are package private.
Option #2 I tried using the alias in the count to check in the
SQLTreeProcessor when to change it to another function, i.e.

property.count().alias("__ARRAY_AGG__");

...

protected Optional<Node> onFunctionNode(Node parent, FunctionNode child, int
index)
{
if ("__ARRAY_AGG__".equals(child.getAlias()))
{
return Optional.of(new FunctionNode("ARRAY_AGG", null));
}

return Optional.empty();
}

Problem here is that the return type doesn't match with the count causing:

Caused by: org.postgresql.util.PSQLException: Bad value for type long :
{123,456}
at org.postgresql.jdbc.PgResultSet.toLong(PgResultSet.java:3233)
at org.postgresql.jdbc.PgResultSet.getLong(PgResultSet.java:2449)
at
io.agroal.pool.wrapper.ResultSetWrapper.getLong(ResultSetWrapper.java:158)
at
org.apache.cayenne.access.types.LongType.materializeObject(LongType.java:37)
at
org.apache.cayenne.access.types.LongType.materializeObject(LongType.java:28)
at
org.apache.cayenne.access.jdbc.reader.ScalarRowReader.readRow(ScalarRowReader.java:50)
at
org.apache.cayenne.access.jdbc.reader.CompoundRowReader.readRow(CompoundRowReader.java:47)
at
org.apache.cayenne.access.jdbc.reader.CompoundRowReader.readRow(CompoundRowReader.java:28)
at
org.apache.cayenne.access.jdbc.JDBCResultIterator.nextRow(JDBCResultIterator.java:104)
at
org.apache.cayenne.access.jdbc.LimitResultIterator.nextRow(LimitResultIterator.java:115)
at
org.apache.cayenne.access.jdbc.LimitResultIterator.allRows(LimitResultIterator.java:95)
at
org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.java:139)
at
org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:97)
at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:273)

Best regards,
Mark

On Thu, Jan 4, 2024 at 5:57 PM Andrus Adamchik <[email protected]> wrote:

> Hi Marc,
>
> Upgrading to 4.2 final is probably a good idea regardless of the
> aggregation function use :)
>
> Regarding your question. There are a few ways to approach it (and I wish
> we could abstract it a bit better) :
>
> 1. Instead of someProperty.function(..), try to create a subclass of
> ASTAggregateFunctionCall. E.g. you can follow an expample of ASTMin.
> 2. You can customize the generated SQL via a custom SQLTreeProcessor
> (something that was mentioned a few months ago in a different context)
>
> I am really curious if #1 works, and if it doesn't, be happy to provide
> pointers on #2.
>
> Thanks,
> Andrus
>
>
> > On Jan 4, 2024, at 10:12 AM, Mark Stobbe <[email protected]> wrote:
> >
> > Hi all,
> >
> > Does anyone know how to use "array_agg" as a function? I am using Cayenne
> > 4.2.M3, but it's ok if I need to upgrade to a later version.
> >
> > I was trying with someProperty.function("array_agg", List.class)
> > but it will not automatically group by all the other fields since it
> > doesn't recognise it as a ASTAggregateFunctionCall
> >
> > Mark
>
>

Reply via email to