<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>RAW-JENA: Approximate Query Processing for SPARQL Endpoints</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Julien Aimonier-Davat</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Minh-Hoang Dang</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Pascal Molli</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Brice Nédelec</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Hala Skaf-Molli</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Nantes Université</institution>
          ,
          <addr-line>CNRS, LS2N, UMR 6004, F-44000 Nantes</addr-line>
          ,
          <country country="FR">France</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>Sampling-based Approximate Query Processing (S-AQP) has many important use cases for RDF, including computing large-scale statistics, embeddings, join orderings, approximate aggregations, summaries, and exploratory queries. However, current SPARQL endpoints have no support for S-AQP, and many queries just time out on public SPARQL endpoints. In this demonstration, we present RAW-JENA: an extension of Apache Jena to support S-AQP for conjunctive SPARQL queries relying on random walks. RAW-JENA delivers partial random results and cardinality estimates in a pay-as-you-go fashion.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;SPARQL</kwd>
        <kwd>Sampling</kwd>
        <kwd>Approximate query processing</kwd>
        <kwd>Random walks</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>Public SPARQL endpoints cannot fully execute many SPARQL queries due to their quotas and
fair-use policies. After 60 seconds, they stop their execution and return only partial results,
forbidding many use cases such as building summaries or computing large-scale statistics. This
constitutes a major issue for building decentralized ecosystems of public SPARQL endpoints.</p>
      <p>
        Sampling-based Approximate Query Processing (S-AQP) [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] tackles this issue for use cases
such as computing large-scale statistics [
        <xref ref-type="bibr" rid="ref2 ref3">2, 3</xref>
        ], knowledge graph embeddings [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], join orders [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ],
approximate aggregations [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], summaries [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ], and exploratory queries [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. By confining query
execution to samples of large datasets, S-AQP drastically reduces execution time,
delivering approximate results with error estimates. To support S-AQP in SPARQL, the evaluation
of such queries must both (i) return random samples, and (ii) comply with fair-use policies
of public SPARQL endpoints. Ad-hoc methods already exist to sample knowledge graphs.
For example, a user could draw random triples from Wikidata [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] by repeatedly executing
SELECT * {?s ?p ?o} OFFSET r LIMIT 1, where  is a random number between 0 and
the dataset size (0 &lt;  &lt; 12). However, all queries time out when  is above 100 . Some
triple stores propose home-made methods for sampling triple patterns1,2, but these solutions
are limited to single triple patterns and the underlying complexity is not established.
      </p>
      <p>In this demonstration, we introduce RAW-JENA, an open source extension of Apache Jena
that eficiently supports S-AQP for conjunctive SPARQL queries. RAW-JENA evaluates a query
}
# tp3
# tp2
# tp1</p>
      <p>A
C</p>
      <p>P17
P641
P17
D
B
E</p>
      <p>P361
P641</p>
      <p>
        (b) RDF Graph 1: , , and  are cycling sports;
 and  are countries of Central America [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ]
 over a dataset  by drawing random walks guided by , as defined in Wander Join [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ].
Random walks have two desirable properties: (i) As each random walk is independent, a user can
distribute its query execution into multiple requests, hence collecting and merging random walks
in a pay-as-you-go fashion without impairing the fair-use policy of public SPARQL endpoints.
(ii) As each random walk enjoys a logarithmic time complexity, endpoints can draw thousands
of random walks per second: the widely used BTree indexes of RDF stores allow endpoints to
compute each random walk in (|| log ||) where || is the number of triple/quad patterns
in  and || is the number of triples/quad in .
      </p>
      <p>
        RAW-JENA produces random partial results instead of complete results. Without cardinality
estimates, users cannot appreciate the quality of provided samples. In Figure 2, RAW-JENA
returns 1434 random results after 35 seconds. By adding an estimate of the total number of
results (26 ± 3 ), the user acknowledges that her sample represents but a tiny fraction of
the whole results. Provided estimates prove highly accurate as long as random walks remain
paired with their probability of being drawn [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ]. Despite starting from 35 ± 15 , RAW-JENA
improved over time, reaching 26 ± 3 while the actual number of results is 25 .
      </p>
      <p>
        For the demonstration, we load the dump of Wikidata provided by WDBench [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ] that
comprises 1.2 triples. We let users choose a query among the 16 that time out on Apache Jena.
We execute it using RAW-JENA to highlight (i) the benefits of S-AQP for ecosystems of public
SPARQL endpoints and (ii) the feasibility of implementing S-AQP on well-known engines.
      </p>
    </sec>
    <sec id="sec-2">
      <title>2. RAW-JENA: RAndom Walks for Apache Jena</title>
      <p>
        RAW-JENA is an open source extension of Apache Jena available on the GitHub platform at
