Makes GROUP_CONCAT return a string in all cases

Closes #33
pull/35/head
Tpt 5 years ago
parent cc7c92092f
commit 6c96f4fa82
  1. 11
      lib/src/sparql/eval.rs
  2. 3
      lib/tests/oxigraph-tests/sparql/group_concat_with_null.rq
  3. 13
      lib/tests/oxigraph-tests/sparql/group_concat_with_null.srx
  4. 4
      lib/tests/oxigraph-tests/sparql/group_concat_with_null.ttl
  5. 20
      lib/tests/oxigraph-tests/sparql/manifest.ttl
  6. 9
      lib/tests/sparql_test_cases.rs

@ -2596,12 +2596,8 @@ impl<'a, S: ReadableEncodedStore + 'a> GroupConcatAccumulator<'a, S> {
impl<'a, S: ReadableEncodedStore + 'a> Accumulator for GroupConcatAccumulator<'a, S> { impl<'a, S: ReadableEncodedStore + 'a> Accumulator for GroupConcatAccumulator<'a, S> {
fn add(&mut self, element: Option<EncodedTerm>) { fn add(&mut self, element: Option<EncodedTerm>) {
if let Some(concat) = self.concat.as_mut() { if let Some(concat) = self.concat.as_mut() {
let element = if let Some(element) = element { if let Some(element) = element {
self.eval.to_string_and_language(element) if let Some((value, e_language)) = self.eval.to_string_and_language(element) {
} else {
None
};
if let Some((value, e_language)) = element {
if let Some(lang) = self.language { if let Some(lang) = self.language {
if lang != e_language { if lang != e_language {
self.language = Some(None) self.language = Some(None)
@ -2611,8 +2607,7 @@ impl<'a, S: ReadableEncodedStore + 'a> Accumulator for GroupConcatAccumulator<'a
self.language = Some(e_language) self.language = Some(e_language)
} }
concat.push_str(&value); concat.push_str(&value);
} else { }
self.concat = None;
} }
} }
} }

@ -0,0 +1,3 @@
PREFIX : <http://www.example.org>
SELECT (GROUP_CONCAT(?opt) AS ?g) WHERE { ?baseS a :ex OPTIONAL { ?baseS :opt ?opt } }

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
<variable name="g"/>
</head>
<results>
<result>
<binding name="opt">
<literal datatype="http://www.w3.org/2001/XMLSchema#string">value</literal>
</binding>
</result>
</results>
</sparql>

@ -0,0 +1,4 @@
@prefix : <http://www.example.org/> .
:a a :ex ; :s :opt "value" .
:b a :ex .

@ -0,0 +1,20 @@
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <https://github.com/oxigraph/oxigraph/tests/sparql/manifest#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix mf: <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#> .
@prefix qt: <http://www.w3.org/2001/sw/DataAccess/tests/test-query#> .
<> rdf:type mf:Manifest ;
rdfs:label "Oxigraph SPARQL tests" ;
mf:entries
(
:group_concat_with_null
) .
:group_concat_with_null rdf:type mf:QueryEvaluationTest ;
mf:name "GROUP_CONCAT with NULL" ;
rdfs:comment "GROUP_CONCAT should ignore null values" ;
mf:action
[ qt:query <group_concat_with_null.rq> ;
qt:data <group_concat_with_null.ttl> ] ;
mf:result <group_concat_with_null.srx> .

@ -10,6 +10,7 @@ use std::fmt;
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use std::io::{BufRead, BufReader}; use std::io::{BufRead, BufReader};
use std::iter::once;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::Arc; use std::sync::Arc;
@ -27,6 +28,9 @@ fn sparql_w3c_syntax_testsuite() -> Result<()> {
for test_result in manifest_10_urls for test_result in manifest_10_urls
.into_iter() .into_iter()
.chain(manifest_11_urls.into_iter()) .chain(manifest_11_urls.into_iter())
.chain(once(
"https://github.com/oxigraph/oxigraph/tests/sparql/manifest.ttl",
))
.flat_map(TestManifest::new) .flat_map(TestManifest::new)
{ {
let test = test_result.unwrap(); let test = test_result.unwrap();
@ -272,6 +276,11 @@ fn to_relative_path(url: &str) -> Result<String> {
"http://www.w3.org/2009/sparql/docs/tests/", "http://www.w3.org/2009/sparql/docs/tests/",
"rdf-tests/sparql11/", "rdf-tests/sparql11/",
)) ))
} else if url.starts_with("https://github.com/oxigraph/oxigraph/tests/") {
Ok(url.replace(
"https://github.com/oxigraph/oxigraph/tests/",
"oxigraph-tests/",
))
} else { } else {
Err(Error::msg(format!("Not supported url for file: {}", url))) Err(Error::msg(format!("Not supported url for file: {}", url)))
} }

Loading…
Cancel
Save