Skip to content

Commit

Permalink
Correctly convert FROM/CONSTRUCT algebra
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimvh committed Oct 30, 2023
1 parent 51242ca commit edfbb30
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/sparql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,12 @@ function translateExtend(op: Algebra.Extend): any
function translateFrom(op: Algebra.From): GroupPattern
{
const result = translateOperation(op.input);
// Can't type as CONSTRUCT queries do not have `from` field in their type
let obj = result;
// project is nested in group object
const obj: SelectQuery = result.patterns[0];
if (result.type === 'group') {
obj = result.patterns[0];
}
obj.from = {
default: op.default,
named: op.named
Expand Down
65 changes: 65 additions & 0 deletions test/algebra-blank-to-var/sparql-1.1/construct/construct-from.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"default": [
{
"termType": "NamedNode",
"value": "http://example.com/data"
}
],
"input": {
"input": {
"input": {
"patterns": [
{
"graph": {
"termType": "DefaultGraph",
"value": ""
},
"object": {
"termType": "Variable",
"value": "o"
},
"predicate": {
"termType": "Variable",
"value": "p"
},
"subject": {
"termType": "Variable",
"value": "s"
},
"termType": "Quad",
"type": "pattern"
}
],
"type": "bgp"
},
"template": [
{
"graph": {
"termType": "DefaultGraph",
"value": ""
},
"object": {
"termType": "Variable",
"value": "o"
},
"predicate": {
"termType": "Variable",
"value": "p"
},
"subject": {
"termType": "Variable",
"value": "s"
},
"termType": "Quad",
"type": "pattern"
}
],
"type": "construct"
},
"length": 100,
"start": 0,
"type": "slice"
},
"named": [],
"type": "from"
}
65 changes: 65 additions & 0 deletions test/algebra/sparql-1.1/construct/construct-from.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"default": [
{
"termType": "NamedNode",
"value": "http://example.com/data"
}
],
"input": {
"input": {
"input": {
"patterns": [
{
"graph": {
"termType": "DefaultGraph",
"value": ""
},
"object": {
"termType": "Variable",
"value": "o"
},
"predicate": {
"termType": "Variable",
"value": "p"
},
"subject": {
"termType": "Variable",
"value": "s"
},
"termType": "Quad",
"type": "pattern"
}
],
"type": "bgp"
},
"template": [
{
"graph": {
"termType": "DefaultGraph",
"value": ""
},
"object": {
"termType": "Variable",
"value": "o"
},
"predicate": {
"termType": "Variable",
"value": "p"
},
"subject": {
"termType": "Variable",
"value": "s"
},
"termType": "Quad",
"type": "pattern"
}
],
"type": "construct"
},
"length": 100,
"start": 0,
"type": "slice"
},
"named": [],
"type": "from"
}
4 changes: 4 additions & 0 deletions test/sparql/sparql-1.1/construct/construct-from.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONSTRUCT { ?s ?p ?o. }
FROM <http://example.com/data>
WHERE { ?s ?p ?o. }
LIMIT 100

0 comments on commit edfbb30

Please sign in to comment.