Type-ARQuE example transformation: test/ssws2010/cyganiak-nested-optionals.rq (simple-inline)
SPARQL Query
SELECT ?a ?b ?c
WHERE {
?a <http://test1.aql-testdata/p/firstname> ?b
OPTIONAL {
?a <http://test1.aql-testdata/p/lastname> ?c .
OPTIONAL { ?a <http://test1.aql-testdata/p/age> ?b }
}
}
Query translated into AQL
(aql-query ("triple_1_1")
(select "a" (property (string IRI double integer boolean datetime)
"triple_1_1" subject))
(select "b" (property (string IRI double integer boolean datetime)
"triple_1_1" object))
(select "c" (property (string IRI double integer boolean datetime)
"triple_2_1" object))
(join left ("triple_2_1")
(and (comp-eq (property (string IRI double integer boolean datetime)
"triple_2_1" subject)
(property (string IRI double integer boolean datetime)
"triple_1_1" subject))
(comp-eq (property (string IRI double integer boolean datetime)
"triple_2_1" predicate)
(literal IRI "http://test1.aql-testdata/p/lastname")))
(join left ("triple_3_1")
(and (comp-eq (property (string IRI double integer boolean datetime)
"triple_3_1" subject)
(property (string IRI double integer boolean datetime)
"triple_2_1" subject))
(comp-eq (property (string IRI double integer boolean datetime)
"triple_3_1" predicate)
(literal IRI "http://test1.aql-testdata/p/age"))
(comp-eq (property (string IRI double integer boolean datetime)
"triple_3_1" object)
(property (string IRI double integer boolean datetime)
"triple_1_1" object)))))
(criterion (comp-eq (property (string IRI double integer boolean datetime)
"triple_1_1" predicate)
(literal IRI "http://test1.aql-testdata/p/firstname"))))
Lowered and optimized AQL
(aql-query ("triple_1_1")
(select "a" (custom (IRI)
FlexibleSQLLayout::SQLAccessExpr INLINE subj_value USING JOIN triple_1_1))
(select "b" (custom (string)
FlexibleSQLLayout::SQLAccessExpr INLINE obj_value USING JOIN triple_1_1))
(select "c" (custom (string)
FlexibleSQLLayout::SQLAccessExpr INLINE obj_value USING JOIN triple_2_1))
(join left ("triple_2_1")
(function"builtin:and" (boolean) ### variant [(boolean) (boolean)] : (boolean)
(function"builtin:comp-eq" (boolean) ### variant [(reference) (reference)] : (boolean)
(custom (integer)
FlexibleSQLLayout::SQLAccessExpr INLINE subj_value USING JOIN triple_2_1)
(custom (integer)
FlexibleSQLLayout::SQLAccessExpr INLINE subj_value USING JOIN triple_1_1))
(function"builtin:comp-eq" (boolean) ### variant [(IRI) (IRI)] : (boolean)
(custom (IRI)
FlexibleSQLLayout::SQLAccessExpr INLINE pred_value USING JOIN triple_2_1)
(literal IRI "http://test1.aql-testdata/p/lastname")))
# Inference map = {
# triple_2_1.subject: (IRI)
# triple_2_1.predicate: (IRI)
# triple_2_1.object: (string IRI double integer boolean datetime)
)
(join left ("triple_3_1")
(function"builtin:and" (boolean) ### variant [(boolean) (boolean) (boolean) (boolean)] : (boolean)
(function"builtin:comp-eq" (boolean) ### variant [(reference) (reference)] : (boolean)
(custom (integer)
FlexibleSQLLayout::SQLAccessExpr INLINE subj_value USING JOIN triple_3_1)
(custom (integer)
FlexibleSQLLayout::SQLAccessExpr INLINE subj_value USING JOIN triple_2_1))
(function"builtin:comp-eq" (boolean) ### variant [(IRI) (IRI)] : (boolean)
(custom (IRI)
FlexibleSQLLayout::SQLAccessExpr INLINE pred_value USING JOIN triple_3_1)
(literal IRI "http://test1.aql-testdata/p/age"))
(function"builtin:comp-eq" (boolean) ### variant [(reference) (reference)] : (boolean)
(custom (integer)
FlexibleSQLLayout::SQLAccessExpr INLINE obj_value USING JOIN triple_3_1)
(custom (integer)
FlexibleSQLLayout::SQLAccessExpr INLINE obj_value USING JOIN triple_1_1))
(function"builtin:is-not-null" (boolean) ### variant [(string IRI double integer boolean datetime)] : (boolean)
(custom (integer)
FlexibleSQLLayout::SQLAccessExpr INLINE subj_value USING JOIN triple_2_1)))
# Inference map = {
# triple_3_1.subject: (IRI)
# triple_3_1.predicate: (IRI)
# triple_3_1.object: (string IRI double integer boolean datetime)
)
(criterion (function"builtin:comp-eq" (boolean) ### variant [(IRI) (IRI)] : (boolean)
(custom (IRI)
FlexibleSQLLayout::SQLAccessExpr INLINE pred_value USING JOIN triple_1_1)
(literal IRI "http://test1.aql-testdata/p/firstname")))
# Inference map = {
# triple_1_1.subject: (IRI)
# triple_1_1.predicate: (IRI)
# triple_1_1.object: (string IRI double integer boolean datetime)
)
SQL
SELECT triple_1_1.subj_value AS c0,
triple_1_1.obj_value AS c1,
triple_2_1.obj_value AS c2
FROM InlinedTriples AS triple_1_1
LEFT JOIN InlinedTriples AS triple_2_1 ON triple_2_1.subj_value=triple_1_1.subj_value AND triple_2_1.pred_value='http://test1.aql-testdata/p/lastname'
LEFT JOIN InlinedTriples AS triple_3_1 ON triple_3_1.subj_value=triple_2_1.subj_value AND triple_3_1.pred_value='http://test1.aql-testdata/p/age' AND triple_3_1.obj_value=triple_1_1.obj_value AND triple_2_1.subj_value IS NOT NULL
WHERE triple_1_1.pred_value='http://test1.aql-testdata/p/firstname'
Execution result
| a | b | c |
============================================================
| http://test1.aql-testdata/author1 | Anne | Aadolfson |
| http://test1.aql-testdata/author2 | Beatrice | Beowulf |
| http://test1.aql-testdata/author3 | Chuck | Chorris |
| http://test1.aql-testdata/author4 | David | Daft |
4 rows