Type-ARQuE example transformation: test/ssws2010/type-inference-or.rq (versatile-compact)

SPARQL Query

SELECT ?a ?c
WHERE {
  ?a ?b ?c.
  FILTER (?c=55 || ?c='David')
}
ORDER BY (?c)

Query translated into AQL

(aql-query ("triple_1_1")
           (select "a" (property (string IRI double integer boolean datetime)
                                 "triple_1_1" subject))
           (select "c" (property (string IRI double integer boolean datetime)
                                 "triple_1_1" object))
           (criterion (or (comp-eq (property (string IRI double integer boolean datetime)
                                             "triple_1_1" object)
                                   (literal integer 55))
                          (comp-eq (property (string IRI double integer boolean datetime)
                                             "triple_1_1" object)
                                   (literal string "David"))))
           (sort ascending (property (string IRI double integer boolean datetime)
                                     "triple_1_1" object)))

Lowered and optimized AQL

(aql-query ("triple_1_1")
           (select "a" (custom (IRI)
                               FlexibleSQLLayout::SQLAccessExpr INDEX VC_IRIs.{ix: id, value: iri_value, triple-table-column: subj(subject)} USING JOIN triple_1_1))
           (select "c" (function"builtin:coalesce" (string) ### variant [(string) (string) (string)] : (string)
                                                            (custom (string)
                                                                    FlexibleSQLLayout::SQLAccessExpr INDEX VC_Strings.{ix: id, value: str_value, triple-table-column: obj(object)} USING JOIN triple_1_1)
                                                            (custom (string)
                                                                    FlexibleSQLLayout::SQLAccessExpr INDEX VC_BigStrings.{ix: id, value: text_value, triple-table-column: obj(object)} USING JOIN triple_1_1)
                                                            (function"builtin:to-string" (string IRI double integer boolean datetime)
                                                                                         (custom (integer)
                                                                                                 FlexibleSQLLayout::SQLAccessExpr INDEX VC_Integers.{ix: id, value: int_value, triple-table-column: obj(object)} USING JOIN triple_1_1))))
           (criterion (function"builtin:and" (boolean) ### variant [(boolean) (boolean)] : (boolean)
                                                       (function"builtin:or" (boolean) ### variant [(boolean) (boolean)] : (boolean)
                                                                                       (function"builtin:comp-eq" (boolean) ### variant [(integer) (integer)] : (boolean)
                                                                                                                            (custom (integer)
                                                                                                                                    FlexibleSQLLayout::SQLAccessExpr INDEX VC_Integers.{ix: id, value: int_value, triple-table-column: obj(object)} USING JOIN triple_1_1)
                                                                                                                            (literal integer 55))
                                                                                       (function"builtin:comp-eq" (boolean) ### variant [(string) (string)] : (boolean)
                                                                                                                            (function"builtin:coalesce" (string) ### variant [(string) (string)] : (string)
                                                                                                                                                                 (custom (string)
                                                                                                                                                                         FlexibleSQLLayout::SQLAccessExpr INDEX VC_Strings.{ix: id, value: str_value, triple-table-column: obj(object)} USING JOIN triple_1_1)
                                                                                                                                                                 (custom (string)
                                                                                                                                                                         FlexibleSQLLayout::SQLAccessExpr INDEX VC_BigStrings.{ix: id, value: text_value, triple-table-column: obj(object)} USING JOIN triple_1_1))
                                                                                                                            (literal string "David")))
                                                       (function"builtin:or" (boolean) ### variant [(boolean) (boolean) (boolean)] : (boolean)
                                                                                       (function"builtin:is-not-null" (boolean) ### variant [(string IRI double integer boolean datetime)] : (boolean)
                                                                                                                                (custom (string)
                                                                                                                                        FlexibleSQLLayout::SQLAccessExpr INDEX VC_Strings.{ix: id, value: str_value, triple-table-column: obj(object)} USING JOIN triple_1_1))
                                                                                       (function"builtin:is-not-null" (boolean) ### variant [(string IRI double integer boolean datetime)] : (boolean)
                                                                                                                                (custom (string)
                                                                                                                                        FlexibleSQLLayout::SQLAccessExpr INDEX VC_BigStrings.{ix: id, value: text_value, triple-table-column: obj(object)} USING JOIN triple_1_1))
                                                                                       (function"builtin:is-not-null" (boolean) ### variant [(string IRI double integer boolean datetime)] : (boolean)
                                                                                                                                (custom (integer)
                                                                                                                                        FlexibleSQLLayout::SQLAccessExpr INDEX VC_Integers.{ix: id, value: int_value, triple-table-column: obj(object)} USING JOIN triple_1_1)))))
           (sort ascending (function"builtin:coalesce" (string) ### variant [(string) (string) (string)] : (string)
                                                                (custom (string)
                                                                        FlexibleSQLLayout::SQLAccessExpr INDEX VC_Strings.{ix: id, value: str_value, triple-table-column: obj(object)} USING JOIN triple_1_1)
                                                                (custom (string)
                                                                        FlexibleSQLLayout::SQLAccessExpr INDEX VC_BigStrings.{ix: id, value: text_value, triple-table-column: obj(object)} USING JOIN triple_1_1)
                                                                (function"builtin:to-string" (string IRI double integer boolean datetime)
                                                                                             (custom (integer)
                                                                                                     FlexibleSQLLayout::SQLAccessExpr INDEX VC_Integers.{ix: id, value: int_value, triple-table-column: obj(object)} USING JOIN triple_1_1))))
# Inference map = {
#  triple_1_1.subject: (IRI)
#  triple_1_1.predicate: (IRI)
#  triple_1_1.object: (string integer)
                            )

SQL

SELECT triple_1_1_subj_VC_IRIs.iri_value AS c0,
       COALESCE(triple_1_1_obj_VC_Strings.str_value,triple_1_1_obj_VC_BigStrings.text_value,CAST(triple_1_1_obj_VC_Integers.int_value AS TEXT)) AS c1
  FROM VC_Triples AS triple_1_1
       LEFT JOIN VC_Strings AS triple_1_1_obj_VC_Strings ON triple_1_1_obj_VC_Strings.id=triple_1_1.obj
       LEFT JOIN VC_BigStrings AS triple_1_1_obj_VC_BigStrings ON triple_1_1_obj_VC_BigStrings.id=triple_1_1.obj
       LEFT JOIN VC_Integers AS triple_1_1_obj_VC_Integers ON triple_1_1_obj_VC_Integers.id=triple_1_1.obj
      INNER JOIN VC_IRIs AS triple_1_1_subj_VC_IRIs ON triple_1_1_subj_VC_IRIs.id=triple_1_1.subj
 WHERE (triple_1_1_obj_VC_Integers.int_value=55 OR COALESCE(triple_1_1_obj_VC_Strings.str_value,triple_1_1_obj_VC_BigStrings.text_value)='David') AND (triple_1_1_obj_VC_Strings.str_value IS NOT NULL OR triple_1_1_obj_VC_BigStrings.text_value IS NOT NULL OR triple_1_1_obj_VC_Integers.int_value IS NOT NULL)
ORDER BY COALESCE(triple_1_1_obj_VC_Strings.str_value,triple_1_1_obj_VC_BigStrings.text_value,CAST(triple_1_1_obj_VC_Integers.int_value AS TEXT)) ASC

Execution result

| a                                 | c     |
=============================================
| http://test1.aql-testdata/author4 | 55    |
| http://test1.aql-testdata/author4 | David |

2 rows