Skip to content

Comprehensive SPARQL tests#104

Open
daghovland wants to merge 10 commits intomainfrom
story/sparql-tests
Open

Comprehensive SPARQL tests#104
daghovland wants to merge 10 commits intomainfrom
story/sparql-tests

Conversation

@daghovland
Copy link
Copy Markdown
Owner

@daghovland daghovland commented Mar 1, 2026

Added tests for several examples in the SPARQL-1.2 specification

This pull request implements support for SPARQL aggregate functions and the GROUP BY clause, enabling complex analytical queries over RDF datasets.

Key Changes

  • AST & Parser Enhancements:

    • Extended the query AST in src/Rdf/Query.fs with Aggregate, Expression, and ProjectionElement types.
    • Updated Sparql.Parser to handle aggregate expressions (e.g., (SUM(?price) AS ?total)) and GROUP BY conditions.
    • Renamed internal union cases (e.g., Variable to ExprVariable) for better cross-language compatibility (C#/F#).
  • Query Processor Implementation (src/Rdf/QueryProcessor.fs):

    • Implemented evaluation logic for GROUP BY clauses.
    • Added support for both explicit and implicit grouping (where aggregates are used without a GROUP BY clause).
    • Implemented the following SPARQL aggregate functions:
      • SUM (with DISTINCT support).
      • COUNT (including COUNT(*) and COUNT(?var) with DISTINCT support).
      • MIN and MAX.
      • AVG (with DISTINCT support).
    • Ensured spec compliance, such as returning 0 for SUM on empty groups.
  • Testing & Verification:

    • Enabled and passed the TestSparql12ExampleAggregate parser test.
    • Implemented a new integration test TestSparqlAggregate in Api.Tests/TestApi.cs to verify end-to-end execution of aggregate queries via the public IDataset API.
    • Verified all existing SPARQL tests to ensure no regressions.

Example Supported Query

PREFIX : <http://books.example/>
SELECT ?org (SUM(?lprice) AS ?totalPrice)
WHERE {
  ?org :hasBook ?book .
  ?book :price ?lprice .
}
GROUP BY ?org

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant