Skip to content

Treat variables that are not in the pattern as unbound in expressions - #85

Open
MathiasVDA wants to merge 1 commit into
DataTreehouse:mainfrom
MathiasVDA:fix/unbound-variable-in-expressions
Open

MathiasVDA wants to merge 1 commit into
DataTreehouse:mainfrom
MathiasVDA:fix/unbound-variable-in-expressions

Conversation

@MathiasVDA

Copy link
Copy Markdown

Requested by Mathias

Fixes #84.

Before: an expression that uses a variable which does not occur in the graph pattern fails the whole query, e.g. ORDER BY ?nope raises Variable ?nope not found in context ProjectInner-OrderByExpression(0)-OrderingOperation. The same happens for BOUND(?nope), COALESCE(?nope, ?o) and FILTER(?nope = "a").

After: the variable is treated as unbound, as SPARQL 1.1 §18.6 requires. ORDER BY ?nope keeps the input order, BOUND(?nope) is false, COALESCE falls through to the next argument and FILTER(?nope = "a") removes the row.

How: variable() and bound() in lib/query_processing/src/expressions.rs no longer return VariableNotFound. variable() adds a null column of type None for the expression context, the same way project() already handles a projected variable that does not exist, and bound() returns false. The existing null handling in comparisons and functions does the rest.

Tests: py_maplib/tests/test_unbound_variables.py covers ORDER BY (with and without DISTINCT), BOUND, COALESCE and FILTER. The new tests fail on 0.20.32 and pass with this change; test_basics, test_aggregation_count_zero, test_concat_is_string, test_replace_bindings and test_exceptions still pass.

🤖 Generated with Claude Code

ORDER BY ?x, BOUND(?x), COALESCE(?x, ...) and FILTER(?x = ...) failed with
VariableNotFound when ?x did not occur in the graph pattern. Per SPARQL 1.1
such a variable is unbound in every solution, the same way project()
already treats a projected variable that does not exist.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Query fails with "Variable ?x not found in context" when an expression uses a variable that is not in the pattern

1 participant