Skip to content

Commit

Permalink
apacheGH-1615: LATERAL eval tests
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Nov 21, 2022
1 parent 4fb933e commit 521ffa2
Show file tree
Hide file tree
Showing 15 changed files with 340 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ public static void setup() {
dsg.add(Quad.defaultGraphNodeGenerated, b, p2, o);
dsg.add(Quad.defaultGraphNodeGenerated, c, p1, o);
//dsg.add(Quad.defaultGraphNodeGenerated, a, pSelf, a);

// Currently these optimizations are off by default
Assert.assertFalse(ARQ.isFalse(ARQ.optFilterImplicitJoin));
Assert.assertFalse(ARQ.isFalse(ARQ.optImplicitLeftJoin));
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public Op transform(OpTable opTable) {
@Test public void disjunction03() {
testOp("(filter (|| (!= ?x <x>) (= ?x <y>)) (bgp ( ?s ?p ?x)) )",
t_disjunction,
// Note - reording of disjunction terms.
// Note - reordering of disjunction terms.
"(disjunction ",
"(assign ((?x <y>)) (bgp ( ?s ?p <y>)))",
"(filter (!= ?x <x>) (bgp ( ?s ?p ?x)))",
Expand Down Expand Up @@ -391,11 +391,21 @@ public void oneOf6() {
"(assign ((?x ?y)) (bgp (?y ?p ?o)(?y ?p1 ?o1)))");
}

// Test no longer appropriate.
// LATERAL means the variables that are join-scope bound may have values at execution time.
// @Test public void implicitJoin02() {
// testOp(
// "(filter (= ?x ?y) (bgp (?x ?p ?o)))",
// t_implicitJoin,
// "(table empty)");
// }

// LATERAL safe - no transformation.
@Test public void implicitJoin02() {
testOp(
"(filter (= ?x ?y) (bgp (?x ?p ?o)))",
t_implicitJoin,
"(table empty)");
"(filter (= ?x ?y) (bgp (?x ?p ?o)))");
}

@Test public void implicitJoin03() {
Expand Down Expand Up @@ -465,17 +475,28 @@ public void oneOf6() {
(String[])null);
}

// Test no longer appropriate.
// LATERAL means the variables that are join-scope bound may have values at execution time.
// @Test public void implictJoin11() {
// // Test case related to JENA-500
// // Detect that the expression (= ?prebound ?y) is always 'error' because
// // ?prebound is undef. Therefore the whole thing can be removed as there
// // can be no solutions.
// testOp(
// "(filter (= ?prebound ?y) (extend ((?y (ex:someFunction ?x))) (table unit)))",
// t_implicitJoin,
// "(table empty)");
// }

// LATERAL safe - no "(table empty)" substitution.
@Test public void implictJoin11() {
// Test case related to JENA-500
// Detect that the expression (= ?prebound ?y) is always 'error' because
// ?prebound is undef. Therefore the whole thing can be removed as there
// can be no solutions.
testOp(
"(filter (= ?prebound ?y) (extend ((?y (ex:someFunction ?x))) (table unit)))",
t_implicitJoin,
"(table empty)");
"(filter (= ?prebound ?y) (extend ((?y (ex:someFunction ?x))) (table unit)))");
}


@Test public void implicitJoin12() {
// Test case from JENA-692
// Implicit join should not apply to the whole union because the variables involved aren't fixed
Expand Down
24 changes: 24 additions & 0 deletions jena-arq/testing/ARQ/Lateral/data.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
PREFIX : <http://example/>

:s1 :p 1 .
:s1 :label "s1-one" .

:s2 :p 2 .
:s2 :label "s2-one" .
:s2 :label "s2-two" .

:s3 :p 3 .
:s3 :label "s3-one" .
:s3 :label "s3-two" .
:s3 :label "s3-three" .

:x1 :q 1 .
:z1 :q 1 .

:x0 :q "a" .
:z0 :q "b" .





6 changes: 6 additions & 0 deletions jena-arq/testing/ARQ/Lateral/lateral-1.arq
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PREFIX : <http://example/>

SELECT ?s ?label {
?s :p ?o
LATERAL { SELECT * { ?s :label ?label } LIMIT 2 }
}
28 changes: 28 additions & 0 deletions jena-arq/testing/ARQ/Lateral/lateral-1.srj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{ "head": {
"vars": [ "s" , "label" ]
} ,
"results": {
"bindings": [
{
"s": { "type": "uri" , "value": "http://example/s3" } ,
"label": { "type": "literal" , "value": "s3-three" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s3" } ,
"label": { "type": "literal" , "value": "s3-two" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s1" } ,
"label": { "type": "literal" , "value": "s1-one" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s2" } ,
"label": { "type": "literal" , "value": "s2-one" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s2" } ,
"label": { "type": "literal" , "value": "s2-two" }
}
]
}
}
5 changes: 5 additions & 0 deletions jena-arq/testing/ARQ/Lateral/lateral-2.arq
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PREFIX : <http://example/>

SELECT * {
LATERAL { ?s :label ?label }
}
32 changes: 32 additions & 0 deletions jena-arq/testing/ARQ/Lateral/lateral-2.srj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{ "head": {
"vars": [ "s" , "label" ]
} ,
"results": {
"bindings": [
{
"s": { "type": "uri" , "value": "http://example/s3" } ,
"label": { "type": "literal" , "value": "s3-three" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s3" } ,
"label": { "type": "literal" , "value": "s3-two" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s1" } ,
"label": { "type": "literal" , "value": "s1-one" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s2" } ,
"label": { "type": "literal" , "value": "s2-one" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s2" } ,
"label": { "type": "literal" , "value": "s2-two" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s3" } ,
"label": { "type": "literal" , "value": "s3-one" }
}
]
}
}
10 changes: 10 additions & 0 deletions jena-arq/testing/ARQ/Lateral/lateral-3.arq
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PREFIX : <http://example/>

SELECT * {
?s :q ?z .

LATERAL { ?x :q ?v .
FILTER( ?x != ?s)
FILTER( ?v = ?z )
}
}
20 changes: 20 additions & 0 deletions jena-arq/testing/ARQ/Lateral/lateral-3.srj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ "head": {
"vars": [ "s" , "z" , "x" , "v" ]
} ,
"results": {
"bindings": [
{
"s": { "type": "uri" , "value": "http://example/z1" } ,
"z": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } ,
"x": { "type": "uri" , "value": "http://example/x1" } ,
"v": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" }
} ,
{
"s": { "type": "uri" , "value": "http://example/x1" } ,
"z": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } ,
"x": { "type": "uri" , "value": "http://example/z1" } ,
"v": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" }
}
]
}
}
7 changes: 7 additions & 0 deletions jena-arq/testing/ARQ/Lateral/lateral-4.arq
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
PREFIX : <http://example/>

SELECT * {
?s :p ?o .
## ?s : in-scope
LATERAL { SELECT ?s ?label { ?s :p ?label } }
}
23 changes: 23 additions & 0 deletions jena-arq/testing/ARQ/Lateral/lateral-4.srj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ "head": {
"vars": [ "s" , "o" , "label" ]
} ,
"results": {
"bindings": [
{
"s": { "type": "uri" , "value": "http://example/s3" } ,
"o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "3" } ,
"label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "3" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s1" } ,
"o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } ,
"label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s2" } ,
"o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "2" } ,
"label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "2" }
}
]
}
}
7 changes: 7 additions & 0 deletions jena-arq/testing/ARQ/Lateral/lateral-5.arq
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
PREFIX : <http://example/>

SELECT * {
?s :p ?o .
## ?s : different scope
LATERAL { SELECT ?label { ?s :p ?label } }
}
53 changes: 53 additions & 0 deletions jena-arq/testing/ARQ/Lateral/lateral-5.srj
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{ "head": {
"vars": [ "s" , "o" , "label" ]
} ,
"results": {
"bindings": [
{
"s": { "type": "uri" , "value": "http://example/s3" } ,
"o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "3" } ,
"label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "3" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s3" } ,
"o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "3" } ,
"label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s3" } ,
"o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "3" } ,
"label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "2" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s1" } ,
"o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } ,
"label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "3" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s1" } ,
"o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } ,
"label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s1" } ,
"o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } ,
"label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "2" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s2" } ,
"o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "2" } ,
"label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "3" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s2" } ,
"o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "2" } ,
"label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" }
} ,
{
"s": { "type": "uri" , "value": "http://example/s2" } ,
"o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "2" } ,
"label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "2" }
}
]
}
}
Loading

0 comments on commit 521ffa2

Please sign in to comment.