Type-ARQuE example transformation: test/ssws2010/cyganiak-filter-scope.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 .
	           FILTER (?b = 'David') }
}

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"))
                           (comp-eq (property (string IRI double integer boolean datetime)
                                              "triple_1_1" object)
                                    (literal string "David"))))
           (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)] : (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"))
                                                       (function"builtin:comp-eq" (boolean) ### variant [(string) (string)] : (boolean)
                                                                                            (custom (string)
                                                                                                    FlexibleSQLLayout::SQLAccessExpr INLINE obj_value USING JOIN triple_1_1)
                                                                                            (literal string "David")))
# Inference map = {
#  triple_2_1.subject: (IRI)
#  triple_2_1.predicate: (IRI)
#  triple_2_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' AND triple_1_1.obj_value='David'
 WHERE triple_1_1.pred_value='http://test1.aql-testdata/p/firstname'

Execution result

| a                                 | b        | c      |
=========================================================
| http://test1.aql-testdata/author1 | Anne     | (null) |
| http://test1.aql-testdata/author2 | Beatrice | (null) |
| http://test1.aql-testdata/author3 | Chuck    | (null) |
| http://test1.aql-testdata/author4 | David    | Daft   |

4 rows