[ 
https://issues.apache.org/jira/browse/CALCITE-5280?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17608727#comment-17608727
 ] 

Bertil Chapuis edited comment on CALCITE-5280 at 9/23/22 3:41 PM:
------------------------------------------------------------------

{quote}I agree that it's confusing to have regular and aggregate functions 
named {{{}ST_Union{}}}. (Not just confusing for humans - the validator needs to 
decide whether a query is implicitly an aggregate query due to the presence of 
aggregate functions.) H2GIS, at least, [has 
both|http://www.h2gis.org/docs/dev/ST_Union/]. Do you recommend that were 
rename the regular (non-aggregate) function to {{{}ST_UnaryUnion{}}}? I could 
support that.
{quote}
 
Ideally, I would love to use the same method names, but my understanding of 
what's going on is still limited. I tried to debug the query and I think the 
validator selects the right function. However, a strange exception occurs later 
on (see below). I believe that the problem is located at 
{{{}RelFieldTrimmer.java:1223{}}}. This call will always throw an exception 
when {{fieldsUsed}} is empty and {{fieldCount}} is equal to 0. Is this a bug?
{code:java}
// If they are asking for no fields, we can't give them what they want,
// because zero-column records are illegal. Give them the last field,
// which is unlikely to be a system field.
if (fieldsUsed.isEmpty()) {
   fieldsUsed = ImmutableBitSet.range(fieldCount - 1, fieldCount);
}
{code}
{code:java}
1524,1525c1524,1567
< EXPR$0
< MULTIPOINT ((-2 3), (1 2))
---
> java.sql.SQLException: Error while executing SQL "SELECT ST_AsText(ST_Union(
>     ST_GeomFromText('POINT(1 2)'),
>     ST_GeomFromText('POINT(-2 3)')))": Index -1 out of bounds for length 0
>     at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
>     at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
>     at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:163)
>     at 
> org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:227)
>     at net.hydromatic.quidem.Quidem.checkResult(Quidem.java:325)
>     at net.hydromatic.quidem.Quidem.access$2800(Quidem.java:54)
>     at net.hydromatic.quidem.Quidem$ContextImpl.checkResult(Quidem.java:1748)
>     at 
> net.hydromatic.quidem.Quidem$CheckResultCommand.execute(Quidem.java:1079)
>     at net.hydromatic.quidem.Quidem$CompositeCommand.execute(Quidem.java:1549)
>     at net.hydromatic.quidem.Quidem.execute(Quidem.java:216)
>     at org.apache.calcite.test.QuidemTest.checkRun(QuidemTest.java:171)
>     at org.apache.calcite.test.QuidemTest.test(QuidemTest.java:222)
>     at org.apache.calcite.test.CoreQuidemTest.main(CoreQuidemTest.java:41)
> Caused by: java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds 
> for length 0
>     at org.apache.calcite.util.ImmutableBitSet.range(ImmutableBitSet.java:245)
>     at 
> org.apache.calcite.sql2rel.RelFieldTrimmer.trimFields(RelFieldTrimmer.java:1223)
>     at jdk.internal.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
>     at 
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>     at java.base/java.lang.reflect.Method.invoke(Method.java:568)
>     at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:531)
>     at 
> org.apache.calcite.sql2rel.RelFieldTrimmer.dispatchTrimFields(RelFieldTrimmer.java:284)
>     at 
> org.apache.calcite.sql2rel.RelFieldTrimmer.trimChild(RelFieldTrimmer.java:226)
>     at 
> org.apache.calcite.sql2rel.RelFieldTrimmer.trimFields(RelFieldTrimmer.java:498)
>     at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
>     at 
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>     at java.base/java.lang.reflect.Method.invoke(Method.java:568)
>     at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:531)
>     at 
> org.apache.calcite.sql2rel.RelFieldTrimmer.dispatchTrimFields(RelFieldTrimmer.java:284)
>     at 
> org.apache.calcite.sql2rel.RelFieldTrimmer.trim(RelFieldTrimmer.java:171)
>     at 
> org.apache.calcite.sql2rel.SqlToRelConverter.trimUnusedFields(SqlToRelConverter.java:549)
>     at org.apache.calcite.prepare.Prepare.trimUnusedFields(Prepare.java:384)
>     at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:297)
>     at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:220)
>     at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:648)
>     at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:514)
>     at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:484)
>     at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:234)
>     at 
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:623)
>     at 
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:677)
>     at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
>     ... 10 more {code}
 


