Skip to content

SPARQL 1.2: Add a test to cover variable introduced by an earlier SELECT expression#340

Merged
Tpt merged 2 commits into
mainfrom
tpt/group-select-variable
May 28, 2026
Merged

SPARQL 1.2: Add a test to cover variable introduced by an earlier SELECT expression#340
Tpt merged 2 commits into
mainfrom
tpt/group-select-variable

Conversation

@Tpt

@Tpt Tpt commented May 23, 2026

Copy link
Copy Markdown
Contributor

@Tpt Tpt requested review from afs and rubensworks May 23, 2026 08:37
Comment thread sparql/sparql12/grouping/manifest.ttl Outdated
Co-authored-by: Gregory Todd Williams <greg@evilfunhouse.com>
@Tpt Tpt merged commit 9909627 into main May 28, 2026
2 checks passed
jitsedesmet added a commit to comunica/traqula that referenced this pull request Jun 3, 2026
* feat: add select-variable-reuse test and allow AS-bound variable references

Add support for referencing variables bound by preceding (expr AS ?var)
expressions in subsequent SELECT expressions, per the updated SPARQL spec
(w3c/sparql-query#380, w3c/rdf-tests#340).

The query `SELECT (COUNT(?v) AS ?count) (?count + 1 AS ?countPlusOne) ...`
was previously rejected with 'Use of ungrouped variable' because the
validator did not recognize that ?count was in scope from an earlier
AS binding.

Changes:
- Fix queryProjectionIsGood validation to track AS-bound variables and
  allow their use in subsequent projection expressions
- Add select-variable-reuse test with AST, algebra, and generator statics

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* some comments

* Split 1.1 and 1.2 validators

* test: achieve 100% coverage on rules-sparql-1-2 validators

The queryProjectionIsGood function in rules-sparql-1-2/validators.ts is a
separate implementation from the 1.1 version (changed per w3c/sparql-query#380).
Although all 1.1 tests correctly run against the 1.2 parser, several branches
of this function were not reached by any existing test.

Fix by adding cases to the shared test infrastructure so they run on
both parsers automatically:

- 3 new sparql-1-1-invalid static queries (select-star-with-group-by,
  ungrouped-variable-in-expression-projection,
  count-with-ungrouped-expression-variable) that cover the throw paths
  in queryProjectionIsGood (lines 123 and 158).

- 3 new note tests in importSparql11NoteTests covering the no-throw
  branches: AS variable not conflicting with a term-var subquery,
  AS variable not conflicting with a wildcard subquery, and expression
  projection variable covered by GROUP BY (line 158 and 183-186 FALSE
  branches).

Also add rapport.md documenting the investigation findings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* test: move 3 note tests from Sparql11NotesTest to static files

Replace the three programmatic 'should NOT throw' tests added in the
previous commit with proper static test files that slot into the shared
positive-test infrastructure and therefore run automatically on all
parsers (1.1, 1.1-adjust, 1.2) and the 1.2 generator.

Files added per test case:
- sparql/sparql-1-1/<name>.sparql        – the query under test
- ast-source-tracked/sparql-1-1/<name>.json – expected AST (source-tracked)
- sparql-generated/sparql-1-1/<name>.sparql – expected generator output
- sparql-generated-compact/sparql-1-1/<name>.sparql – compact generator output

Cases migrated:
- note-as-var-not-in-term-subquery
- note-as-var-not-in-wildcard-subquery
- note-expression-grouped-var

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* No rapport

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Tpt Tpt deleted the tpt/group-select-variable branch June 18, 2026 18:34
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.

5 participants