-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1926 lines (1769 loc) · 73.6 KB
/
index.html
File metadata and controls
1926 lines (1769 loc) · 73.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>RDF/JS: Query specification</title>
<script src="https://www.w3.org/Tools/respec/respec-w3c-common" class="remove"></script>
<script class="remove">
var respecConfig = {
specStatus: "CG-DRAFT",
shortName: "rdfjs",
subtitle: "RDF/JS: Query specification",
processVersion: 2020,
edDraftURI: "https://github.com/rdfjs/query-spec/",
issueBase: "https://github.com/rdfjs/query-spec/issues/",
githubAPI: "https://api.github.com/repos/rdfjs/query-spec",
// TODO: testSuiteURIkey: "",
editors: [
{
name: "Ruben Taelman",
url: "https://www.rubensworks.net/#me",
company: "Ghent University – imec",
companyURL: "http://idlab.ugent.be/",
w3cid: 84199
},
{
name: "Jacopo Scazzosi",
url: "https://jacoscaz.com/#me",
company: "Belay Engineering s.r.l.",
companyURL: "https://belayeng.com/",
w3cid: 72858
}
],
authors: [
{
name: "Ruben Taelman",
url: "https://www.rubensworks.net/#me",
company: "Ghent University – imec",
companyURL: "http://idlab.ugent.be/",
w3cid: 84199
},
{
name: "Jacopo Scazzosi",
url: "https://jacoscaz.com/#me",
company: "Belay Engineering s.r.l.",
companyURL: "https://belayeng.com/",
w3cid: 72858
}
],
bugTracker: {
open: "https://github.com/rdfjs/query-spec/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20",
new: "https://github.com/rdfjs/query-spec/issues/new"
},
otherLinks: [{
key: "Version control",
data: [{
value: "Github Repository",
href: "https://github.com/rdfjs/query-spec"
}]
}],
wg: "RDF JavaScript Libraries Community Group",
wgURI: "https://www.w3.org/community/rdfjs/",
wgPublicList: "public-rdfjs",
maxTocLevel: 2
};
</script>
</head>
<body>
<section id="abstract">
<h2>Abstract</h2>
<p>
The scope of this specification is to provide a way to query over RDF quads in JavaScript, as defined in the <a href="http://rdf.js.org/data-model-spec/#quad-interface">RDF/JS: Data model specification</a>.
It contains high-level interfaces for libraries that want to expose querying capabilities,
and low-level interfaces for working across query engine components.
</p>
</section>
<section id="sotd">
<p>
This document provides a specification of an interface for RDF query engines in a JavaScript environment.
The task force which defines this interface was formed by RDF JavaScript library developers with the wish to make existing
and future libraries interoperable. This definition strives to provide the minimal necessary
interface to enable interoperability of RDF querying libraries.
</p>
<p>
<strong>Currently, this specification provides high-level interfaces such as <code>Queryable</code> for exposing querying capabilities,
and low-level interfaces such as <code>FilterableSource</code> for interoperability across query engines.</strong>
</p>
</section>
<section>
<h2>Design elements and principles</h2>
<ul>
<li><em>All <a href="http://rdf.js.org/data-model-spec/#design-elements-and-principles">design elements and principles from the RDF/JS data model specification</a> apply here as well.</em></li>
<li>Interfaces do not conflict with other RDF/JS interfaces, and users and implementers of purely other RDF/JS interfaces should not be aware of the interfaces in this specification if they are not needed.</li>
<li>Data interfaces should not contain methods, as to enable straightforward transmission over low-level communication protocols such as Web Assembly.</li>
<li>To enable querying over large graphs, interfaces should handle quads in a streaming manner, such as the <a href="https://rdf.js.org/stream-spec/">RDF/JS stream interfaces</a>.</li>
</ul>
</section>
<section>
<h2>SPARQL Queryable interfaces</h2>
This section introduces queryable interfaces that can be implemented by SPARQL-constrained query engines.
These interfaces guarantees that result objects are of the expected type as defined by the SPARQL spec,
and is often more convenient to use compared to the general queryable interfaces.
<section data-dfn-for="StringSparqlQueryable">
<h3><dfn>StringSparqlQueryable</dfn> interface</h3>
<pre class="idl">
interface StringSparqlQueryable {
optional Promise<Stream<Bindings>> queryBindings(String query, QueryStringContext? context);
optional Promise<Stream<Quad>> queryQuads(String query, QueryStringContext? context);
optional Promise<boolean> queryBoolean(String query, QueryStringContext? context);
optional Promise<void> queryVoid(String query, QueryStringContext? context);
};
</pre>
<p>
A <code>StringSparqlQueryable</code> can be implemented by objects that want to expose a SPARQL-constrained query execution interface
that accepts queries as a string.
</p>
<p>
<dfn>queryBindings()</dfn> is an optional method that asynchronously returns a <a href="https://rdf.js.org/stream-spec/#stream-interface">Stream</a> of <a>Bindings</a> objects.
<dfn>query</dfn> is a query string that SHOULD be a SPARQL <code>SELECT</code> query.
<dfn>context</dfn> is an optional context in which query execution options can be passed.
</p>
<p>
<dfn>queryQuads()</dfn> is an optional method that asynchronously returns a <a href="https://rdf.js.org/stream-spec/#stream-interface">Stream</a> of <a href="http://rdf.js.org/data-model-spec/#quad-interface">Quad</a> objects.
<dfn>query</dfn> is a query string that SHOULD be a SPARQL <code>CONSTRUCT</code> or <code>DESCRIBE</code> query.
<dfn>context</dfn> is an optional context in which query execution options can be passed.
</p>
<p>
<dfn>queryBoolean()</dfn> is an optional method that asynchronously returns a <code>boolean</code>.
<dfn>query</dfn> is a query string that SHOULD be a SPARQL <code>ASK</code> query.
<dfn>context</dfn> is an optional context in which query execution options can be passed.
</p>
<p>
<dfn>queryVoid()</dfn> is an optional method that asynchronously returns a <code>void</code>.
<dfn>query</dfn> is a query string that SHOULD be a SPARQL update query.
<dfn>context</dfn> is an optional context in which query execution options can be passed.
</p>
</section>
<section data-dfn-for="AlgebraSparqlQueryable">
<h3><dfn>AlgebraSparqlQueryable</dfn> interface</h3>
<pre class="idl">
interface AlgebraSparqlQueryable {
optional Promise<Stream<Bindings>> queryBindings(Algebra query, QueryStringContext? context);
optional Promise<Stream<Quad>> queryQuads(Algebra query, QueryStringContext? context);
optional Promise<boolean> queryBoolean(Algebra query, QueryStringContext? context);
optional Promise<void> queryVoid(Algebra query, QueryStringContext? context);
};
</pre>
<p>
An <code>AlgebraSparqlQueryable</code> can be implemented by objects that want to expose a query execution interface that accepts queries as an <code>Algebra</code> object.
</p>
<p>
<dfn>queryBindings()</dfn> is an optional method that asynchronously returns a <a href="https://rdf.js.org/stream-spec/#stream-interface">Stream</a> of <a>Bindings</a> objects.
<dfn>query</dfn> is a query <code>Algebra</code> object that SHOULD be a SPARQL <code>SELECT</code> query.
<dfn>context</dfn> is an optional context in which query execution options can be passed.
</p>
<p>
<dfn>queryQuads()</dfn> is an optional method that asynchronously returns a <a href="https://rdf.js.org/stream-spec/#stream-interface">Stream</a> of <a href="http://rdf.js.org/data-model-spec/#quad-interface">Quad</a> objects.
<dfn>query</dfn> is a query <code>Algebra</code> object that SHOULD be a SPARQL <code>CONSTRUCT</code> or <code>DESCRIBE</code> query.
<dfn>context</dfn> is an optional context in which query execution options can be passed.
</p>
<p>
<dfn>queryBoolean()</dfn> is an optional method that asynchronously returns a <code>boolean</code>.
<dfn>query</dfn> is a query <code>Algebra</code> object that SHOULD be a SPARQL <code>ASK</code> query.
<dfn>context</dfn> is an optional context in which query execution options can be passed.
</p>
<p>
<dfn>queryVoid()</dfn> is an optional method that asynchronously returns a <code>void</code>.
<dfn>query</dfn> is a query <code>Algebra</code> object that SHOULD be a SPARQL update query.
<dfn>context</dfn> is an optional context in which query execution options can be passed.
</p>
</section>
</section>
<section>
<h2>Queryable interfaces</h2>
This section introduces interfaces that can be implemented by query engines to make them expose a query execution interface.
<section data-dfn-for="StringQueryable">
<h3><dfn>StringQueryable</dfn> interface</h3>
<pre class="idl">
interface StringQueryable {
Promise<Query> query(String query, QueryStringContext? context);
};
</pre>
<p>
A <code>StringQueryable</code> can be implemented by objects that want to expose a query execution interface that accepts queries as a string.
</p>
<p>
<dfn>query()</dfn> asynchronously returns a new <a>Query</a> object that can be executed later.
<dfn>query</dfn> is a query string.
<dfn>context</dfn> is an optional context in which query execution options can be passed.
</p>
</section>
<section data-dfn-for="AlgebraQueryable">
<h3><dfn>AlgebraQueryable</dfn> interface</h3>
<pre class="idl">
interface AlgebraQueryable {
Promise<Query> query(Algebra query, QueryAlgebraContext? context);
};
</pre>
<p>
An <code>AlgebraQueryable</code> can be implemented by objects that want to expose a query execution interface that accepts queries as an <code>Algebra</code> object.
</p>
<p>
<dfn>query()</dfn> asynchronously returns a new <a>Query</a> object that can be executed later.
<dfn>query</dfn> is a query <code>Algebra</code> object.
<dfn>context</dfn> is an optional context in which query execution options can be passed.
</p>
</section>
</section>
<section>
<h2>Query interfaces</h2>
This section introduces query interfaces that act as intermediary objects that represent queries that can be executed.
<section data-dfn-for="Query">
<h3><dfn>Query</dfn> interface</h3>
<pre class="idl">
interface Query {
readonly attribute string resultType;
Promise<any> execute(any options);
};
</pre>
<p>
<code>Query</code> is an abstract interface that represents a query that can be executed.
</p>
<p>
<dfn>resultType</dfn> represents the type of query results that will be obtained for a query's execution.
Possible values include <code>"bindings"</code>, <code>"quads"</code>, <code>"boolean"</code>, and <code>"void"</code>.
</p>
<p>
<dfn>execute()</dfn> asynchronously returns the query result, where the signature depends on the <code>resultType</code>.
</p>
</section>
<section data-dfn-for="QueryBindings">
<h3><dfn>QueryBindings</dfn> interface</h3>
<pre class="idl">
interface QueryBindings {
readonly attribute string resultType;
Promise<Stream<Bindings>> execute(QueryExecuteOptions<Variable>? options);
Promise<QueryMetadata<Bindings>> metadata(QueryMetadataOptions? options);
};
</pre>
<p>
<code>QueryBindings</code> represents a query that returns a stream of <a>Bindings</a>, such as a SPARQL <code>SELECT</code> query.
</p>
<p>
<dfn>resultType</dfn> contains the constant <code>"bindings"</code>.
</p>
<p>
<dfn>execute()</dfn> asynchronously returns a stream of <a>Bindings</a>.
<dfn>options</dfn> is an optional argument in which execution options can be passed.
</p>
<p>
<dfn>metadata()</dfn> asynchronously returns a <a>QueryMetadata</a> object.
<dfn>options</dfn> is an optional argument in which desired metadata options can be passed.
</p>
</section>
<section data-dfn-for="QueryQuads">
<h3><dfn>QueryQuads</dfn> interface</h3>
<pre class="idl">
interface QueryQuads {
readonly attribute string resultType;
Promise<Stream<Quad>> execute(QueryExecuteOptions<("subject" or "predicate" or "object" or "graph")>? options);
Promise<QueryMetadata<Quad>> metadata(QueryMetadataOptions? options);
};
</pre>
<p>
<code>QueryQuads</code> represents a query that returns a stream of <a href="http://rdf.js.org/data-model-spec/#quad-interface">Quad</a>s, such as a SPARQL <code>CONSTRUCT</code> or <code>DESCRIBE</code> query.
</p>
<p>
<dfn>resultType</dfn> contains the constant <code>"quads"</code>.
</p>
<p>
<dfn>execute()</dfn> asynchronously returns a stream of <a href="http://rdf.js.org/data-model-spec/#quad-interface">Quad</a>s.
<dfn>options</dfn> is an optional argument in which execution options can be passed.
</p>
<p>
<dfn>metadata()</dfn> asynchronously returns a <a>QueryMetadata</a> object.
<dfn>options</dfn> is an optional argument in which desired metadata options can be passed.
</p>
</section>
<section data-dfn-for="QueryBoolean">
<h3><dfn>QueryBoolean</dfn> interface</h3>
<pre class="idl">
interface QueryBoolean {
readonly attribute string resultType;
Promise<boolean> execute();
};
</pre>
<p>
<code>QueryBoolean</code> represents a query that returns a <code>boolean</code>, such as a SPARQL <code>ASK</code> query.
</p>
<p>
<dfn>resultType</dfn> contains the constant <code>"boolean"</code>.
</p>
<p>
<dfn>execute()</dfn> asynchronously returns a <code>boolean</code>.
</p>
</section>
<section data-dfn-for="QueryVoid">
<h3><dfn>QueryVoid</dfn> interface</h3>
<pre class="idl">
interface QueryVoid {
readonly attribute string resultType;
Promise<void> execute();
};
</pre>
<p>
<code>QueryVoid</code> represents a query that returns nothing, such as a SPARQL update query.
</p>
<p>
<dfn>resultType</dfn> contains the constant <code>"void"</code>.
</p>
<p>
<dfn>execute()</dfn> asynchronously returns nothing.
</p>
</section>
<section data-dfn-for="QueryExecuteOptions">
<h3><dfn>QueryExecuteOptions</dfn> interface</h3>
<pre class="idl">
interface QueryExecuteOptions<OrderType> {
readonly attribute Array<QueryOperationOrderTerm<OrderType>> order;
};
</pre>
<p>
<code>QueryExecuteOptions</code> represents the options for executing a query.
</p>
<p>
<dfn>order</dfn> contains the desired order of query results.
</p>
</section>
<section data-dfn-for="QueryMetadataOptions">
<h3><dfn>QueryMetadataOptions</dfn> interface</h3>
<pre class="idl">
interface QueryMetadataOptions {
attribute ("estimate" or "exact")? cardinality;
attribute boolean order;
attribute boolean availableOrders;
};
</pre>
<p>
<code>QueryMetadataOptions</code> represents the options for requesting the metadata of a query.
</p>
<p>
<dfn>cardinality</dfn> indicates if an exact or estimated value for the <code>cardinality</code> metadata field should be returned.
</p>
<p>
<dfn>order</dfn> indicates if the <code>order</code> metadata field should be returned.
</p>
<p>
<dfn>availableOrders</dfn> indicates if the <code>availableOrders</code> metadata field should be returned.
</p>
</section>
</section>
<section>
<h2>Metadata interfaces</h2>
This section introduces metadata interfaces that can contain additional information about the query execution process.
<section data-dfn-for="QueryMetadata">
<h3><dfn>QueryMetadata</dfn> interface</h3>
<pre class="idl">
interface QueryMetadata<OrderType> {
readonly attribute QueryResultCardinality? cardinality;
readonly attribute Array<QueryOperationOrderTerm<OrderType>>? order;
readonly attribute Array<QueryResultOrderCost<OrderType>>? availableOrders;
};
</pre>
<p>
<code>QueryMetadata</code> is an interface that contains side information about the query execution process.
</p>
<p>
<dfn>cardinality</dfn> represents the number of results of a query.
</p>
<p>
<dfn>order</dfn> represents the order of results in the query result.
</p>
<p>
<dfn>availableOrders</dfn> is an array of alternative orders that may be requested when executing a query.
</p>
</section>
<section data-dfn-for="QueryResultCardinality">
<h3><dfn>QueryResultCardinality</dfn> interface</h3>
<pre class="idl">
interface QueryResultCardinality {
attribute ("estimate" or "exact") type;
attribute unsigned long value;
};
</pre>
<p>
<code>QueryResultCardinality</code> represents the number of results of a query, which can either be an estimated value or exact.
</p>
<p>
<dfn>type</dfn> contains the value <code>"estimate"</code> or <code>"exact"</code>,
which respectively refer to an exact or estimate value.
</p>
<p>
<dfn>value</dfn> contains the cardinality value.
</p>
</section>
<section data-dfn-for="QueryOperationOrderTerm">
<h3><dfn>QueryOperationOrderTerm</dfn> interface</h3>
<pre class="idl">
interface QueryOperationOrderTerm<OrderType> {
attribute OrderType term;
attribute ("asc" or "desc") direction;
};
</pre>
<p>
<code>QueryOperationOrderTerm</code> represents the ordering of a term of a given generic type.
</p>
<p>
<dfn>term</dfn> contains the term over which the order is applied.
</p>
<p>
<dfn>direction</dfn> contains the value <code>"asc"</code> or <code>"desc"</code>,
which respectively refer to an ascending or descending order.
</p>
</section>
<section data-dfn-for="QueryResultOrderCost">
<h3><dfn>QueryResultOrderCost</dfn> interface</h3>
<pre class="idl">
interface QueryResultOrderCost<OrderType> {
attribute QueryOperationCost cost;
attribute Array<QueryOperationOrderTerm<OrderType>> terms;
};
</pre>
<p>
<code>QueryResultOrderCost</code> represents the cost of a specific ordering of query results.
</p>
<p>
<dfn>cost</dfn> represents the cost of executing this ordering.
</p>
<p>
<dfn>terms</dfn> represents the order of terms in an ordering.
</p>
</section>
<section data-dfn-for="QueryOperationCost">
<h3><dfn>QueryOperationCost</dfn> interface</h3>
<pre class="idl">
interface QueryOperationCost {
attribute unsigned long iterations;
attribute unsigned long persistedItems;
attribute unsigned long blockingItems;
attribute unsigned long requestTime;
};
</pre>
<p>
<code>QueryOperationCost</code> represents the cost of a certain query operation.
</p>
<p>
<dfn>iterations</dfn> is estimation of how many iterations over items are executed. This can be used to determine the CPU cost.
</p>
<p>
<dfn>persistedItems</dfn> is estimation of how many items are stored in memory. This is used to determine the memory cost.
</p>
<p>
<dfn>blockingItems</dfn> is estimation of how many items block the stream. This is used to determine the time the stream is not progressing anymore.
</p>
<p>
<dfn>requestTime</dfn> is estimation of the time to request items from sources. This is used to determine the I/O cost.
</p>
</section>
</section>
<section>
<h2>Query context interfaces</h2>
This section introduces interfaces related to query contexts,
which are an optional argument to queryable interfaces for passing additional in information to query engines.
<section data-dfn-for="QueryContext">
<h3><dfn>QueryContext</dfn> interface</h3>
<pre class="idl">
interface QueryContext {
attribute Date? queryTimestamp;
};
</pre>
<p>
<code>QueryContext</code> is a base context interface.
</p>
<p>
<dfn>queryTimestamp</dfn> The date that should be used by SPARQL operations such as <code>NOW()</code>.
</p>
</section>
<section data-dfn-for="QueryStringContext">
<h3><dfn>QueryStringContext</dfn> interface</h3>
<pre class="idl">
interface QueryStringContext : QueryContext {
attribute QueryFormat? queryFormat;
attribute string? baseIRI;
};
</pre>
<p>
A <code>QueryStringContext</code> is a context that can be passed together with a query string.
</p>
<p>
<dfn>queryFormat</dfn> The format in which the query string is defined.
</p>
<p>
<dfn>baseIRI</dfn> The base IRI for parsing the query.
</p>
</section>
<section data-dfn-for="QueryAlgebraContext">
<h3><dfn>QueryAlgebraContext</dfn> interface</h3>
<pre class="idl">
interface QueryAlgebraContext : QueryContext {};
</pre>
<p>
A <code>QueryAlgebraContext</code> is a context that can be passed together with a query <code>Algebra</code> object.
</p>
</section>
<section data-dfn-for="QuerySourceContext">
<h3><dfn>QuerySourceContext</dfn> interface</h3>
<pre class="idl">
interface QuerySourceContext : QueryContext {
attribute Array? sources;
};
</pre>
<p>
A <code>QuerySourceContext</code> can be used by query engines that accept custom data sources during query execution.
</p>
<p>
<dfn>sources</dfn> An array of data sources the query engine must use.
</p>
</section>
<section data-dfn-for="QueryFormat">
<h3><dfn>QueryFormat</dfn> interface</h3>
<pre class="idl">
interface QueryFormat {
attribute string language;
attribute string version;
attribute Array<string>? extensions;
};
</pre>
<p>
A <code>QueryFormat</code> represents the format of a string query, and may influence parsing or execution behaviour.
</p>
<p>
<dfn>language</dfn> The query language, e.g. <code>"sparql"</code>.
</p>
<p>
<dfn>version</dfn> The version of the query language, e.g. <code>"1.1"</code>.
</p>
<p>
<dfn>language</dfn> An optional array of extensions on the query language. The representation of these extensions is undefined.
</p>
</section>
</section>
<section>
<h2>Bindings interfaces</h2>
This section introduces interfaces related to query result bindings.
In SPARQL SELECT queries, these bindings correspond to <a href="https://www.w3.org/TR/sparql11-query/#sparqlSolutions">solution mappings</a>.
<section>
<h2>Goals</h2>
<ul>
<li>Query engines should be able to interact with bindings created by different libraries.</li>
<li>Bindings are immutable</li>
<li>Interfaces do no specify how bindings are stored in memory</li>
</ul>
</section>
<section data-dfn-for="Bindings">
<h3><dfn>Bindings</dfn> interface</h3>
<pre class="idl">
interface Bindings {
iterable<(Variable, Term)>;
readonly attribute string type;
readonly attribute unsigned long size;
boolean has((Variable or string) key);
Term? get((Variable or string) key);
Bindings set((Variable or string) key, Term value);
Bindings delete((Variable or string) key);
iterable<Variable> keys();
iterable<Term> values();
boolean equals(optional Bindings? other);
void forEach(BindingsEntryCallback callback);
Bindings filter(BindingsFilterCallback callback);
Bindings map(BindingsMapCallback callback);
Bindings merge(Bindings other);
Bindings mergeWith(BindingsMergeCallback callback, Bindings other);
};
callback BindingsEntryCallback = undefined (Term value, Variable key);
callback BindingsFilterCallback = boolean (Term value, Variable key);
callback BindingsMapCallback = Term (Term value, Variable key);
callback BindingsMergeCallback = Term (Term self, Term other, Variable key);
</pre>
<p>
A <a>Bindings</a> is an object that represents the mapping of variables to RDF values using an immutable Map-like representation.
This means that methods such as <code>set</code> and <code>delete</code> do not modify this instance,
but they return a new Bindings instance that contains the modification.
</p>
<p>
Every <a>Bindings</a> object is an iterable over its entries, where each entry is a tuple of <code>Variable</code> key and <code>Term</code> value.
</p>
<h3>Attributes</h3>
<p>
<dfn>type</dfn> contains the constant <code>"bindings"</code>.
</p>
<p>
<dfn>size</dfn> is a field that contains the number of entries in this <a>Bindings</a> object.
</p>
<h3>Methods</h3>
<p>
<dfn>has</dfn> checks if a binding exist for the given variable.
<dfn>key</dfn> can be a <a href="http://rdf.js.org/data-model-spec/#variable-interface">Variable</a> or string. If it is a string, no `?` prefix must be given.
</p>
<p>
<dfn>get</dfn> returns the <a href="http://rdf.js.org/data-model-spec/#term-interface">Term</a> value bound to the given variable, or <code>undefined</code> if no binding exists.
<dfn>key</dfn> can be a <a href="http://rdf.js.org/data-model-spec/#variable-interface">Variable</a> or string. If it is a string, no `?` prefix must be given.
</p>
<p>
<dfn>set</dfn> returns a new <a>Bindings</a> object by adding the given variable and value mapping.
If the variable already exists in the binding, then the existing mapping is overwritten.
<dfn>key</dfn> can be a <a href="http://rdf.js.org/data-model-spec/#variable-interface">Variable</a> or string. If it is a string, no `?` prefix must be given.
<dfn>value</dfn> is the <a href="http://rdf.js.org/data-model-spec/#term-interface">Term</a> value that must be bound.
</p>
<p>
<dfn>delete</dfn> returns a new <a>Bindings</a> object by removing the given variable.
If the variable does not exist in the binding, a copy of the <a>Bindings</a> object is returned.
<dfn>key</dfn> can be a <a href="http://rdf.js.org/data-model-spec/#variable-interface">Variable</a> or string. If it is a string, no `?` prefix must be given.
</p>
<p>
<dfn>keys</dfn> returns an iterable of <a href="http://rdf.js.org/data-model-spec/#variable-interface">Variable</a> instances for which mappings exist.
</p>
<p>
<dfn>values</dfn> returns an iterable of <a href="http://rdf.js.org/data-model-spec/#term-interface">Term</a> values for which mappings exist.
</p>
<p>
<dfn>equals</dfn> returns <code>true</code>
when called with parameter <code>other</code>
on an object <a>Bindings</a> if
all of the conditions below hold:
</p>
<ul>
<li><code>other</code> is <em>neither</em> <code>null</code> nor <code>undefined</code>;</li>
<li>The keys in the this and the other <a>Bindings</a> object are equal (following the semantics of <code>Variable.equals</code>);</li>
<li>For each key, the values within each <a>Bindings</a> object are equal (following the semantics of <code>Term.equals</code>);</li>
</ul>
<p>
<dfn>forEach</dfn> invokes the <code>callback</code> for all entries in this <a>Bindings</a> object,
with the entry value <a href="http://rdf.js.org/data-model-spec/#term-interface">Term</a> as first argument, and the entry key <a href="http://rdf.js.org/data-model-spec/#variable-interface">Variable</a> as second argument.
</p>
<p>
<dfn>filter</dfn> returns a new <a>Bindings</a> object by filtering entries using <code>callback</code>,
with the entry value <a href="http://rdf.js.org/data-model-spec/#term-interface">Term</a> as first argument, and the entry key <a href="http://rdf.js.org/data-model-spec/#variable-interface">Variable</a> as second argument.
Returning <code>true</code> indicates that this entry must be contained in the resulting <a>Bindings</a> object.
</p>
<p>
<dfn>map</dfn> returns a new <a>Bindings</a> object by mapping entries using <code>callback</code>,
with the entry value <code>Term</code> as first argument, and the entry key <a href="http://rdf.js.org/data-model-spec/#variable-interface">Variable</a> as second argument.
The original <code>Term</code> value is replaced by the returned <a href="http://rdf.js.org/data-model-spec/#term-interface">Term</a> value in the resulting <a>Bindings</a> object.
</p>
<p>
<dfn>merge</dfn> merges this <a>Bindings</a> object with another <a>Bindings</a> object.
If a merge conflict occurs (this and other have an equal variable with unequal value), then <code>undefined</code> is returned.
</p>
<p>
<dfn>mergeWith</dfn> merges this <a>Bindings</a> object with another <a>Bindings</a> object,
where merge conflicts can be resolved using <code>callback</code>.
<code>callback</code> is invoked with the value <a href="http://rdf.js.org/data-model-spec/#term-interface">Term</a> of the first <a>Bindings</a> object as first argument,
the value <a href="http://rdf.js.org/data-model-spec/#term-interface">Term</a> of the second <a>Bindings</a> object as second argument,
and the key <a href="http://rdf.js.org/data-model-spec/#variable-interface">Variable</a> as third argument,
where the returned <a href="http://rdf.js.org/data-model-spec/#term-interface">Term</a> is considered the merged value.
</p>
</section>
<section data-dfn-for="BindingsFactory">
<h3><dfn>BindingsFactory</dfn> interface</h3>
<pre class="idl">
interface BindingsFactory {
Bindings bindings(Array<(Variable, Term)>? entries);
Bindings fromBindings(Bindings bindings);
};
</pre>
<p>
<dfn>bindings()</dfn> returns a new <a>Bindings</a> using the given entries,
where the entries are represented as an array of key-value pairs.
</p>
<p>
<dfn>fromBindings()</dfn> returns a copy of the given <a>Bindings</a> using this factory.
</p>
</section>
</section>
<div class="warning" title="Experimental!">
<p>
The following interfaces are experimental and will change in future versions of this document:
</p>
<p>
<code>FilterableSource</code>, <code>FilterResult</code>, <code>QueryResultMetadata</code>, <code>QueryResultMetadataCount</code>, <code>QueryResultMetadataOptions</code>, <code>Expression</code>, <code>OperatorExpression</code>, <code>TermExpression</code>, <code>ExpressionFactory</code>
</p>
</div>
<section>
<h2>Filter expression interfaces</h2>
This section introduces interfaces that enable quad sources to be filtered based on a declarative expression.
<section>
<h2>Goals</h2>
<ul>
<li>Query engines MUST be able to push down filters into sources.</li>
<li>Query engines MUST be able to detect what expressions are supported by sources.</li>
<li>Query engines MUST be able to obtain the estimated cardinality of any supported expression.</li>
</ul>
</section>
<section data-dfn-for="FilterableSource">
<h3><dfn>FilterableSource</dfn> interface</h3>
<pre class="idl">
interface FilterableSource {
FilterResult matchExpression (
optional Term? subject,
optional Term? predicate,
optional Term? obj,
optional Term? graph,
optional Expression? expression
);
};
</pre>
<p>
A <code>FilterableSource</code> is an object that produces a <code>FilterableSourceResult</code> that can emit quads.
The emitted quads can be directly contained in this <code>FilterableSource</code> object, or they can be generated on the fly.
</p>
<p>
<code>FilterableSource</code> is not necessarily an extension of the <a href="https://rdf.js.org/stream-spec/#source-interface">RDF/JS Source interface</a>, but implementers MAY decide to implement both at the same time.
</p>
<p>
<dfn>matchExpression()</dfn> Returns a <code>FilterableSourceResult</code> that contains a quad stream that processes all quads matching the quad pattern and the expression.
</p>
<p>
When a <code>Term</code> parameter is defined, and is a <code>NamedNode</code>, <code>Literal</code> or <code>BlankNode</code>,
it must match each produced quad, according to the <a href="http://rdf.js.org/data-model-spec/#quad-interface"><code>Quad.equals</code></a> semantics.
When a <code>Term</code> parameter is a <code>Variable</code>,
or it is undefined, it acts as a wildcard, and can match with any <code>Term</code>.
</p>
<p class="note">
When matching with <code>graph</code> set to <code>undefined</code> or <code>null</code>
it MUST match all the graphs (sometimes called <em>the union graph</em>). To match only <em>the default graph</em>
set <code>graph</code> to a <code>DefaultGraph</code>
</p>
<p>
When an <code>Expression</code> parameter is defined, the complete quad stream is filtered according to this expression.
When it is undefined, no filter is applied.
</p>
<p>
If parameters of type <code>Variable</code> with an equal variable name are in place,
then the corresponding quad components in the resulting quad stream MUST be equal.
</p>
<p>
<code>Expression</code>'s MAY contain <code>Variable</code> <code>Term</code>'s.
If their variable names are equal to <code>Variable</code>'s in the given quad pattern,
then the <code>Expression</code> MUST be instantiated for each variable's binding in the resulting quad stream when applying the <code>Expression</code> filter.
</p>
</section>
<section data-dfn-for="FilterResult">
<h3><dfn>FilterResult</dfn> interface</h3>
<pre class="idl">
interface FilterResult {
Stream quads();
Promise<QueryResultMetadata> metadata(optional QueryResultMetadataOptions? options);
Promise<boolean> isSupported();
};
</pre>
<p>
A <code>FilterResult</code> is an object that represents the result of a filter expression of <code>FilterableSource</code> for a given quad pattern and expression.
It MAY create results lazily after one of its methods is invoked.
</p>
<p>
<dfn>quads()</dfn> Returns a <a href="https://rdf.js.org/stream-spec/#stream-interface"><code>Stream<Quad></code></a> containing all the quads that matched the given quad pattern and expression.
</p>
<p>
<dfn>metadata()</dfn> Asynchronously returns a <code>QueryResultMetadata</code>, that contains the metadata of the current result.
</p>
<p>
<dfn>isSupported()</dfn> Asynchronously returns a boolean indicating if the requested expression is supported by the <code>FilterableSource</code>.
If it returns <code>true</code>, <code>quads()</code> and <code>metadata()</code> MAY produce a valid result.
If it returns <code>false</code>, <code>quads()</code> MUST return a stream emitting an error, and <code>metadata()</code> MUST reject.
</p>
</section>
<section data-dfn-for="QueryResultMetadata">
<h3><dfn>QueryResultMetadata</dfn> interface</h3>
<pre class="idl">
interface QueryResultMetadata {
attribute QueryResultMetadataCount? count;
};
</pre>
<p>
A <code>QueryResultMetadata</code> is an object that represents contains metadata bout a certain query result,
such as invoking <code>FilterableSource.matchExpression</code>.
</p>
<p>
<dfn>count</dfn> is an optional field that contains metadata about the number of quads in the result stream.
</p>
</section>
<section data-dfn-for="QueryResultMetadataCount">
<h3><dfn>QueryResultMetadataCount</dfn> interface</h3>
<pre class="idl">
interface QueryResultMetadataCount {
attribute string type;
attribute number value;
};
</pre>
<p>
<code>QueryResultMetadataCount</code> is part of the <code>QueryResultMetadata</code> interface
to represent metadata about the number of quads in the result stream.
</p>
<p>
<dfn>type</dfn> indicates the type of counting that was done, and MUST either be <code>"estimate"</code> or <code>"exact"</code>.
</p>
<p>
<dfn>value</dfn> indicates an estimate of the number of quads in the stream if <code>type = "estimate"</code>,
or the exact number of quads in the stream if <code>type = "exact"</code>.
</p>
</section>
<section data-dfn-for="QueryResultMetadata">
<h3><dfn>QueryResultMetadataOptions</dfn> interface</h3>
<pre class="idl">
interface QueryResultMetadataOptions {
attribute string? count;
};
</pre>
<p>
A <code>QueryResultMetadataOptions</code> is an object that gives suggestions on what type of metadata is desired,
such as when invoking <code>FilterResult.metadata</code>.
</p>
<p>
<dfn>count</dfn> is an optional field that MAY either contain <code>"estimate"</code> or <code>"exact"</code>.
If defined, this type MUST correspond to the type in <code>QueryResultMetadataCount</code>.
</p>
</section>
<section data-dfn-for="Expression">
<h3><dfn>Expression</dfn> interface</h3>
<pre class="idl">
interface Expression {
attribute string expressionType;
};
</pre>
<p>
<code>QueryResultMetadataOptions</code> is an abstract interface that represents a generic expression over a stream of quads.
</p>
<p>
<dfn>expressionType</dfn> contains a value that identifies the concrete interface of the expression, since the Expression itself is not directly instantiated.
Possible values include <code>"operator"</code> and <code>"term"</code>.
</p>
</section>
<section data-dfn-for="OperatorExpression">
<h3><dfn>OperatorExpression</dfn> interface</h3>
<pre class="idl">
interface OperatorExpression {
attribute string expressionType;
attribute string operator;
attribute FrozenArray<Expression> args;
};
</pre>
<p>
An <code>OperatorExpression</code> is represents an expression that applies a given operator on given sub-expressions.
</p>
<p>
<dfn>expressionType</dfn> contains the constant <code>"operator"</code>.
</p>
<p>
<dfn>operator</dfn> contains a value that identifies an operator.
Possible values can be found in <a href="#expression-operators">the list of operators</a>.
</p>
<p>
<dfn>args</dfn> contains an array of <code>Expression</code>'s on to which the given operator applies.
The length of this array depends on the operator.
</p>
</section>
<section data-dfn-for="TermExpression">
<h3><dfn>TermExpression</dfn> interface</h3>
<pre class="idl">
interface TermExpression {
attribute string expressionType;
attribute Term term;
};
</pre>
<p>
A <code>TermExpression</code> is an expression that contains a <a href="http://rdf.js.org/data-model-spec/#term-interface"><code>Term</code></a>.
</p>
<p>
<dfn>expressionType</dfn> contains the constant <code>"term"</code>.
</p>
<p>
<dfn>term</dfn> contains a <a href="http://rdf.js.org/data-model-spec/#term-interface"><code>Term</code></a>.
</p>
</section>
<section data-dfn-for="ExpressionFactory">
<h3><dfn>ExpressionFactory</dfn> interface</h3>