6 #ifndef TURI_SFRAME_QUERY_MANAGER_CONSTANT_HPP 7 #define TURI_SFRAME_QUERY_MANAGER_CONSTANT_HPP 8 #include <core/logging/assertions.hpp> 9 #include <core/data/flexible_type/flexible_type.hpp> 10 #include <core/storage/query_engine/operators/operator.hpp> 11 #include <core/storage/query_engine/execution/query_context.hpp> 12 #include <core/storage/query_engine/operators/operator_properties.hpp> 15 namespace query_eval {
31 DECL_CORO_STATE(execute);
32 std::shared_ptr<sframe_rows> retbuf;
38 static std::string name() {
return "constant"; }
52 inline std::string
print()
const {
53 return std::string(
"constant(") + (std::string)m_value +
")";
56 inline std::shared_ptr<query_operator>
clone()
const {
57 return std::make_shared<operator_impl>(m_value, m_len);
60 inline bool coro_running()
const {
61 return CORO_RUNNING(execute);
68 len = std::min(m_len - i, context.
block_size());
70 retbuf->resize(1, len);
71 for (
auto& value: *(retbuf->get_columns()[0])) value = m_value;
79 static std::shared_ptr<planner_node> make_planner_node(
const flexible_type& val,
87 {
"end_index", count}});
90 static std::shared_ptr<query_operator> from_planner_node(
91 std::shared_ptr<planner_node> pnode) {
93 ASSERT_EQ((
int)pnode->operator_type, (
int)planner_node_type::CONSTANT_NODE);
94 ASSERT_TRUE(pnode->operator_parameters.count(
"value"));
95 ASSERT_TRUE(pnode->operator_parameters.count(
"begin_index"));
96 ASSERT_TRUE(pnode->operator_parameters.count(
"end_index"));
97 ASSERT_TRUE(pnode->operator_parameters.count(
"type"));
98 size_t count = (
flex_int)pnode->operator_parameters[
"end_index"] -
99 (
flex_int)pnode->operator_parameters[
"begin_index"];
100 return std::make_shared<operator_impl>(pnode->operator_parameters[
"value"], count);
103 static std::vector<flex_type_enum> infer_type(
104 std::shared_ptr<planner_node> pnode) {
105 ASSERT_EQ((
int)pnode->operator_type, (
int)planner_node_type::CONSTANT_NODE);
106 ASSERT_TRUE(pnode->operator_parameters.count(
"type"));
107 return {(
flex_type_enum)(
int)(pnode->operator_parameters[
"type"])};
110 static int64_t infer_length(std::shared_ptr<planner_node> pnode) {
111 ASSERT_EQ((
int)pnode->operator_type, (
int)planner_node_type::CONSTANT_NODE);
112 size_t count = (
flex_int)pnode->operator_parameters[
"end_index"] -
113 (
flex_int)pnode->operator_parameters[
"begin_index"];
117 static std::string repr(std::shared_ptr<planner_node> pnode, pnode_tagger&) {
118 ASSERT_EQ((
int)pnode->operator_type, (
int)planner_node_type::CONSTANT_NODE);
119 ASSERT_TRUE(pnode->operator_parameters.count(
"value"));
120 ASSERT_TRUE(pnode->operator_parameters.count(
"begin_index"));
121 ASSERT_TRUE(pnode->operator_parameters.count(
"end_index"));
124 flex_int begin_index = pnode->operator_parameters[
"begin_index"];
125 flex_int end_index = pnode->operator_parameters[
"end_index"];
127 std::ostringstream ss;
129 ss <<
"Const(" << v <<
")[" << begin_index <<
":" << end_index <<
"]";
145 #endif // TURI_SFRAME_QUERY_MANAGER_CONSTANT_HPP
void execute(query_context &context)
int num_inputs
Number of inputs expected to the operator.
size_t attribute_bitfield
A bitfield of the attribute enum.
void emit(const std::shared_ptr< sframe_rows > &rows)
std::shared_ptr< sframe_rows > get_output_buffer()
flex_type_enum get_type() const
std::string print() const
#define ASSERT_TRUE(cond)
size_t block_size() const
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::shared_ptr< query_operator > clone() const