Turi Create  4.0
optonly_identity_operator.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_MANAGER_IDENTITY_NODE_HPP_
7 #define TURI_SFRAME_QUERY_MANAGER_IDENTITY_NODE_HPP_
8 
9 #include <core/data/flexible_type/flexible_type.hpp>
10 #include <core/random/random.hpp>
11 #include <core/parallel/pthread_tools.hpp>
12 #include <core/storage/query_engine/operators/operator.hpp>
13 #include <core/storage/query_engine/execution/query_context.hpp>
14 #include <core/storage/query_engine/operators/operator_properties.hpp>
15 #include <core/util/coro.hpp>
16 
17 namespace turi {
18 namespace query_eval {
19 
20 /**
21  * A no-op operator. Does not have a physical equivalent but only has
22  * a logical form. Used as a sentinel for the query optimizer.
23  */
24 template<>
25 class operator_impl<planner_node_type::IDENTITY_NODE> : public query_operator {
26  public:
27  planner_node_type type() const { return planner_node_type::IDENTITY_NODE; }
28 
29  static std::string name() { return "identity_node"; }
30 
31  static query_operator_attributes attributes() {
34  ret.num_inputs = 1;
35  return ret;
36  }
37 
38  ////////////////////////////////////////////////////////////////////////////////
39 
40  inline operator_impl() {}
41 
42  inline std::shared_ptr<query_operator> clone() const {
43  return std::make_shared<operator_impl>(*this);
44  }
45 
46  inline bool coro_running() const {
47  return false;
48  }
49 
50  static std::shared_ptr<planner_node> make_planner_node(std::shared_ptr<planner_node> pnode) {
51  auto pn = planner_node::make_shared(planner_node_type::IDENTITY_NODE);
52  pn->inputs = {pnode};
53  return pn;
54  }
55 
56  static std::vector<flex_type_enum> infer_type(std::shared_ptr<planner_node> pnode) {
57  ASSERT_EQ(pnode->inputs.size(), 1);
58  return infer_planner_node_type(pnode->inputs[0]);
59  }
60 
61  static int64_t infer_length(std::shared_ptr<planner_node> pnode) {
62  ASSERT_EQ(pnode->inputs.size(), 1);
63  return infer_planner_node_length(pnode->inputs[0]);
64  }
65 
66 };
67 
69 
70 } // query_eval
71 } // turicreate
72 
73 #endif
int64_t infer_planner_node_length(std::shared_ptr< planner_node > pnode)
int num_inputs
Number of inputs expected to the operator.
Definition: operator.hpp:56
size_t attribute_bitfield
A bitfield of the attribute enum.
Definition: operator.hpp:55
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< flex_type_enum > infer_planner_node_type(std::shared_ptr< planner_node > pnode)