summaryrefslogtreecommitdiff
path: root/rdflib/plugins/sparql/algebra.py
diff options
context:
space:
mode:
authorRob B <73846016+robons@users.noreply.github.com>2023-01-29 15:51:08 +0000
committerGitHub <noreply@github.com>2023-01-29 16:51:08 +0100
commit9625ed0b432c9085e2d9dda1fd8acf707b9022ab (patch)
tree8ab2cd3d404205199fccad7caff74a37f19ca22e /rdflib/plugins/sparql/algebra.py
parentc5c16dfafaf32dc46a06381a774822eb9be8cfbc (diff)
downloadrdflib-9625ed0b432c9085e2d9dda1fd8acf707b9022ab.tar.gz
fix: bug applying VALUES outside of a GROUP BY (#2188)
Altering order in which aggregate variable aliases are renamed to user-defined variable names to ensure that when defining a `VALUES` pattern outside of a `GROUP BY`, the variables in the query are correctly joined to those defined in the `VALUES` pattern.
Diffstat (limited to 'rdflib/plugins/sparql/algebra.py')
-rw-r--r--rdflib/plugins/sparql/algebra.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/rdflib/plugins/sparql/algebra.py b/rdflib/plugins/sparql/algebra.py
index 923957b2..1429012b 100644
--- a/rdflib/plugins/sparql/algebra.py
+++ b/rdflib/plugins/sparql/algebra.py
@@ -667,9 +667,14 @@ def translate(q: CompValue) -> Tuple[CompValue, List[Variable]]:
aggregate = True
if aggregate:
- M, E = translateAggregates(q, M)
+ M, aggregateAliases = translateAggregates(q, M)
else:
- E = []
+ aggregateAliases = []
+
+ # Need to remove the aggregate var aliases before joining to VALUES;
+ # else the variable names won't match up correctly when aggregating.
+ for alias, var in aggregateAliases:
+ M = Extend(M, alias, var)
# HAVING
if q.having:
@@ -689,6 +694,7 @@ def translate(q: CompValue) -> Tuple[CompValue, List[Variable]]:
PV = list(VS)
else:
+ E = list()
PV = list()
for v in q.projection:
if v.var:
@@ -702,8 +708,8 @@ def translate(q: CompValue) -> Tuple[CompValue, List[Variable]]:
else:
raise Exception("I expected a var or evar here!")
- for e, v in E:
- M = Extend(M, e, v)
+ for e, v in E:
+ M = Extend(M, e, v)
# ORDER BY
if q.orderby: