Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions rdflib/plugins/sparql/aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,16 @@ def get_value(self) -> None:


class GroupConcat(Accumulator):
def __init__(self, aggregation):
value: List[Literal]

def __init__(self, aggregation: CompValue):
super(GroupConcat, self).__init__(aggregation)
# only GROUPCONCAT needs to have a list as accumulator
self.value = []
self.separator = aggregation.separator or " "
if aggregation.separator is None:
self.separator = " "
else:
self.separator = aggregation.separator

def update(self, row: FrozenBindings, aggregator: "Aggregator") -> None:
try:
Expand Down
23 changes: 23 additions & 0 deletions test/test_sparql/test_translate_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import rdflib.plugins.sparql.algebra as algebra
import rdflib.plugins.sparql.parser as parser
from rdflib import Graph, Literal, URIRef
from rdflib.plugins.sparql.algebra import translateAlgebra


Expand Down Expand Up @@ -304,3 +305,25 @@ def test_roundtrip(test_spec: AlgebraTest, data_path: Path) -> None:
# TODO: Execute the raw query (query_text) and the reconstituted query
# (query_from_query_from_algebra) against a well defined graph and ensure
# they yield the same result.


def test_sparql_group_concat():
"""Tests if GROUP_CONCAT correctly uses the separator keyword"""
query = """
PREFIX : <http://example.org/>

SELECT ?subject (GROUP_CONCAT(?object; separator="")
AS ?concatenatedObjects)
WHERE {
VALUES (?subject ?object) {
(:pred "a")
(:pred "b")
(:pred "c")
}
}
GROUP BY ?subject
"""

g = Graph()
q = dict(g.query(query))
assert q[URIRef("http://example.org/pred")] == Literal("abc")