Type-ARQuE example transformation: test/ssws2010/cyganiak-joins-with-missing-information.rq (simple-inline)

SPARQL Query

SELECT DISTINCT ?a ?firstNameOrTitle
WHERE { ?a ?b ?c
	OPTIONAL { ?a <http://test1.aql-testdata/p/firstname> ?firstNameOrTitle }
	OPTIONAL { ?a <http://test1.aql-testdata/p/title> ?firstNameOrTitle }
}

Query translated into AQL

(aql-query ("triple_1_1")
           (distinct)
           (select "a" (property (string IRI double integer boolean datetime)
                                 "triple_1_1" subject))
           (select "firstNameOrTitle" (function"builtin:coalesce" (string IRI double integer boolean datetime)
                                                                  (property (string IRI double integer boolean datetime)
                                                                            "triple_2_1" object)
                                                                  (property (string IRI double integer boolean datetime)
                                                                            "triple_3_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/firstname"))))
           (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_1_1" subject))
                           (comp-eq (property (string IRI double integer boolean datetime)
                                              "triple_3_1" predicate)
                                    (literal IRI "http://test1.aql-testdata/p/title"))
                           (or (function"builtin:is-null" (string IRI double integer boolean datetime)
                                                          (property (string IRI double integer boolean datetime)
                                                                    "triple_2_1" object))
                               (comp-eq (property (string IRI double integer boolean datetime)
                                                  "triple_3_1" object)
                                        (property (string IRI double integer boolean datetime)
                                                  "triple_2_1" object)))))
           (criterion))

Lowered and optimized AQL

(aql-query ("triple_1_1")
           (distinct)
           (select "a" (custom (IRI)
                               FlexibleSQLLayout::SQLAccessExpr INLINE subj_value USING JOIN triple_1_1))
           (select "firstNameOrTitle" (function"builtin:coalesce" (string) ### variant [(string) (string)] : (string)
                                                                           (custom (string)
                                                                                   FlexibleSQLLayout::SQLAccessExpr INLINE obj_value USING JOIN triple_2_1)
                                                                           (custom (string)
                                                                                   FlexibleSQLLayout::SQLAccessExpr INLINE obj_value USING JOIN triple_3_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/firstname")))
# 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)
                                                       (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_1_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/title"))
                                                       (function"builtin:or" (boolean) ### variant [(boolean) (boolean)] : (boolean)
                                                                                       (function"builtin:is-null" (boolean) ### variant [(string IRI double integer boolean datetime)] : (boolean)
                                                                                                                            (custom (string)
                                                                                                                                    FlexibleSQLLayout::SQLAccessExpr INLINE obj_value USING JOIN triple_2_1))
                                                                                       (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_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 (literal boolean true))
# Inference map = {
#  triple_1_1.subject: (IRI)
#  triple_1_1.predicate: (IRI)
#  triple_1_1.object: (string IRI double integer boolean datetime)
                       )

SQL

SELECT DISTINCT triple_1_1.subj_value AS c0,
       COALESCE(triple_2_1.obj_value,triple_3_1.obj_value) AS c1
  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/firstname'
       LEFT JOIN InlinedTriples AS triple_3_1 ON triple_3_1.subj_value=triple_1_1.subj_value AND triple_3_1.pred_value='http://test1.aql-testdata/p/title' AND (triple_2_1.obj_value IS NULL OR triple_3_1.obj_value=triple_2_1.obj_value)
 WHERE TRUE

Execution result

| a                                 | firstNameOrTitle           |
==================================================================
| http://test1.aql-testdata/book5   | Bar-Master (bootleg)       |
| http://test1.aql-testdata/book2   | The Book of Blah           |
| http://test1.aql-testdata/book1   | The Great Book of Nonsense |
| http://test1.aql-testdata/book4   | Bar-Master                 |
| http://test1.aql-testdata/author1 | Anne                       |
| http://test1.aql-testdata/author4 | David                      |
| http://test1.aql-testdata/book3   | The Art of Foo             |
| http://test1.aql-testdata/author2 | Beatrice                   |
| http://test1.aql-testdata/author3 | Chuck                      |

9 rows