was (Author: bchapuis):
{quote}I agree that it's confusing to have regular and aggregate functions 
named {{{}ST_Union{}}}. (Not just confusing for humans - the validator needs to 
decide whether a query is implicitly an aggregate query due to the presence of 
aggregate functions.) H2GIS, at least, [has 
both|http://www.h2gis.org/docs/dev/ST_Union/]. Do you recommend that were 
rename the regular (non-aggregate) function to {{{}ST_UnaryUnion{}}}? I could 
support that.
{quote}
 
Ideally, I would love to use the same signatures, but my understanding of 
what's going on is still limited. I tried to debug the query and I think the 
validator selects the right function. However, a strange exception occurs later 
on (see below). I believe that the problem is located at 
{{{}RelFieldTrimmer.java:1223{}}}. This call will always throw an exception 
when {{fieldsUsed}} is empty and {{fieldCount}} is equal to 0. Is this a bug?
{code:java}
// If they are asking for no fields, we can't give them what they want,
// because zero-column records are illegal. Give them the last field,
// which is unlikely to be a system field.
if (fieldsUsed.isEmpty()) {
   fieldsUsed = ImmutableBitSet.range(fieldCount - 1, fieldCount);
}
{code}
{code:java}
1524,1525c1524,1567
< EXPR$0
< MULTIPOINT ((-2 3), (1 2))
---
> java.sql.SQLException: Error while executing SQL "SELECT ST_AsText(ST_Union(
>     ST_GeomFromText('POINT(1 2)'),
>     ST_GeomFromText('POINT(-2 3)')))": Index -1 out of bounds for length 0
>     at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
>     at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
>     at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:163)
>     at 
> org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:227)
>     at net.hydromatic.quidem.Quidem.checkResult(Quidem.java:325)
>     at net.hydromatic.quidem.Quidem.access$2800(Quidem.java:54)
>     at net.hydromatic.quidem.Quidem$ContextImpl.checkResult(Quidem.java:1748)
>     at 
> net.hydromatic.quidem.Quidem$CheckResultCommand.execute(Quidem.java:1079)
>     at net.hydromatic.quidem.Quidem$CompositeCommand.execute(Quidem.java:1549)
>     at net.hydromatic.quidem.Quidem.execute(Quidem.java:216)
>     at org.apache.calcite.test.QuidemTest.checkRun(QuidemTest.java:171)
>     at org.apache.calcite.test.QuidemTest.test(QuidemTest.java:222)
>     at org.apache.calcite.test.CoreQuidemTest.main(CoreQuidemTest.java:41)
> Caused by: java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds 
> for length 0
>     at org.apache.calcite.util.ImmutableBitSet.range(ImmutableBitSet.java:245)
>     at 
> org.apache.calcite.sql2rel.RelFieldTrimmer.trimFields(RelFieldTrimmer.java:1223)
>     at jdk.internal.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
>     at 
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>     at java.base/java.lang.reflect.Method.invoke(Method.java:568)
>     at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:531)
>     at 
> org.apache.calcite.sql2rel.RelFieldTrimmer.dispatchTrimFields(RelFieldTrimmer.java:284)
>     at 
> org.apache.calcite.sql2rel.RelFieldTrimmer.trimChild(RelFieldTrimmer.java:226)
>     at 
> org.apache.calcite.sql2rel.RelFieldTrimmer.trimFields(RelFieldTrimmer.java:498)
>     at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
>     at 
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>     at java.base/java.lang.reflect.Method.invoke(Method.java:568)
>     at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:531)
>     at 
> org.apache.calcite.sql2rel.RelFieldTrimmer.dispatchTrimFields(RelFieldTrimmer.java:284)
>     at 
> org.apache.calcite.sql2rel.RelFieldTrimmer.trim(RelFieldTrimmer.java:171)
>     at 
> org.apache.calcite.sql2rel.SqlToRelConverter.trimUnusedFields(SqlToRelConverter.java:549)
>     at org.apache.calcite.prepare.Prepare.trimUnusedFields(Prepare.java:384)
>     at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:297)
>     at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:220)
>     at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:648)
>     at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:514)
>     at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:484)
>     at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:234)
>     at 
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:623)
>     at 
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:677)
>     at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
>     ... 10 more {code}
 

> Implement geometry aggregate functions
> --------------------------------------
>
>                 Key: CALCITE-5280
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5280
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>            Reporter: Bertil Chapuis
>            Assignee: Bertil Chapuis
>            Priority: Minor
>              Labels: pull-request-available
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Geometry aggregate functions (ST_Accum, ST_Collect, and ST_Union) are 
> currently missing in Calcite. Using an AggregateFunctionImpl looks be pretty 
> straightforward, but many aggregate function implement SqlAggFunction 
> directly.
> [~julianhyde] What would be the best way to implement them?



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to