@@ -11,8 +11,8 @@ use serde::Serialize;
1111use smallvec:: { SmallVec , smallvec} ;
1212
1313use crate :: {
14- FilteredQuery , ManyRecordsQuery , Query , QueryGraphBuilderError , QueryGraphBuilderResult , QueryOptions , ReadQuery ,
15- interpreter:: ExpressionResult ,
14+ ManyRecordsQuery , Query , QueryGraphBuilderError , QueryGraphBuilderResult , QueryOptions , ReadQuery ,
15+ inputs :: ManyRecordsQueryFilterInput , interpreter:: ExpressionResult ,
1616} ;
1717use guard:: * ;
1818use itertools:: Itertools ;
@@ -21,7 +21,7 @@ use petgraph::{
2121 visit:: { EdgeRef as PEdgeRef , NodeIndexable } ,
2222 * ,
2323} ;
24- use query_structure:: { FieldSelection , Filter , IntoFilter , QueryArguments , SelectionResult , WriteArgs } ;
24+ use query_structure:: { FieldSelection , Filter , QueryArguments , SelectionResult , WriteArgs } ;
2525
2626pub type QueryGraphResult < T > = std:: result:: Result < T , QueryGraphError > ;
2727
@@ -135,9 +135,6 @@ impl EdgeRef {
135135 }
136136}
137137
138- pub ( crate ) type ProjectedDataDependencyFn =
139- Box < dyn FnOnce ( Node , Vec < SelectionResult > ) -> QueryGraphBuilderResult < Node > + Send + Sync + ' static > ;
140-
141138/// Stored on the edges of the QueryGraph, a QueryGraphDependency contains information on how children are connected to their parents,
142139/// expressing for example the need for additional information from the parent to be able to execute at runtime.
143140pub enum QueryGraphDependency {
@@ -156,9 +153,7 @@ pub enum QueryGraphDependency {
156153 /// Important note: As opposed to `DataDependency`, this dependency guarantees that if the closure is called, the source result contains at least the requested selection.
157154 /// To achieve that, the query graph is post-processed in the `finalize` and reloads are injected at points where a selection is not fulfilled.
158155 /// See `insert_reloads` for more information.
159- ProjectedDataDependency ( FieldSelection , ProjectedDataDependencyFn , Option < DataExpectation > ) , // [Composites] todo rename
160-
161- ProjectedDataSinkDependency ( FieldSelection , RowSink , Option < DataExpectation > ) ,
156+ ProjectedDataDependency ( FieldSelection , RowSink , Option < DataExpectation > ) ,
162157
163158 /// Only valid in the context of a `If` control flow node.
164159 Then ,
@@ -170,14 +165,16 @@ pub enum QueryGraphDependency {
170165#[ derive( Debug ) ]
171166pub enum RowSink {
172167 /// Store a single row to the node input field.
173- Single ( & ' static dyn NodeInputField < SelectionResult > ) ,
168+ Single ( & ' static dyn NodeInputField < Option < SelectionResult > > ) ,
174169 /// Store all rows to the node input field.
175170 All ( & ' static dyn NodeInputField < Vec < SelectionResult > > ) ,
176171 /// Store at most one row to the node input field.
177172 AtMostOne ( & ' static dyn NodeInputField < Vec < SelectionResult > > ) ,
178173 /// Store an array of exactly one row to the node input field.
179174 ExactlyOne ( & ' static dyn NodeInputField < Vec < SelectionResult > > ) ,
180- /// Store exactly one filter to the node input field.
175+ /// Store a filter representing all rows to the node input field.
176+ AllFilter ( & ' static dyn NodeInputField < Filter > ) ,
177+ /// Store a filter representing exactly one row to the node input field.
181178 ExactlyOneFilter ( & ' static dyn NodeInputField < Filter > ) ,
182179 /// Inject write arguments based on selection retrieved from exactly one row.
183180 ExactlyOneWriteArgs ( FieldSelection , & ' static dyn NodeInputField < [ WriteArgs ] > ) ,
@@ -841,12 +838,14 @@ impl QueryGraph {
841838 let out_edges = self . outgoing_edges ( & return_node) ;
842839 let dependencies: Vec < FieldSelection > = out_edges
843840 . into_iter ( )
844- . filter_map ( |edge| match self . edge_content ( & edge) . unwrap ( ) {
845- QueryGraphDependency :: ProjectedDataDependency ( requested_selection, _, _)
846- | QueryGraphDependency :: ProjectedDataSinkDependency ( requested_selection, _, _) => {
841+ . filter_map ( |edge| {
842+ if let QueryGraphDependency :: ProjectedDataDependency ( requested_selection, _, _) =
843+ self . edge_content ( & edge) . unwrap ( )
844+ {
847845 Some ( requested_selection. clone ( ) )
846+ } else {
847+ None
848848 }
849- _ => None ,
850849 } )
851850 . collect ( ) ;
852851 let dependencies = FieldSelection :: union ( dependencies) ;
@@ -857,10 +856,7 @@ impl QueryGraph {
857856 let incoming_dep_edge = in_edges. into_iter ( ) . find ( |edge| {
858857 matches ! (
859858 self . edge_content( edge) ,
860- Some (
861- QueryGraphDependency :: ProjectedDataDependency ( _, _, _)
862- | QueryGraphDependency :: ProjectedDataSinkDependency ( _, _, _)
863- )
859+ Some ( QueryGraphDependency :: ProjectedDataDependency ( _, _, _) )
864860 )
865861 } ) ;
866862
@@ -871,28 +867,13 @@ impl QueryGraph {
871867 . remove_edge ( incoming_edge)
872868 . expect ( "Expected edges between marked nodes to be non-empty." ) ;
873869
874- match content {
875- QueryGraphDependency :: ProjectedDataDependency ( existing, transformer, expectation) => {
876- let merged_dependencies = dependencies. merge ( existing) ;
877- self . create_edge (
878- & source,
879- & target,
880- QueryGraphDependency :: ProjectedDataDependency (
881- merged_dependencies,
882- transformer,
883- expectation,
884- ) ,
885- ) ?;
886- }
887- QueryGraphDependency :: ProjectedDataSinkDependency ( existing, sink, expectation) => {
888- let merged_dependencies = dependencies. merge ( existing) ;
889- self . create_edge (
890- & source,
891- & target,
892- QueryGraphDependency :: ProjectedDataSinkDependency ( merged_dependencies, sink, expectation) ,
893- ) ?;
894- }
895- _ => ( ) ,
870+ if let QueryGraphDependency :: ProjectedDataDependency ( existing, sink, expectation) = content {
871+ let merged_dependencies = dependencies. merge ( existing) ;
872+ self . create_edge (
873+ & source,
874+ & target,
875+ QueryGraphDependency :: ProjectedDataDependency ( merged_dependencies, sink, expectation) ,
876+ ) ?;
896877 }
897878 }
898879 }
@@ -988,13 +969,7 @@ impl QueryGraph {
988969 & reload_node,
989970 QueryGraphDependency :: ProjectedDataDependency (
990971 primary_model_id,
991- Box :: new ( |mut reload_node, parent_result| {
992- if let Node :: Query ( Query :: Read ( ReadQuery :: ManyRecordsQuery ( ref mut mr) ) ) = reload_node {
993- mr. set_filter ( parent_result. filter ( ) ) ;
994- }
995-
996- Ok ( reload_node)
997- } ) ,
972+ RowSink :: AllFilter ( & ManyRecordsQueryFilterInput ) ,
998973 None ,
999974 ) ,
1000975 ) ?;
@@ -1103,7 +1078,6 @@ impl QueryGraph {
11031078 . into_iter ( )
11041079 . filter_map ( |edge| match self . edge_content ( & edge) . unwrap ( ) {
11051080 QueryGraphDependency :: ProjectedDataDependency ( requested_selection, _, _)
1106- | QueryGraphDependency :: ProjectedDataSinkDependency ( requested_selection, _, _)
11071081 if !q. satisfies ( requested_selection) =>
11081082 {
11091083 Some ( requested_selection. clone ( ) )
0 commit comments