https://github.com/GDD-Nantes/raw-jena. It eficiently supports Sampling-based Approximate
Query Processing (S-AQP) for conjunctive SPARQL queries. This Section provides a formal
framework for sampling and applies it on a small toy example; then it details the benefits of
RAW-JENA on a larger larger example extracted from WDBench [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ]; finally it describes the
demonstration protocol for the live session.
      </p>
      <p>Sampling principles. Let  be a SPARQL conjunctive query, and  = ⟨1, ..., ⟩ be the
join order to perform random walks. A random walk   = ⟨1, ..., ⟩ is computed over an RDF
graph  by randomly picking 1 in J1K, and each subsequent  ( &gt; 1) in J− 1 ◁▷ K.</p>
      <p>
        Once computed, the cardinality of  is estimated as the inverse probability of sampling   [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ],
with  ( ) = |J1K|− 1 ∏︀=2 |J− 1 ◁▷ K|− 1. For instance, let us consider the query 1
and the RDF graph 1 depicted in Figure 1. Following the join order 3, 2, 1, the random
walk  1 is computed as follows:
3
2
1
draw 1
draw 2
draw 3
= (A,  641, 3609)
= (,  17, D)
= (,  361, 27611)
∈ J(?1,  641, 3609)K1
∈ J(A,  17, ?3)K1
∈ J(D,  361, 27611)K1
The cardinality of 1 is then estimated as the inverse probability of sampling  1:
 ( 1)− 1 = |J(?1,  641, 3609)K1 | · | J(A,  17, ?3)K1 | · | J(D,  361, 27611)K1 | = 2 · 1 · 1 = 2
