Osma Suominen created MARMOTTA-657:
--------------------------------------

             Summary: SPARQL query GROUP BY with ORDER BY clause fails
                 Key: MARMOTTA-657
                 URL: https://issues.apache.org/jira/browse/MARMOTTA-657
             Project: Marmotta
          Issue Type: Bug
    Affects Versions: 3.4.0
         Environment: Ubuntu 16.04
PostgreSQL 9.5.4 (empty database)
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

            Reporter: Osma Suominen


I noticed that the following SPARQL query, used to count the number of triples 
in different graphs, fails on the current 3.4.0-SNAPSHOT (using PostgreSQL 9.5 
as backend, starting from an empty database). It works on 3.3.0 using the same 
database.

{noformat}
SELECT ?g (COUNT(*) AS ?c) {
  GRAPH ?g {
    ?s ?p ?o
  }
}
GROUP BY ?g
ORDER BY DESC(?c)
{noformat}

The error in the Tomcat log is:


{noformat}
09:32:30.101 ERROR - error while evaluating query: {}
org.openrdf.query.QueryEvaluationException: org.postgresql.util.PSQLException: 
ERROR: aggregate functions are not allowed in GROUP BY
  Position: 183
        at 
org.openrdf.repository.sail.SailTupleQuery.evaluate(SailTupleQuery.java:67)
        at 
org.openrdf.repository.sail.SailTupleQuery.evaluate(SailTupleQuery.java:75)
        at 
org.apache.marmotta.platform.sparql.services.sparql.SparqlServiceImpl.query(SparqlServiceImpl.java:344)
        at 
org.apache.marmotta.platform.sparql.services.sparql.SparqlServiceImpl.query(SparqlServiceImpl.java:351)
        at 
org.apache.marmotta.platform.sparql.services.sparql.SparqlServiceImpl.access$700(SparqlServiceImpl.java:60)
        at 
org.apache.marmotta.platform.sparql.services.sparql.SparqlServiceImpl$5.call(SparqlServiceImpl.java:290)
        at 
org.apache.marmotta.platform.sparql.services.sparql.SparqlServiceImpl$5.call(SparqlServiceImpl.java:279)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.openrdf.sail.SailException: org.postgresql.util.PSQLException: 
ERROR: aggregate functions are not allowed in GROUP BY
  Position: 183
        at 
org.apache.marmotta.kiwi.sparql.sail.KiWiSparqlSailConnection.evaluate(KiWiSparqlSailConnection.java:101)
        at 
org.openrdf.sail.helpers.SailConnectionWrapper.evaluate(SailConnectionWrapper.java:95)
        at 
org.openrdf.repository.sail.SailTupleQuery.evaluate(SailTupleQuery.java:60)
        ... 10 common frames omitted
Caused by: org.openrdf.query.QueryEvaluationException: 
org.postgresql.util.PSQLException: ERROR: aggregate functions are not allowed 
in GROUP BY
  Position: 183
        at 
org.apache.marmotta.kiwi.sparql.evaluation.KiWiEvaluationStrategy.evaluateNative(KiWiEvaluationStrategy.java:398)
        at 
org.apache.marmotta.kiwi.sparql.evaluation.KiWiEvaluationStrategy.evaluate(KiWiEvaluationStrategy.java:133)
        at 
org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl.evaluate(EvaluationStrategyImpl.java:616)
        at 
org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl.evaluate(EvaluationStrategyImpl.java:207)
        at 
org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl.evaluate(EvaluationStrategyImpl.java:687)
        at 
org.apache.marmotta.kiwi.sparql.evaluation.KiWiEvaluationStrategy.evaluate(KiWiEvaluationStrategy.java:108)
        at 
org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl.evaluate(EvaluationStrategyImpl.java:589)
        at 
org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl.evaluate(EvaluationStrategyImpl.java:207)
        at 
org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl.evaluate(EvaluationStrategyImpl.java:621)
        at 
org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl.evaluate(EvaluationStrategyImpl.java:207)
        at 
org.apache.marmotta.kiwi.sparql.sail.KiWiSparqlSailConnection.evaluate(KiWiSparqlSailConnection.java:98)
        ... 12 common frames omitted
Caused by: org.postgresql.util.PSQLException: ERROR: aggregate functions are 
not allowed in GROUP BY
  Position: 183
        at 
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161)
        at 
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890)
        at 
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
        at 
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:560)
        at 
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
        at 
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
        at 
org.apache.marmotta.kiwi.sparql.evaluation.KiWiEvaluationStrategy$1.call(KiWiEvaluationStrategy.java:217)
        at 
org.apache.marmotta.kiwi.sparql.evaluation.KiWiEvaluationStrategy$1.call(KiWiEvaluationStrategy.java:213)
        ... 4 common frames omitted
{noformat}

Originally reported on users@marmotta: 
https://lists.apache.org/thread.html/7df333d6678a853e0ae013178660a78cd7bc5438caaf8ee207ff643f@%3Cusers.marmotta.apache.org%3E



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to