Turi Create  4.0
subplan_executor.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef TURI_SFRAME_QUERY_ENGINE_SUBPLAN_EXECUTOR_H_
7 #define TURI_SFRAME_QUERY_ENGINE_SUBPLAN_EXECUTOR_H_
8 
9 #include <vector>
10 #include <memory>
11 #include <functional>
12 #include <core/storage/sframe_data/sframe.hpp>
13 #include <core/storage/query_engine/planning/materialize_options.hpp>
14 
15 namespace turi { namespace query_eval {
16 
17 typedef std::function<bool(size_t, const std::shared_ptr<sframe_rows>&)> execution_callback;
18 
19 struct planner_node;
20 
21 
22 /**
23  * \ingroup sframe_query_engine
24  * \addtogroup execution Execution
25  * \{
26  */
27 
28 /**
29  * The subplan executor executes a restricted class of constant rate query
30  * plans.
31  *
32  * The subplan executor is the last stage of a hierarchy of query
33  * executors.
34  *
35  * The hierarchy is:
36  * - \ref planner::materialize Handles the most general materializations
37  * - \ref planner::partial_materialize Handles the most general materializations
38  * but performs all materializations except
39  * for the last stage. A private function.
40  * - \ref planner::execute_node Replicates a plan for parallelization.
41  * A private function.
42  * - \ref subplan_executor Executes a restricted plan.
43  *
44  * As described in \ref execution_node, to successfully execute a query plan
45  * requires certain rate control constraints to be true: i.e. all nodes
46  * must read/write data at exactly the same rate.
47  *
48  * This executor assumes that the query plan to execute is exactly restricted
49  * to that. It simply sets up the pipeline of \ref execution_node objects
50  * and materializes the results.
51  */
53  public:
54 
55  /**
56  * Runs a single job sequentially returning the resultant SFrame.
57  *
58  * Note that materialize_options may be used to adapt the materialization
59  * process.
60  */
61  sframe run(const std::shared_ptr<planner_node>& run_this,
62  const materialize_options& exec_params = materialize_options());
63 
64  /** Runs a batch of planner nodes in parallel, returning an SFrame for
65  * each of them.
66  *
67  * Note that materialize_options may be used to adapt the materialization
68  * process.
69  */
70  std::vector<sframe> run(
71  const std::vector<std::shared_ptr<planner_node> >& stuff_to_run_in_parallel,
72  const materialize_options& exec_params = materialize_options());
73 
74 
75  /** Runs a batch of planner nodes in parallel, returning an SFrame comprising
76  * of the concatenation of the output of each of the planner nodes.
77  *
78  * All the stuff_to_run_in_parallel must share exactly the same schema.
79  *
80  * Note that materialize_options may be used to adapt the materialization
81  * process.
82  */
84  const std::vector<std::shared_ptr<planner_node> >& stuff_to_run_in_parallel,
85  const materialize_options& exec_params = materialize_options());
86 
87  private:
88 
89  /**
90  * \internal
91  * Runs a single job sequentially to a single sframe segment.
92  */
93  void generate_to_sframe_segment(const std::shared_ptr<planner_node>& run_this,
94  sframe& out,
95  size_t output_segment_id);
96 
97  /**
98  * \internal
99  * Runs a single job sequentially, calling the callback on each output.
100  */
101  void generate_to_callback_function(
102  const std::shared_ptr<planner_node>& plan,
103  size_t output_segment_id,
104  execution_callback out_f);
105 };
106 
107 /// \}
108 
109 }}
110 
111 #endif /* _SUBPLAN_EXECUTOR_H_ */
sframe run(const std::shared_ptr< planner_node > &run_this, const materialize_options &exec_params=materialize_options())
sframe run_concat(const std::vector< std::shared_ptr< planner_node > > &stuff_to_run_in_parallel, const materialize_options &exec_params=materialize_options())