You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
should return a single binding of ?eye_color to "blue". It should return the same binding when the equivalent SPARQL algebra is given instead of the string query. However, in the following tests, while Comunica always returns the binding for the string query, it returns 0 results for the algebra query when:
The data was generated by constructing quads manually, rather than by parsing Turtle, or
Something else has match()ed the source and read some data from it before the query is executed.
Presumably there's still something to this that I haven't grokked yet, but that's the bizarre behavior I'm seeing right now.
Importantly (and demonstrated below), if you replace the blank node in the query with a variable, the binding is always returned.
Tests
import{Readable}from"node:stream";import{QueryEngine}from"@comunica/query-sparql-rdfjs";import{describe,it,expect}from"@jest/globals";import*asN3from"n3";import{translate,typeAlgebra}from"sparqlalgebrajs";importtype*asRDFfrom"@rdfjs/types";/** * Read all results from an RDF Stream and return them as a promise of an array. */exportconstreadAll=<R>(stream: RDF.ResultStream<R>)=>newPromise<R[]>((resolve)=>{constquads: R[]=[];stream.on("data",(result: R)=>{quads.push(result);}).on("end",()=>{resolve(quads);});});describe("querying with a string or with algebra",()=>{constdf=N3.DataFactory;constengine=newQueryEngine();constbindings=async(source: RDF.Source,sparql: string|Algebra.Operation)=>readAll(awaitengine.queryBindings(sparql,{sources: [source],}));([["blank node",/* sparql */` PREFIX swapi: <http://swapi.dev/documentation#> SELECT ?eye_color WHERE { [] swapi:name "Luke Skywalker"; swapi:eye_color ?eye_color . } `,],["variable",/* sparql */` PREFIX swapi: <http://swapi.dev/documentation#> SELECT ?eye_color WHERE { ?luke swapi:name "Luke Skywalker"; swapi:eye_color ?eye_color . } `,],]asconst).forEach(([thing,sparqlString])=>{constsparqlAlgebra=translate(sparqlString);describe(`using a ${thing} in the query`,()=>{describe("starting with Quads",()=>{it("should be the same result",async()=>{conststore=newN3.Store();store.addQuads([df.quad(df.blankNode("b0"),df.namedNode("http://swapi.dev/documentation#eye_color"),df.literal("blue")),df.quad(df.blankNode("b0"),df.namedNode("http://swapi.dev/documentation#name"),df.literal("Luke Skywalker")),]);expect(awaitbindings(store,sparqlAlgebra)).toStrictEqual(awaitbindings(store,sparqlString));});});describe("starting with Turtle",()=>{constdata=/* turtle */` @prefix swapi: <http://swapi.dev/documentation#>. [] swapi:eye_color "blue"; swapi:name "Luke Skywalker". `;it("should be the same result",async()=>{conststore=newN3.Store();constparser=newN3.StreamParser();store.import(parser.import(Readable.from(data)));expect(awaitbindings(store,sparqlAlgebra)).toStrictEqual(awaitbindings(store,sparqlString));});it("should still be the same result when an unrelated `match()` is read",async()=>{conststore=newN3.Store();constparser=newN3.StreamParser();store.import(parser.import(Readable.from(data)));// Why does this make the test fail?awaitreadAll(store.match());expect(awaitbindings(store,sparqlAlgebra)).toStrictEqual(awaitbindings(store,sparqlString));});});});});});
Full test output
querying with a string or with algebra
using a blank node in the query
starting with Quads
✕ should be the same result (31 ms)
starting with Turtle
✓ should be the same result (17 ms)
✕ should still be the same result when an unrelated `match()` is read (10 ms)
using a variable in the query
starting with Quads
✓ should be the same result (9 ms)
starting with Turtle
✓ should be the same result (4 ms)
✓ should still be the same result when an unrelated `match()` is read (8 ms)
● querying with a string or with algebra › using a blank node in the query › starting with Quads › should be the same result
expect(received).toStrictEqual(expected) // deep equality
- Expected - 20
+ Received + 1
- Array [
- Bindings {
- "dataFactory": DataFactory {
- "blankNodeCounter": 0,
- "blankNodePrefix": "df_47_",
- },
- "entries": Immutable.Map {
- "eye_color": Object {
- "datatype": Object {
- "termType": "NamedNode",
- "value": "http://www.w3.org/2001/XMLSchema#string",
- },
- "language": "",
- "termType": "Literal",
- "value": "blue",
- },
- },
- "type": "bindings",
- },
- ]
+ Array []
81 | ]);
82 |
> 83 | expect(await bindings(store, sparqlAlgebra)).toStrictEqual(
| ^
84 | await bindings(store, sparqlString)
85 | );
86 | });
at Object.<anonymous> (src/repro.test.ts:83:56)
● querying with a string or with algebra › using a blank node in the query › starting with Turtle › should still be the same result when an unrelated `match()` is read
expect(received).toStrictEqual(expected) // deep equality
- Expected - 20
+ Received + 1
- Array [
- Bindings {
- "dataFactory": DataFactory {
- "blankNodeCounter": 0,
- "blankNodePrefix": "df_47_",
- },
- "entries": Immutable.Map {
- "eye_color": Object {
- "datatype": Object {
- "termType": "NamedNode",
- "value": "http://www.w3.org/2001/XMLSchema#string",
- },
- "language": "",
- "termType": "Literal",
- "value": "blue",
- },
- },
- "type": "bindings",
- },
- ]
+ Array []
113 | await readAll(store.match());
114 |
> 115 | expect(await bindings(store, sparqlAlgebra)).toStrictEqual(
| ^
116 | await bindings(store, sparqlString)
117 | );
118 | });
at Object.<anonymous> (src/repro.test.ts:115:56)
Issue type:
Description:
Given the data:
the query:
should return a single binding of
?eye_color
to"blue"
. It should return the same binding when the equivalent SPARQL algebra is given instead of the string query. However, in the following tests, while Comunica always returns the binding for the string query, it returns 0 results for the algebra query when:match()
ed the source and read some data from it before the query is executed.Presumably there's still something to this that I haven't grokked yet, but that's the bizarre behavior I'm seeing right now.
Importantly (and demonstrated below), if you replace the blank node in the query with a variable, the binding is always returned.
Tests
Full test output
Environment:
The text was updated successfully, but these errors were encountered: