@@ -12,6 +12,8 @@ pub struct PlanBuilder<'a> {
12
12
storage : & ' a dyn Storage ,
13
13
prefixes : HashMap < String , String > ,
14
14
variables : Vec < String > ,
15
+ limit : Option < usize > ,
16
+ skip : Option < usize > ,
15
17
}
16
18
17
19
impl < ' a > PlanBuilder < ' a > {
@@ -20,9 +22,21 @@ impl<'a> PlanBuilder<'a> {
20
22
storage,
21
23
prefixes : Self :: make_prefixes ( prefixes) ,
22
24
variables : Vec :: new ( ) ,
25
+ skip : None ,
26
+ limit : None ,
23
27
}
24
28
}
25
29
30
+ pub fn with_limit ( & mut self , limit : usize ) -> & Self {
31
+ self . limit = Some ( limit) ;
32
+ self
33
+ }
34
+
35
+ pub fn with_skip ( & mut self , skip : usize ) -> & Self {
36
+ self . skip = Some ( skip) ;
37
+ self
38
+ }
39
+
26
40
pub fn build_plan ( & mut self , where_clause : WhereClause ) -> StdResult < QueryPlan > {
27
41
let bgp: Vec < QueryNode > = where_clause
28
42
. iter ( )
@@ -33,9 +47,31 @@ impl<'a> PlanBuilder<'a> {
33
47
. collect :: < StdResult < Vec < QueryNode > > > ( ) ?;
34
48
35
49
self . build_from_bgp ( bgp)
50
+ . map ( |mut node| {
51
+ if let Some ( skip) = self . skip {
52
+ node = QueryNode :: Skip {
53
+ child : Box :: new ( node) ,
54
+ first : skip,
55
+ }
56
+ }
57
+ node
58
+ } )
59
+ . map ( |mut node| {
60
+ if let Some ( limit) = self . skip {
61
+ node = QueryNode :: Limit {
62
+ child : Box :: new ( node) ,
63
+ first : limit,
64
+ }
65
+ }
66
+ node
67
+ } )
68
+ . map ( |node| QueryPlan {
69
+ entrypoint : Box :: new ( node) ,
70
+ variables : self . variables . clone ( ) ,
71
+ } )
36
72
}
37
73
38
- fn build_from_bgp ( & self , bgp : Vec < QueryNode > ) -> StdResult < QueryPlan > {
74
+ fn build_from_bgp ( & self , bgp : Vec < QueryNode > ) -> StdResult < QueryNode > {
39
75
bgp. into_iter ( )
40
76
. reduce ( |left : QueryNode , right : QueryNode | -> QueryNode {
41
77
if left
@@ -56,10 +92,6 @@ impl<'a> PlanBuilder<'a> {
56
92
} )
57
93
. map ( Ok )
58
94
. unwrap_or ( Err ( StdError :: generic_err ( "Empty basic graph pattern" ) ) )
59
- . map ( |query_node| QueryPlan {
60
- entrypoint : Box :: new ( query_node) ,
61
- variables : self . variables . clone ( ) ,
62
- } )
63
95
}
64
96
65
97
fn build_triple_pattern ( & mut self , pattern : & TriplePattern ) -> StdResult < QueryNode > {
0 commit comments