Turi Create  4.0
planner_node.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_NODE_HPP
7 #define TURI_SFRAME_QUERY_ENGINE_PLANNER_NODE_HPP
8 
9 #include <memory>
10 #include <string>
11 #include <map>
12 #include <vector>
13 #include <core/data/flexible_type/flexible_type.hpp>
14 #include <core/util/any.hpp>
15 #include <core/storage/query_engine/operators/operator_properties.hpp>
16 
17 namespace turi {
18 namespace query_eval {
19 
20 class query_operator;
21 struct qp_info;
22 
23 /**
24  * \ingroup sframe_query_engine
25  * \addtogroup operators Logical Operators
26  * \{
27  */
28 
29 /**
30  * The logical node describing an operator in a logical operator graph.
31  *
32  * The planner node is a simple datastructure comprising of just a few
33  * elements:
34  * \arg \c operator_type One of the operator enumerations in operator_properties.hpp
35  * \arg \c operator_parameters (map of string->flexible_type>: The parameters for
36  * the operator. This is operator
37  * dependent and is defined by the operator itself. Generally, user's of
38  * the planner node should not need this, and should just call
39  * planner_node_traits<...>::make_plan() to create an operator node.
40  * key names begining with "__" are reserved (for instance, for memoizations, etc)
41  * \arg \c any_operator_parameters (map of string->any): Non-portable parameters.
42  * Operators which use this will generally not work for going distributed.
43  * key names begining with "__" are reserved. (for instance, for memoizations, etc)
44  * \arg \c inputs (vector of shared_ptr<planner_node>) Inputs to the operators
45  * are defined here.
46  */
47 struct planner_node {
49  const std::map<std::string, flexible_type>& operator_parameters
50  = std::map<std::string, flexible_type>(),
51  const std::map<std::string, any>& any_operator_parameters
52  = std::map<std::string, any>(),
53  const std::vector<std::shared_ptr<planner_node> >& inputs
54  = std::vector<std::shared_ptr<planner_node> >()):
55  operator_type(operator_type),
58  inputs(inputs) { }
59 
60  planner_node(planner_node&&) = default;
61  planner_node(const planner_node&) = default;
62  planner_node& operator=(const planner_node&) = default;
63  planner_node& operator=(planner_node&&) = default;
64 
65  /** The name of the operator.
66  */
67  planner_node_type operator_type = planner_node_type::INVALID;
68 
69  /**
70  * A generic field for holding the parameters of the operator.
71  */
72  std::map<std::string, flexible_type> operator_parameters;
73 
74  /**
75  * This field holds all other non-portable parameters. For instance,
76  * function pointers, etc. Operators / Planner nodes which depend on this
77  * will generally, not work for going distributed.
78  */
79  std::map<std::string, any> any_operator_parameters;
80 
81  /** The inputs to the operator.
82  */
83  std::vector<std::shared_ptr<planner_node> > inputs;
84 
85  /** A struct to hold the accompaning info for the node.
86  */
87  std::shared_ptr<qp_info> qpi;
88 
89  /**
90  * Makes copy of the node.
91  */
92  std::shared_ptr<planner_node> clone() {
93  return make_shared(operator_type, operator_parameters,
94  any_operator_parameters, inputs);
95  }
96 
97  /**
98  * Alternative constructor which creates a shared_ptr<planner_node>
99  */
100  static inline std::shared_ptr<planner_node> make_shared(
101  planner_node_type operator_type,
102  const std::map<std::string, flexible_type>& operator_parameters
103  = std::map<std::string, flexible_type>(),
104  const std::map<std::string, any>& any_operator_parameters
105  = std::map<std::string, any>(),
106  const std::vector<std::shared_ptr<planner_node>>& inputs
107  = std::vector<std::shared_ptr<planner_node>>()) {
108  return std::make_shared<planner_node>(operator_type, operator_parameters,
110  }
111 
112  ////////////////////////////////////////////////////////////////////////////////
113 
114 };
115 
116 /// A handy typedef
117 typedef std::shared_ptr<planner_node> pnode_ptr;
118 
119 /// \}
120 
121 } // namespace query_eval
122 } // namespace turi
123 
124 
125 
126 #endif // TURI_SFRAME_QUERY_ENGINE_PLANNER_NODE_HPP
std::shared_ptr< planner_node > clone()
std::map< std::string, any > any_operator_parameters
std::shared_ptr< qp_info > qpi
std::shared_ptr< planner_node > pnode_ptr
A handy typedef.
planner_node_type operator_type
static std::shared_ptr< planner_node > make_shared(planner_node_type operator_type, const std::map< std::string, flexible_type > &operator_parameters=std::map< std::string, flexible_type >(), const std::map< std::string, any > &any_operator_parameters=std::map< std::string, any >(), const std::vector< std::shared_ptr< planner_node >> &inputs=std::vector< std::shared_ptr< planner_node >>())
std::vector< std::shared_ptr< planner_node > > inputs
std::map< std::string, flexible_type > operator_parameters