Turi Create  4.0
optimization_transforms.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_QUERY_OPTIMIZATION_TRANSFORMS_H_
7 #define TURI_SFRAME_QUERY_ENGINE_QUERY_OPTIMIZATION_TRANSFORMS_H_
8 
9 #include <core/storage/query_engine/planning/optimization_node_info.hpp>
10 #include <string>
11 
12 namespace turi {
13 namespace query_eval {
14 
15 struct optimization_transform_registry;
16 struct materialize_options;
17 
18 /**
19  * Optimization transforms are successively applied until no more
20  * optimizations are possible. A queue of active nodes is maintained,
21  * starting with all nodes in the planner graph.
22  *
23  * The transforms are indexed by type; for each node in the planner
24  * graph, all transformations that apply to that planner node type
25  * are attempted in order of declaration. If no transformations
26  * apply to a node, then it is discarded from the active queue.
27  *
28  * If apply_transform returns true, then the optimization for that
29  * node is stopped. If apply_transform returns false, then it is
30  * assumed that the transformation did not apply, and the next
31  * transformation is attempted.
32  *
33  * Changes to the graph coming as a result of transformations should
34  * call the appropriate method in the optimization_engine. All
35  * intrinsic graph operations required to maintain the graph
36  * consistently are done internally by these nodes, including
37  * requeueing all affected nodes on the active queue.
38  *
39  * All new transformations need to be registered in
40  * populate_transforms() inside optimization_transforms.cpp.
41  */
43  public:
44 
45  virtual ~opt_transform() = default;
46 
47  /** A description string that gets logged when the transformation is
48  * applied.
49  */
50  virtual std::string description() = 0;
51 
52  /** Does the transform apply to a particular node type?
53  */
54  virtual bool transform_applies(planner_node_type t) = 0;
55 
56  /** Return true if the transform was applied.
57  */
58  virtual bool apply_transform(optimization_engine *opt_manager, cnode_info_ptr n) = 0;
59 };
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 
63 /** Deterime which stages are run, given exec_params.
64  */
65 std::vector<size_t> get_stages_to_run(const materialize_options& exec_params);
66 
67 /** Populate the transform registry with all transforms.
68  */
70 
71 }}
72 
73 #endif /* _OPTIMIZATION_TRANSFORMS_H_ */
virtual bool transform_applies(planner_node_type t)=0
virtual bool apply_transform(optimization_engine *opt_manager, cnode_info_ptr n)=0
virtual std::string description()=0
void populate_transforms(optimization_transform_registry *otr)
std::vector< size_t > get_stages_to_run(const materialize_options &exec_params)