Type-ARQuE example transformation: test/ssws2010/type-inference-parent-restriction.rq (versatile-compact)
SPARQL Query
SELECT *
WHERE {
?a ?b ?c.
OPTIONAL {
?c ?d ?e.
}
FILTER(?a=<http://test1.aql-testdata/author4>)
FILTER(?e>='9')
}
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" predicate))
(select "c" (property (string IRI double integer boolean datetime)
"triple_1_1" object))
(select "d" (property (string IRI double integer boolean datetime)
"triple_2_1" predicate))
(select "e" (property (string IRI double integer boolean datetime)
"triple_2_1" object))
(join left ("triple_2_1")
(comp-eq (property (string IRI double integer boolean datetime)
"triple_2_1" subject)
(property (string IRI double integer boolean datetime)
"triple_1_1" object)))
(criterion (and (comp-eq (property (string IRI double integer boolean datetime)
"triple_1_1" subject)
(literal IRI "http://test1.aql-testdata/author4"))
(comp-ge (property (string IRI double integer boolean datetime)
"triple_2_1" object)
(literal string "9")))))
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 "b" (custom (IRI)
FlexibleSQLLayout::SQLAccessExpr INDEX VC_IRIs.{ix: id, value: iri_value, triple-table-column: pred(predicate)} USING JOIN triple_1_1))
(select "c" (function"builtin:coalesce" (string) ### variant [(string) (string) (string) (string) (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 (IRI)
FlexibleSQLLayout::SQLAccessExpr INDEX VC_IRIs.{ix: id, value: iri_value, triple-table-column: obj(object)} USING JOIN triple_1_1))
(function"builtin:to-string" (string IRI double integer boolean datetime)
(custom (double)
FlexibleSQLLayout::SQLAccessExpr INDEX VC_Doubles.{ix: id, value: double_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))
(function"builtin:to-string" (string IRI double integer boolean datetime)
(custom (boolean)
FlexibleSQLLayout::SQLAccessExpr INDEX VC_Booleans.{ix: id, value: boolean_value, triple-table-column: obj(object)} USING JOIN triple_1_1))
(function"builtin:to-string" (string IRI double integer boolean datetime)
(custom (datetime)
FlexibleSQLLayout::SQLAccessExpr INDEX VC_Datetimes.{ix: id, value: datetime_value, triple-table-column: obj(object)} USING JOIN triple_1_1))))
(select "d" (custom (IRI)
FlexibleSQLLayout::SQLAccessExpr INDEX VC_IRIs.{ix: id, value: iri_value, triple-table-column: pred(predicate)} USING JOIN triple_2_1))
(select "e" (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_2_1)
(custom (string)
FlexibleSQLLayout::SQLAccessExpr INDEX VC_BigStrings.{ix: id, value: text_value, triple-table-column: obj(object)} 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 USING JOIN triple_2_1)
(custom (integer)
FlexibleSQLLayout::SQLAccessExpr INLINE obj USING JOIN triple_1_1))
(function"builtin:or" (boolean) ### variant [(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_2_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_2_1))))
# Inference map = {
# triple_2_1.subject: (IRI)
# triple_2_1.predicate: (IRI)
# triple_2_1.object: (string)
)
(criterion (function"builtin:and" (boolean) ### variant [(boolean) (boolean)] : (boolean)
(function"builtin:comp-eq" (boolean) ### variant [(IRI) (IRI)] : (boolean)
(custom (IRI)
FlexibleSQLLayout::SQLAccessExpr INDEX VC_IRIs.{ix: id, value: iri_value, triple-table-column: subj(subject)} USING JOIN triple_1_1)
(literal IRI "http://test1.aql-testdata/author4"))
(function"builtin:comp-ge" (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_2_1)
(custom (string)
FlexibleSQLLayout::SQLAccessExpr INDEX VC_BigStrings.{ix: id, value: text_value, triple-table-column: obj(object)} USING JOIN triple_2_1))
(literal string "9"))))
# 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_VC_IRIs.iri_value AS c0,
triple_1_1_pred_VC_IRIs.iri_value AS c1,
COALESCE(triple_1_1_obj_VC_Strings.str_value,triple_1_1_obj_VC_BigStrings.text_value,triple_1_1_obj_VC_IRIs.iri_value,CAST(triple_1_1_obj_VC_Doubles.double_value AS TEXT),CAST(triple_1_1_obj_VC_Integers.int_value AS TEXT),aqltosql_boolean_to_text(triple_1_1_obj_VC_Booleans.boolean_value),aqltosql_timestamp_to_text(triple_1_1_obj_VC_Datetimes.datetime_value)) AS c2,
triple_2_1_pred_VC_IRIs.iri_value AS c3,
COALESCE(triple_2_1_obj_VC_Strings.str_value,triple_2_1_obj_VC_BigStrings.text_value) AS c4
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_IRIs AS triple_1_1_obj_VC_IRIs ON triple_1_1_obj_VC_IRIs.id=triple_1_1.obj
LEFT JOIN VC_Doubles AS triple_1_1_obj_VC_Doubles ON triple_1_1_obj_VC_Doubles.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
LEFT JOIN VC_Booleans AS triple_1_1_obj_VC_Booleans ON triple_1_1_obj_VC_Booleans.id=triple_1_1.obj
LEFT JOIN VC_Datetimes AS triple_1_1_obj_VC_Datetimes ON triple_1_1_obj_VC_Datetimes.id=triple_1_1.obj
INNER JOIN VC_IRIs AS triple_1_1_pred_VC_IRIs ON triple_1_1_pred_VC_IRIs.id=triple_1_1.pred
INNER JOIN VC_IRIs AS triple_1_1_subj_VC_IRIs ON triple_1_1_subj_VC_IRIs.id=triple_1_1.subj
LEFT JOIN (VC_Triples AS triple_2_1
LEFT JOIN VC_Strings AS triple_2_1_obj_VC_Strings ON triple_2_1_obj_VC_Strings.id=triple_2_1.obj
LEFT JOIN VC_BigStrings AS triple_2_1_obj_VC_BigStrings ON triple_2_1_obj_VC_BigStrings.id=triple_2_1.obj
INNER JOIN VC_IRIs AS triple_2_1_pred_VC_IRIs ON triple_2_1_pred_VC_IRIs.id=triple_2_1.pred)
ON triple_2_1.subj=triple_1_1.obj AND (triple_2_1_obj_VC_Strings.str_value IS NOT NULL OR triple_2_1_obj_VC_BigStrings.text_value IS NOT NULL)
WHERE triple_1_1_subj_VC_IRIs.iri_value='http://test1.aql-testdata/author4' AND COALESCE(triple_2_1_obj_VC_Strings.str_value,triple_2_1_obj_VC_BigStrings.text_value)>='9'
Execution result
| a | b | c | d | e |
===================================================================================================================================================================
| http://test1.aql-testdata/author4 | http://test1.aql-testdata/p/author-of | http://test1.aql-testdata/book4 | http://test1.aql-testdata/p/isbn | 9-111-444-333 |
| http://test1.aql-testdata/author4 | http://test1.aql-testdata/p/author-of | http://test1.aql-testdata/book4 | http://test1.aql-testdata/p/title | Bar-Master |
2 rows