Turi Create  4.0
planner.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_PLANNER_HPP_
7 #define TURI_SFRAME_QUERY_ENGINE_PLANNER_HPP_
8 
9 #include <vector>
10 #include <string>
11 #include <memory>
12 
13 #include <core/storage/sframe_data/sframe.hpp>
14 #include <core/storage/query_engine/planning/materialize_options.hpp>
15 #include <core/storage/query_engine/planning/planner_node.hpp>
16 
17 namespace turi {
18 namespace query_eval {
19 
20 class query_planner;
21 
22 /**
23  * \ingroup sframe_query_engine
24  * \addtogroup planning Planning, Optimization and Execution
25  * \{
26  */
27 
28 /**
29  * The main query plan call.
30  */
31 class planner {
32  public:
33  typedef std::function<bool(size_t, const std::shared_ptr<sframe_rows>&)>
34  write_callback_type;
35 
36  planner() {}
37 
38  /**
39  * Materialize the output from a node on a graph as an SFrame.
40  *
41  * Note that exec_params allows some control over the execution of the
42  * materialization.
43  *
44  *
45  * This function is the tip of the materialization pipeline,
46  * everything materialization operation should come through here, and the
47  * objective here is to correctly handle all query plans.
48  *
49  * Internally, the materialization hierarchy is:
50  * - \ref planner::materialize Handles the most general materializations
51  * - \ref planner::execute_node Replicates a plan for parallelization.
52  * A private function.
53  * - \ref subplan_executor Executes a restricted plan.
54  */
55  sframe materialize(std::shared_ptr<planner_node> tip,
57 
58  /**
59  * \overload
60  * Convenience overload for a very common use case which is to just
61  * materialize to a callback function.
62  *
63  * See the \ref materialize_options for details on what the arguments achieve.
64  *
65  * But most notably, if partial_materialize is false, the materialization
66  * may fail. See \ref materialize_options for details.
67  */
68  void materialize(std::shared_ptr<planner_node> tip,
69  write_callback_type callback,
70  size_t num_segments,
72 
73 
74  /** If this returns true, it is recommended to go ahead and
75  * materialize the sframe operations on the fly to prevent memory
76  * issues.
77  */
78  bool online_materialization_recommended(std::shared_ptr<planner_node> tip);
79 
80  /**
81  * Materialize the output, returning the result as a planner node.
82  */
83  std::shared_ptr<planner_node> materialize_as_planner_node(
84  std::shared_ptr<planner_node> tip,
86 
87  /**
88  * Returns a new planner node which is a range slice of the input node.
89  *
90  * The operation may modify (materialize) input node.
91  */
92  std::shared_ptr<planner_node> slice(std::shared_ptr<planner_node>& tip, size_t begin, size_t end);
93 
94  /**
95  * Try to test that both a and b have equal length and to materialize
96  * them if necessary to prove that this is the case.
97  */
98  bool test_equal_length(std::shared_ptr<planner_node> a,
99  std::shared_ptr<planner_node> b);
100 };
101 
102 
103 
104 /// \}
105 
106 } // namespace query_eval
107 } // namespace turi
108 
109 #endif /* TURI_SFRAME_QUERY_ENGINE_PLANNER_HPP_ */
std::shared_ptr< planner_node > slice(std::shared_ptr< planner_node > &tip, size_t begin, size_t end)
bool test_equal_length(std::shared_ptr< planner_node > a, std::shared_ptr< planner_node > b)
bool online_materialization_recommended(std::shared_ptr< planner_node > tip)
sframe materialize(std::shared_ptr< planner_node > tip, materialize_options exec_params=materialize_options())
std::shared_ptr< planner_node > materialize_as_planner_node(std::shared_ptr< planner_node > tip, materialize_options exec_params=materialize_options())