You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by "Andy Seaborne (JIRA)" <ji...@apache.org> on 2016/10/31 09:04:58 UTC
[jira] [Commented] (JENA-1254) GROUP_CONCAT returns nothing when
concatenating unbound and bound values.
[ https://issues.apache.org/jira/browse/JENA-1254?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15621670#comment-15621670 ]
Andy Seaborne commented on JENA-1254:
-------------------------------------
If evaluation of _{{expr}}_ in {{GROUP_CONCAT(expr,...)}} causes and eval error, then the value of {{GROUP_CONCAT}} is an error and the AS does not bind a value. This is defined in the SPARQL 1.1 spec, section 18.5.1.7. {{Flatten(M)}} contains error values, and so where it uses the string {{CONCAT}} to build the string, we get an eval error on {{CONCAT}}.
To replace unbound (which is a form of error when asked for its value) with a value, use {{COALESCE}} (there other ways such as {{IF}} and {{BOUND}}).
{{GROUP_CONCAT(COALESCE(expr,"SomeDefault") ...)}}
which is more easily separated out as
{noformat}
SELECT GROUP_CONCAT(?X ...)}}
WHERE {
...
BIND(COALESCE(expr,"SomeDefault") AS ?X)
}
{noformat}
> GROUP_CONCAT returns nothing when concatenating unbound and bound values.
> -------------------------------------------------------------------------
>
> Key: JENA-1254
> URL: https://issues.apache.org/jira/browse/JENA-1254
> Project: Apache Jena
> Issue Type: Bug
> Components: ARQ
> Affects Versions: Jena 3.1.0
> Reporter: Yev Bronshteyn
> Attachments: c_spdxtest_5530.rdf
>
>
> The following two queries have the same triples in their {{where}} clauses in different order. While it is expected that the first query will return only one solution and the second query - multiple (per https://wiki.blazegraph.com/wiki/index.php/SPARQL_Order_Matters), it is *not* expected that the optional {{copyrightTexts}} value will appear in the result of the first query, but not in the corresponding solution in the result of the second query.
> {code}
> prefix spdx: <http://spdx.org/rdf/terms#>
> prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> prefix doap:<http://usefulinc.com/ns/doap#>
>
> select
> (group_concat(distinct(?licText);separator="\n\n") as ?licTexts)
> (group_concat(?copyrightText;separator="\n\n") as ?copyrightTexts)
> ?name
> where {
> optional {
> ?elem spdx:copyrightText ?copyrightText .
> filter (isLiteral(?copyrightText))
> } .
> {
> # And the name
> {?elem spdx:name ?name}
> union
> {
> ?elem spdx:artifactOf ?artifact .
> ?artifact doap:name ?name
> }
> }.
> }
> group by ?name
> {code}
> And
> {code}
> prefix spdx: <http://spdx.org/rdf/terms#>
> prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> prefix doap:<http://usefulinc.com/ns/doap#>
>
> select
> (group_concat(distinct(?licText);separator="\n\n") as ?licTexts)
> (group_concat(?copyrightText;separator="\n\n") as ?copyrightTexts)
> ?name
> where {
> {
> # And the name
> {?elem spdx:name ?name}
> union
> {
> ?elem spdx:artifactOf ?artifact .
> ?artifact doap:name ?name
> }
> }.
> optional {
> ?elem spdx:copyrightText ?copyrightText .
> filter (isLiteral(?copyrightText))
> } .
> }
> group by ?name
> {code}
> The issue seems to be that with the second query, GROUP_CONCAT has to concatenate the bound value of ?copyrightText with unbound values. Changing the second query to unconditionally bind a value to ?copyrightText eliminates the behavior.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)