SPARQL 1.2: Add a test to cover variable introduced by an earlier SELECT expression#340
Merged
Conversation
kasei
approved these changes
May 23, 2026
Co-authored-by: Gregory Todd Williams <greg@evilfunhouse.com>
rubensworks
approved these changes
May 23, 2026
afs
approved these changes
May 24, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See w3c/sparql-query#380