diff options
author | Filip Kovacevic <f.kovacevic@gmx.at> | 2022-01-03 18:18:54 +0100 |
---|---|---|
committer | Filip Kovacevic <f.kovacevic@gmx.at> | 2022-01-03 18:18:54 +0100 |
commit | 17ad45865d521b830c6b8e391a95dff8b714f636 (patch) | |
tree | 46be83e8d59d4a095a1d9fc0c95ebd2fb5858429 /rdflib/plugins/sparql/algebra.py | |
parent | 6b9e04c42435eb950073ad9282c899e802b372a5 (diff) | |
download | rdflib-17ad45865d521b830c6b8e391a95dff8b714f636.tar.gz |
algebra.py: bugfixes for SUBSTR and CONCAT
test_graph_patterns__group_and_substr.txt: formatted select clause
test_translate_algebra.py: added logging for debugging
tox.ini: configured logging for pytests and set the level to DEBUG for debugging
Diffstat (limited to 'rdflib/plugins/sparql/algebra.py')
-rw-r--r-- | rdflib/plugins/sparql/algebra.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/rdflib/plugins/sparql/algebra.py b/rdflib/plugins/sparql/algebra.py index 805e62a8..e957ea1b 100644 --- a/rdflib/plugins/sparql/algebra.py +++ b/rdflib/plugins/sparql/algebra.py @@ -6,6 +6,7 @@ http://www.w3.org/TR/sparql11-query/#sparqlQuery """ import functools +import logging import operator import collections @@ -847,9 +848,15 @@ def translateAlgebra(query_algebra: Query): with open("query.txt", "w") as file: file.write(filedata) + aggr_vars = collections.defaultdict(list) + def convert_node_arg(node_arg): if isinstance(node_arg, Identifier): - return node_arg.n3() + if node_arg in aggr_vars.keys(): + grp_var = aggr_vars[node_arg].pop(0) + return grp_var.n3() + else: + return node_arg.n3() elif isinstance(node_arg, CompValue): return "{" + node_arg.name + "}" elif isinstance(node_arg, Expr): @@ -959,7 +966,8 @@ def translateAlgebra(query_algebra: Query): raise ExpressionNotCoveredException( "This expression might not be covered yet." ) - agg_func_name = agg_func.name.split("_")[1] + aggr_vars[agg_func.res].append(agg_func.vars) + agg_func_name = agg_func.name.split('_')[1] distinct = "" if agg_func.distinct: distinct = agg_func.distinct + " " @@ -1022,7 +1030,7 @@ def translateAlgebra(query_algebra: Query): if isinstance(c.expr, Identifier): var = c.expr.n3() if c.order is not None: - cond = var + "(" + c.order + ")" + cond = c.order + "(" + var + ")" else: cond = var order_conditions.append(cond) |