Note that a random walk may fail if it becomes impossible to sample  for some  ≤ . In
this case, its probability  ( ) of being sampled is 0. For instance, if 1 = (,  641, 3609)
is picked in J(?1,  641, 3609)K1 instead of (,  641, 3609), then the random walk fails
because J(,  17, ?3)K1 = ∅. To improve the quality of estimates, we compute a set of 
random walks Γ = ⟨ 1, ...,  ⟩, and the cardinality of  is estimated as |Γ|− 1 ∑︀|Γ=|1  ( )− 1.
RAW-JENA in action (https://youtu.be/We5-rG6uxN8). We executed the query 604 of
WDBench [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ] presented in Figure 2 that searches for people with the same dates of birth and
death. 604 expects 25 results, but times out on the public Wikidata SPARQL endpoint after
60 seconds; and takes longer than 2 hours to complete on Apache Jena.
      </p>
      <p>Each time the user presses the play button, RAW-JENA computes either 10 random walks or
as many as possible before reaching 60 seconds of execution time. By repeating the operation,
the web client merges the results iteratively in a pay-as-you-go fashion.</p>
      <p>The bottom panel of Figure 2 displays both succeeded and failed random walks   with their
respective probability of being drawn  ( ). Increasing the number of random walks allows
for displaying more accurate estimates. The left panel of Figure 2 presents the evolution of
cardinality estimates and confidence intervals with respect to the number of random walks.
The 1 iteration provides a rough estimate of 35 ± 15 expected results. After 35 seconds of
execution time and 100 random walks, the 10ℎ iteration provides a more accurate estimate of
26 ± 3 of expected results and 1434 actual random results. The right panel of Figure 2 displays
the join order with (i) the estimated cardinality of the partial query up to each triple/quad
pattern, and (ii) the number of random walks that reached each triple/quad pattern. Among
100 random walks launched on 1, only 1434 reached 6. This hints that the join order
might be suboptimal since 5 is very selective and makes random walks fail.
This example shows how S-AQP can be used for exploratory queries and optimization.
Nevertheless, S-AQP also provides opportunities for computing large-scale statistics, embeddings, or
summaries.</p>
      <p>
        Live demonstration. During the session, we start a local RAW-JENA server on the dataset
of WDBench [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ] that comprises 1.2 triples extracted from Wikidata. We present the Web
interface of RAW-JENA depicted in Figure 2. The user can choose a query among a predefined
set of conjunctive queries that timed out using Apache Jena; or even type her own.
We show that using RAW-JENA, after a second of execution time, the user already gets
meaningful insights on her query execution. Together, we analyze query plan Web view that highlights
where random walks succeeded or failed. We deduce a better join order, emphasizing the
benefits of S-AQP for this first use case.
      </p>
      <p>
        Afterwards, we further show the advantages of pay-as-you-go approaches by starting and
stopping the query execution multiple times until reaching the 60 seconds timeout mark of
public SPARQL endpoints. The Web client manages to receive and aggregate incoming data,
thus providing an estimate of the expected number of results. The cardinality estimation view
allows users to observe the accuracy evolution over time. The estimates and confidence intervals
converge towards the actual number of results of her query. This demonstrates the approximate
aggregations use case [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] that proves useful for numerous other use cases such as exploratory
queries [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ].
      </p>
      <p>
        Finally, we show that RAW-JENA returns both failed and succeeded random walks along with
their probability of being drawn which enables use cases such as the computation of knowledge
graph embeddings [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], or summaries [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ].
      </p>
    </sec>
    <sec id="sec-3">
      <title>3. Conclusion</title>
      <p>S-AQP has many important use cases crucial for building and maintaining ecosystems of public
SPARQL endpoints. RAW-JENA demonstrates the feasibility of implementing S-AQP on a
representative SPARQL endpoint: Apache Jena. As each random walk is independent and enjoys
a logarithmic upper bound on its time complexity, users can collect and merge samples across
multiple executions of the same query. Such a pay-as-you-go approach perfectly fits the fair-use
policies of public SPARQL endpoints.</p>
      <p>In future works, we plan to support full SPARQL queries and to show how the SPARQL standard
could evolve to integrate sampling as SQL did with the TABLESAMPLE clause.</p>
    </sec>
    <sec id="sec-4">
      <title>Acknowledgments</title>
      <p>This work is supported by the French ANR project DeKaloG (Decentralized Knowledge Graphs)
ANR-19-CE23-0014, and the French Labex CominLabs project MiKroloG (The Microdata
Knowledge Graph).</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>S.</given-names>
            <surname>Agarwal</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Milner</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Kleiner</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Talwalkar</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M. I.</given-names>
            <surname>Jordan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Madden</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Mozafari</surname>
          </string-name>
          ,
          <string-name>
            <surname>I. Stoica</surname>
          </string-name>
          ,
          <article-title>Knowing when you're wrong: Building fast and reliable approximate query processing systems</article-title>
          ,
          <source>in: International Conference on Management of Data, SIGMOD</source>
          ,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>A.</given-names>
            <surname>Soulet</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F. M.</given-names>
            <surname>Suchanek</surname>
          </string-name>
          ,
          <article-title>Anytime large-scale analytics of Linked Open Data</article-title>
          , in: 18th International Semantic Web Conference, ISWC,
          <year>2019</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>J.</given-names>
            <surname>Debattista</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Londoño</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Lange</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Auer</surname>
          </string-name>
          ,
          <article-title>Quality assessment of linked datasets using probabilistic approximation</article-title>
          ,
          <source>in: 12th European Semantic Web Conference on The Semantic Web. Latest Advances and New Domains</source>
          ,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>P.</given-names>
            <surname>Ristoski</surname>
          </string-name>
          , H. Paulheim,
          <article-title>RDF2Vec: RDF graph embeddings for data mining</article-title>
          ,
          <source>in: 15th International Semantic Web Conference</source>
          , ISWC,
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>V.</given-names>
            <surname>Leis</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Radke</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Gubichev</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Kemper</surname>
          </string-name>
          , T. Neumann,
          <article-title>Cardinality estimation done right: Index-based join sampling</article-title>
          ,
          <source>in: Cidr</source>
          ,
          <year>2017</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>Y.</given-names>
            <surname>Wang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Khan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>X.</given-names>
            <surname>Xu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Ye</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Pan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Y.</given-names>
            <surname>Zhou</surname>
          </string-name>
          ,
          <article-title>Approximate and interactive processing of aggregate queries on knowledge graphs: A demonstration</article-title>
          ,
          <source>in: 31st ACM International Conference on Information &amp; Knowledge Management</source>
          ,
          <year>2022</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>L.</given-names>
            <surname>Heling</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Acosta</surname>
          </string-name>
          ,
          <article-title>Estimating characteristic sets for RDF dataset profiles based on sampling</article-title>
          ,
          <source>in: The Semantic Web: 17th International Conference, ESWC</source>
          ,
          <year>2020</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>F.</given-names>
            <surname>Li</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Wu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Yi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Z.</given-names>
            <surname>Zhao</surname>
          </string-name>
          ,
          <article-title>Wander Join and XDB: online aggregation via random walks</article-title>
          ,
          <source>ACM Transactions Database Systems</source>
          (
          <year>2019</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>Y.</given-names>
            <surname>Park</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Ko</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S. S.</given-names>
            <surname>Bhowmick</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Kim</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Hong</surname>
          </string-name>
          , W. Han,
          <string-name>
            <surname>G</surname>
          </string-name>
          -CARE:
          <article-title>A framework for performance benchmarking of cardinality estimation techniques for subgraph matching</article-title>
          ,
          <source>in: International Conference on Management of Data, SIGMOD</source>
          ,
          <year>2020</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>R.</given-names>
            <surname>Angles</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C. B.</given-names>
            <surname>Aranda</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Hogan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Rojas</surname>
          </string-name>
          , D. Vrgoč,
          <article-title>WDBench: A Wikidata graph query benchmark</article-title>
          , in: International Semantic Web Conference,
          <year>2022</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>J.</given-names>
            <surname>Aimonier-Davat</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Skaf-Molli</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Molli</surname>
          </string-name>
          ,
          <string-name>
            <surname>M.-H. Dang</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          <string-name>
            <surname>Nédelec</surname>
          </string-name>
          ,
          <article-title>Join ordering of SPARQL property path queries</article-title>
          ,
          <source>in: The Semantic Web: 20th International Conference, ESWC</source>
          ,
          <year>2023</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>