Skip to content

[Query] Implement GROUP BY, Aggregates and HAVING clauses #565

Description

@remiceres

Summary

Implement SPARQL 1.1 solution sequence partitioning (GROUP BY), aggregate computation (COUNT, SUM, AVG, MIN, MAX, SAMPLE, GROUP_CONCAT), and post-aggregation filtering (HAVING) in core.next.query.


Objectives and Technical Scope

1. Solution Sequence Grouping (GROUP BY)

  • Partition incoming solution sequences into multiset groups according to key variables or expressions.
  • Support implicit single-group aggregation when aggregate functions are present without an explicit GROUP BY.

2. Aggregate Functions

  • Implement stateful aggregate evaluators:
    • COUNT(?var), COUNT(*), COUNT(DISTINCT ?var).
    • SUM(?var), SUM(DISTINCT ?var).
    • AVG(?var), AVG(DISTINCT ?var).
    • MIN(?var), MAX(?var).
    • SAMPLE(?var).
    • GROUP_CONCAT(?var; separator="..."), GROUP_CONCAT(DISTINCT ?var; separator="...").

3. Post-Aggregation Filtering (HAVING) and Projection Rules

  • Evaluate boolean filter expressions over computed group aggregate states in HAVING.
  • Enforce SPARQL 1.1 projection constraints (only grouped variables or aggregate expressions in SELECT).

4. Validation and Conformance

  • Validate against official W3C SPARQL 1.1 test suites (aggregates, grouping, having) in corese-w3c.

Dependencies

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requeststandard featureIssue related to an implementation based on W3C standards

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions