# Aggregates

Copyright © 2010 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark, and document use rules apply.

## Abstract

This page describes W3C SPARQL Working Group's SPARQL 1.1 test suite.

### Contributing Tests

The test manifests and entries are built automatically from manifest.ttl using a Rake task. Tests may be contributed via pull request to https://github.com/w3c/rdf-tests with suitable changes to the manifest.ttl and referenced files.

### Distribution

Distributed under both the W3C Test Suite License and the W3C 3-clause BSD License. To contribute to a W3C Test Suite, see the policies and contribution forms.

### Disclaimer

UNDER BOTH MUTUALLY EXCLUSIVE LICENSES, THIS DOCUMENT AND ALL DOCUMENTS, TESTS AND SOFTWARE THAT LINK THIS STATEMENT ARE PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, OR TITLE; THAT THE CONTENTS OF THE DOCUMENT ARE SUITABLE FOR ANY PURPOSE; NOR THAT THE IMPLEMENTATION OF SUCH CONTENTS WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE DOCUMENT OR THE PERFORMANCE OR IMPLEMENTATION OF THE CONTENTS THEREOF.

## Test Descriptions

agg01: COUNT 1

  Simple count

  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg01.srx
agg02: COUNT 2

  Count with grouping

  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg02.srx
agg03: COUNT 3

  Count with grouping and HAVING clause

  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg03.srx
agg04: COUNT 4

  Count(*)

  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg04.srx
agg05: COUNT 5

  Count(*) with grouping

  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg05.srx
agg06: COUNT 6

  Count() with HAVING Count()

  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg06.srx
agg07: COUNT 7

  Count() with grouping and HAVING Count()

  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg07.srx
agg08: COUNT 8

  grouping by expression, done wrong

  type
    mf:NegativeSyntaxTest11
  approval
  action
    agg08.rq
agg08b: COUNT 8b

  grouping by expression, done correctly

  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg08b.srx
agg09: COUNT 9

  Projection of an ungrouped variable (not appearing in the GROUP BY expression)

  type
    mf:NegativeSyntaxTest11
  approval
  action
    agg09.rq
agg10: COUNT 10

  Projection of an ungrouped variable (no GROUP BY expression at all)

  type
    mf:NegativeSyntaxTest11
  approval
  action
    agg10.rq
agg11: COUNT 11

  Use of an ungrouped variable in a project expression

  type
    mf:NegativeSyntaxTest11
  approval
  action
    agg11.rq
agg12: COUNT 12

  Use of an ungrouped variable in a project expression, where the variable appears in a GROUP BY expression

  type
    mf:NegativeSyntaxTest11
  approval
  action
    agg12.rq
agg-groupconcat-01: GROUP_CONCAT 1
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-groupconcat-1.srx
agg-groupconcat-02: GROUP_CONCAT 2
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-groupconcat-2.srx
agg-groupconcat-03: GROUP_CONCAT with SEPARATOR
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-groupconcat-3.srx
agg-groupconcat-04: GROUP_CONCAT with same language tag
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-groupconcat-4.srx
agg-groupconcat-05: GROUP_CONCAT with different language tags
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-groupconcat-5.srx
agg-sum-01: SUM
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-sum-01.srx
agg-sum-02: SUM with GROUP BY
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-sum-02.srx
agg-avg-01: AVG
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-avg-01.srx
agg-avg-02: AVG with GROUP BY
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-avg-02.srx
agg-avg-03: AVG with empty group (value defined to be 0)
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-avg-03.srx
agg-min-01: MIN
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-min-01.srx
agg-min-02: MIN with GROUP BY
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-min-02.srx
agg-max-01: MAX
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-max-01.srx
agg-max-02: MAX with GROUP BY
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-max-02.srx
agg-sample-01: SAMPLE
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-sample-01.srx
agg-err-01: Error in AVG

  Error in AVG return no binding

  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-err-01.srx
agg-err-02: Protect from error in AVG

  Protect from error in AVG using IF and COALESCE

  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-err-02.srx
agg-empty-group-max-1: agg on empty set, explicit grouping

  aggregating empty results returns no rows, as there are no grouped results.

  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-empty-group-max-1.srx
agg-empty-group-max-2: agg on empty set, no grouping

  aggregating empty results with no group-by always returns a single result.

  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-empty-group-max-2.srx
agg-empty-group-count-1: COUNT: no match, with group

  counting no results with grouping returns no results.

  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-empty-group-count-1.srj
agg-empty-group-count-2: COUNT: no match, no group

  counting no results without grouping always returns a single result.

  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-empty-group-count-2.srj
agg-empty-group-count-graph: COUNT: no GROUP BY inside of GRAPH

  counting no results without grouping always returns a single result per named graph.

  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-empty-group-count-graph.ttl
agg-multiple-having: HAVING: multiple conditions

  HAVING can contain multiple conditions.

  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-multiple-having.srx
agg-group-fn: GROUP BY with a function
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-group-fn.srx
agg-group-builtin: GROUP BY with a built-in function
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-group-builtin.srx
agg-avg-distinct: AVG DISTINCT with GROUP BY
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-avg-distinct.srx
agg-count-distinct: COUNT DISTINCT with GROUP BY
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-count-distinct.srx
agg-count-rows-distinct: COUNT(DISTINCT *) with GROUP BY
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-count-rows-distinct.srx
agg-groupconcat-distinct: GROUP_CONCAT DISTINCT
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-groupconcat-distinct.srx
agg-max-distinct: MAX DISTINCT with GROUP BY
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-max-distinct.srx
agg-min-distinct: MIN DISTINCT with GROUP BY
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-min-distinct.srx
agg-sample-distinct: SAMPLE DISTINCT
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-sample-01.srx
agg-sum-distinct: SUM DISTINCT with GROUP BY
  type
    mf:QueryEvaluationTest
  approval
  action
  result
    agg-sum-distinct.srx