static std::shared_ptr<planner_node> make_planner_node(const flexible_type& val, flex_type_enum type, size_t count) { ASSERT_TRUE(val.get_type() == type || val.get_type() == flex_type_enum::UNDEFINED); return planner_node::make_shared(planner_node_type::CONSTANT_NODE, {{"value", val}, {"type", (int)type}, {"begin_index", 0}, {"end_index", count}}); }
bool operator()(value_and_value_check<std::string>& val) const { if (new_value.get_type() == flex_type_enum::STRING) { return val.set_value((std::string)new_value); } else { return false; } }
static void call_lua_function(lua::Value& function, const flexible_type& arg, flexible_type& ret) { lua::Value valret; switch(arg.get_type()) { case flex_type_enum::INTEGER: valret = function(arg.get<flex_int>()); break; case flex_type_enum::FLOAT: valret = function(arg.get<flex_float>()); break; case flex_type_enum::STRING: valret = function(arg.get<flex_string>().c_str()); break; default: log_and_throw("Not Supported at the moment"); }; if (valret.is<lua::Integer>()) { lua::Integer val = 0; valret.get<lua::Integer>(val); ret = val; } else if (valret.is<lua::Number>()) { lua::Number val = 0; valret.get<lua::Number>(val); ret = val; } else if (valret.is<lua::String>()) { std::string val; valret.get<std::string>(val); ret = std::move(val); } else { ret = FLEX_UNDEFINED; } }
static void _to_serializable(flexible_type& data, schema_t& schema, const flexible_type& input) { switch (input.get_type()) { case flex_type_enum::INTEGER: data = input.get<flex_int>(); schema.insert(std::make_pair("type", JSON::types::INTEGER)); break; case flex_type_enum::FLOAT: _to_serializable(data, schema, input.get<flex_float>()); break; case flex_type_enum::STRING: data = input.get<flex_string>(); schema.insert(std::make_pair("type", JSON::types::STRING)); break; case flex_type_enum::VECTOR: _to_serializable(data, schema, input.get<flex_vec>()); break; case flex_type_enum::LIST: _to_serializable(data, schema, input.get<flex_list>()); break; case flex_type_enum::DICT: _to_serializable(data, schema, input.get<flex_dict>()); break; case flex_type_enum::DATETIME: _to_serializable(data, schema, input.get<flex_date_time>()); break; case flex_type_enum::IMAGE: _to_serializable(data, schema, input.get<flex_image>()); break; case flex_type_enum::UNDEFINED: data = FLEX_UNDEFINED; schema.insert(std::make_pair("type", JSON::types::UNDEFINED)); break; } }
bool operator()(value_and_value_check<int64_t>& val) const { if (new_value.get_type() == flex_type_enum::INTEGER || new_value.get_type() == flex_type_enum::FLOAT) { return val.set_value((int64_t)new_value); } else { return false; } }
flex_dict_view::flex_dict_view(const flexible_type& value) { if (value.get_type() == flex_type_enum::DICT) { m_flex_dict_ptr = &(value.get<flex_dict>()); return; } log_and_throw("Cannot construct a flex_dict_view object from type "); }
void continuous_result::update(const flexible_type& value) { // ignore undefined values if (value.get_type() == flex_type_enum::UNDEFINED) { return; } // assign min/max to return value if (value < this->min) { this->min = value; } if (value > this->max) { this->max = value; } // resize bins if needed this->rescale(this->min, this->max); // update count in bin size_t bin = get_bin_idx(value, this->scale_min, this->scale_max); this->bins[bin] += 1; }
/** * Helper utility for converting from flexible_type to json. * TODO: Fill in details */ inline JSONNode flexible_type_to_json(const flexible_type& val, std::string name) { if (val.get_type() == flex_type_enum::INTEGER) { // long cast needed to avoid a ambiguity error which seems to only show up // on mac clang++ if (std::isnan(val.get<flex_int>())) { // treat nan as missing value null JSONNode v(JSON_NULL); v.set_name(name); v.nullify(); return v; } else { return JSONNode(name, (long)val.get<flex_int>()); } } else if (val.get_type() == flex_type_enum::FLOAT) { if (std::isnan(val.get<double>())) { // treat nan as missing value null JSONNode v(JSON_NULL); v.set_name(name); v.nullify(); return v; } else { return JSONNode(name, val.get<double>()); } } else if (val.get_type() == flex_type_enum::STRING) { return JSONNode(name, val.get<flex_string>()); } else if (val.get_type() == flex_type_enum::VECTOR) { const std::vector<double>& v = val.get<flex_vec>(); JSONNode vec(JSON_ARRAY); for (size_t i = 0;i < v.size(); ++i) { JSONNode vecval(JSON_NUMBER); vecval= v[i]; vec.push_back(vecval); } vec.set_name(name); return vec; } else if (val.get_type() == flex_type_enum::DICT){ return JSONNode(name, val.get<flex_string>()); } else if (val.get_type() == flex_type_enum::UNDEFINED){ JSONNode v(JSON_NULL); v.set_name(name); v.nullify(); return v; } JSONNode v(JSON_NULL); v.set_name(name); v.nullify(); return v; }
/** Print a formatted flexible type to the output stream. */ void _print_flexible_type(std::ostringstream& ss, size_t width, const flexible_type& t) { switch(t.get_type()) { case flex_type_enum::FLOAT: _print_double(ss, width, t.get<double>()); return; case flex_type_enum::INTEGER: _print_long(ss, width, t.get<flex_int>()); return; case flex_type_enum::STRING: _print_string(ss, width, t.get<flex_string>()); return; default: _print_string(ss, width, std::string(t)); return; } }
void csv_writer::csv_print(std::ostream& out, const flexible_type& val) { switch(val.get_type()) { case flex_type_enum::INTEGER: case flex_type_enum::FLOAT: case flex_type_enum::VECTOR: out << std::string(val); break; case flex_type_enum::STRING: escape_string(val.get<flex_string>(), escape_char, quote_char, use_quote_char, double_quote, m_escape_buffer, m_escape_buffer_len); out.write(m_escape_buffer.c_str(), m_escape_buffer_len); break; case flex_type_enum::LIST: out << "["; for(size_t i = 0;i < val.get<flex_list>().size(); ++i) { csv_print(out, val.get<flex_list>()[i]); if (i + 1 < val.get<flex_list>().size()) out << ","; } out << "]"; break; case flex_type_enum::DICT: out << "{"; for(size_t i = 0;i < val.get<flex_dict>().size(); ++i) { csv_print(out, val.get<flex_dict>()[i].first); out << ":"; csv_print(out, val.get<flex_dict>()[i].second); if (i + 1 < val.get<flex_dict>().size()) out << ","; } out << "}"; break; case flex_type_enum::UNDEFINED: default: break; } }
field_id_type flexible_type_registry::register_field(std::string name, const flexible_type& value) { return register_field(name, value.get_type()); }
/** * Return the vertex partition number for given vertex id. */ inline size_t get_vertex_partition(const flexible_type& vid) { return vid.hash() % m_num_partitions; }