DAWG Query Sketch Test Cases

Abstract. This document lists a selection of queries that have been used in the discussions of the RDF Data Access Working Group.

Version 0.3, 23-06-2004

1. Query Testcases

The queries are given in an abstract query syntax, listing triples with variables to be bound and qnames. These triples that match a subgraph of the RDF graph to be queried and are listed, followed by and constrinats that apply to the variables. Variables are prefixed by the ? character.

1.1 Variable v's constant comparisons

Discussed at the 1st face to face meeting.

Purpose

This query highlights the difference in execution-complexity between two superficially similar queries.

Query

In this query the number of possbile matches for the constraint section gorws with |?x| × |?y| whereas with a fixed operand (as in ?xAge < 18) the number of possible matches grows with |?x|.

?x :marriedTo ?y
?x :age ?xAge
?y :age ?yAge

?xAge < ?yAge

1.2 Disjunstion

From http://lists.w3.org/Archives/Public/public-rdf-dawg/2004AprJun/0630.html

Purpose

Demonstrates disjustion operation

Data

A0 p1 B A1 p2 C A2 p3 D A3 p2 C A3 p3 D

Query

?n p2 C || ?n p3 D

Triple results

A1 p2 C A2 p3 D A3 p2 C A3 p3 D

1.3 Nested optional arcs

From http://lists.w3.org/Archives/Public/public-rdf-dawg/2004AprJun/0598.html

Purpose

Demonstrates possible results for nested optional subgraphs.

Data

A p1 B # truncates on optional 1 term 1
A p2 C
A2 p1 B # truncates on optional term 2
A2 p2 C
A2 p3 D2
D2 p4 E2
A3 p1 B # eliminates second optional
A3 p2 C
A3 p3 D3
D3 p4 E3
D3 p5 F3
A4 p1 B # has all arcs
A4 p2 C
A4 p3 D4
D4 p4 E4
D4 p5 F4
D4 p6 F4

Query

(~ indicates optional subgraph)

?n p1 B
?n p2 C
~(?n ?p3 ?d
  ?d p4 ?e
  ?d p5 ?f
  ~(?d p6 ?g))

Results

+----------+----------+----------+----------+----------+
| n| d| e| f| g|
+----------+----------+----------+----------+----------+
| A| NULL| NULL| NULL| NULL|
| A2| NULL| NULL| NULL| NULL|
| A3| D3| E3| F3| NULL|
| A4| D4| E4| F4| F4|
+----------+----------+----------+----------+----------+

1.4 Optional triples

Purpose

Demonstrates possible bindings for queries containing optional components. From http://lists.w3.org/Archives/Public/public-rdf-dawg/2004AprJun/0652.html

Data

:x :p :a :x :q :b

Query A

[] indicates optional triples

[(:x :p ?v)] [(:x :q ?v)]

Results A

+--------+ | v | +--------+ | :a | matches the first part but then the second can't match | :b | matches the second part but not the first +--------+

Query B

[(:x :p ?v) (:x :q ?v)]

Results B

has no match

1.5 Optional triples

Purpose

Demonstrates simple, partial matching case. From http://lists.w3.org/Archives/Public/public-rdf-dawg/2004JulSep/0044.html.

Data

http://jena.hpl.hp.com/~afs/DAWG/Tests/dawg-data-01.n3

Query

http://jena.hpl.hp.com/~afs/DAWG/Tests/dawg-query-001 (BRQL syntax)

(?person foaf:name ?name) [(?person foaf:mbox ?mbox)]

Results

http://jena.hpl.hp.com/~afs/DAWG/Tests/dawg-result-001.n3

+-------------------------------+ | name | mbox | +-------------------------------+ | "Bob" | <mailto:bob@work> | | "Bob" | <mailto:bob@home> | | "Eve" | null | | "Alice" | <mailto:alice@work> | +---------+---------------------+

1.6 Optional triples

Purpose

Demonstrates multi-triple graph pattern in optional part. This leads to a need for nested optionals: get the name or mbox of any people known by people in the FOAF datafile. From http://lists.w3.org/Archives/Public/public-rdf-dawg/2004JulSep/0044.html.

Data

http://jena.hpl.hp.com/~afs/DAWG/Tests/dawg-data-01.n3

Query

http://jena.hpl.hp.com/~afs/DAWG/Tests/dawg-query-002 (BRQL syntax)

(?person foaf:name ?name) [(?person foaf:knowns ?p2) (?p2 foaf:name ?name2)]

Results

http://jena.hpl.hp.com/~afs/DAWG/Tests/dawg-result-002.n3

+---------+-----------+ | name | name2 | +---------+-----------+ | "Bob" | "Alice" | | "Alice" | "Bob" | | "Eve" | null | +---------+-----------+

1.7 Optional triples

Purpose

Demonstrates multiple, independent optional clauses. From http://lists.w3.org/Archives/Public/public-rdf-dawg/2004JulSep/0044.html.

Data

http://jena.hpl.hp.com/~afs/DAWG/Tests/dawg-data-01.n3

Query

http://jena.hpl.hp.com/~afs/DAWG/Tests/dawg-query-003 (BRQL syntax)

(?person rdf:type foaf:Person) [(?person foaf:name ?name)] [(?person foaf:mbox ?mbox)]

Results

http://jena.hpl.hp.com/~afs/DAWG/Tests/dawg-result-003.n3

+-----------+---------------------+ | name | mbox | +-----------+---------------------+ | "Bob" | <mailto:bob@home> | | "Bob" | <mailto:bob@work> | | null | <fred@edu> | | "Eve" | null | | "Alice" | <mailto:alice@work> | +-----------+---------------------+