diff --git a/flex/codegen/src/hqps/hqps_scan_builder.h b/flex/codegen/src/hqps/hqps_scan_builder.h index 153d553c8eb0..cf210adf30f8 100644 --- a/flex/codegen/src/hqps/hqps_scan_builder.h +++ b/flex/codegen/src/hqps/hqps_scan_builder.h @@ -489,7 +489,7 @@ class ScanOpBuilder { return "uint32_t"; } else if (type == gs::PropertyType::UInt64()) { return "uint64_t"; - } else if (type == gs::PropertyType::String()) { + } else if (type == gs::PropertyType::StringView()) { return "std::string_view"; } else { LOG(FATAL) << "Currently only support int, long, string as primary key"; diff --git a/flex/codegen/src/pegasus_generator.h b/flex/codegen/src/pegasus_generator.h index 0cd35e36493d..3b3d4a6170ab 100644 --- a/flex/codegen/src/pegasus_generator.h +++ b/flex/codegen/src/pegasus_generator.h @@ -160,7 +160,8 @@ class PegasusGenerator { std::string plan_json; google::protobuf::util::JsonPrintOptions option; option.always_print_primitive_fields = true; - auto st = google::protobuf::util::MessageToJsonString(plan_, &plan_json, option); + auto st = + google::protobuf::util::MessageToJsonString(plan_, &plan_json, option); for (auto i = 0; i < size; ++i) { auto op = plan_.plan(i); LOG(INFO) << "Start codegen for operator " << i; diff --git a/flex/engines/graph_db/database/graph_db_session.cc b/flex/engines/graph_db/database/graph_db_session.cc index 160cf7fea11a..979b14ec55a4 100644 --- a/flex/engines/graph_db/database/graph_db_session.cc +++ b/flex/engines/graph_db/database/graph_db_session.cc @@ -99,7 +99,7 @@ std::shared_ptr GraphDBSession::get_vertex_id_column( dynamic_cast&>( db_.graph().lf_indexers_[label].get_keys())); } else if (db_.graph().lf_indexers_[label].get_type() == - PropertyType::kString) { + PropertyType::kStringView) { return std::make_shared>( dynamic_cast&>( db_.graph().lf_indexers_[label].get_keys())); diff --git a/flex/engines/graph_db/database/insert_transaction.cc b/flex/engines/graph_db/database/insert_transaction.cc index a77105734b8b..975fc75ea322 100644 --- a/flex/engines/graph_db/database/insert_transaction.cc +++ b/flex/engines/graph_db/database/insert_transaction.cc @@ -55,7 +55,7 @@ bool InsertTransaction::AddVertex(label_t label, const Any& id, for (int col_i = 0; col_i != col_num; ++col_i) { auto& prop = props[col_i]; if (prop.type != types[col_i]) { - if (prop.type == PropertyType::kString && + if (prop.type == PropertyType::kStringView && types[col_i] == PropertyType::kStringMap) { } else { arc_.Resize(arc_size); diff --git a/flex/engines/graph_db/database/single_vertex_insert_transaction.cc b/flex/engines/graph_db/database/single_vertex_insert_transaction.cc index 2821af8cd4ca..d18a43f93258 100644 --- a/flex/engines/graph_db/database/single_vertex_insert_transaction.cc +++ b/flex/engines/graph_db/database/single_vertex_insert_transaction.cc @@ -55,7 +55,7 @@ bool SingleVertexInsertTransaction::AddVertex(label_t label, const Any& id, for (int col_i = 0; col_i != col_num; ++col_i) { auto& prop = props[col_i]; if (prop.type != types[col_i]) { - if (!(prop.type == PropertyType::kString && + if (!(prop.type == PropertyType::kStringView && types[col_i] == PropertyType::kStringMap)) { arc_.Resize(arc_size); std::string label_name = graph_.schema().get_vertex_label_name(label); diff --git a/flex/engines/graph_db/database/transaction_utils.h b/flex/engines/graph_db/database/transaction_utils.h index 38feff7216d2..04cf1f6e59e0 100644 --- a/flex/engines/graph_db/database/transaction_utils.h +++ b/flex/engines/graph_db/database/transaction_utils.h @@ -36,7 +36,10 @@ inline void serialize_field(grape::InArchive& arc, const Any& prop) { arc << prop.value.d.milli_second; } else if (prop.type == PropertyType::Day()) { arc << prop.value.day.to_u32(); - } else if (prop.type == PropertyType::String()) { + } else if (prop.type.type_enum == impl::PropertyTypeImpl::kString) { + std::string_view s = *prop.value.s_ptr; + arc << s; + } else if (prop.type == PropertyType::StringView()) { arc << prop.value.s; } else if (prop.type == PropertyType::Int64()) { arc << prop.value.l; @@ -72,7 +75,7 @@ inline void deserialize_field(grape::OutArchive& arc, Any& prop) { uint32_t val; arc >> val; prop.value.day.from_u32(val); - } else if (prop.type == PropertyType::String()) { + } else if (prop.type == PropertyType::StringView()) { arc >> prop.value.s; } else if (prop.type == PropertyType::Int64()) { arc >> prop.value.l; diff --git a/flex/engines/graph_db/database/update_transaction.cc b/flex/engines/graph_db/database/update_transaction.cc index 4f4bee7da7ea..cc3740604445 100644 --- a/flex/engines/graph_db/database/update_transaction.cc +++ b/flex/engines/graph_db/database/update_transaction.cc @@ -52,7 +52,8 @@ UpdateTransaction::UpdateTransaction(MutablePropertyFragment& graph, } else if (graph_.lf_indexers_[idx].get_type() == PropertyType::kUInt32) { added_vertices_.emplace_back( std::make_shared>()); - } else if (graph_.lf_indexers_[idx].get_type() == PropertyType::kString) { + } else if (graph_.lf_indexers_[idx].get_type() == + PropertyType::kStringView) { added_vertices_.emplace_back( std::make_shared>()); } else { @@ -125,7 +126,7 @@ bool UpdateTransaction::AddVertex(label_t label, const Any& oid, for (int col_i = 0; col_i != col_num; ++col_i) { if (props[col_i].type != types[col_i]) { if (types[col_i] == PropertyType::kStringMap && - props[col_i].type == PropertyType::kString) { + props[col_i].type == PropertyType::kStringView) { continue; } return false; @@ -484,9 +485,9 @@ void UpdateTransaction::set_edge_data_with_offset( label_t edge_label, const Any& value, size_t offset) { size_t csr_index = dir ? get_out_csr_index(label, neighbor_label, edge_label) : get_in_csr_index(neighbor_label, label, edge_label); - if (value.type == PropertyType::kString) { + if (value.type == PropertyType::kStringView) { size_t loc = sv_vec_.size(); - sv_vec_.emplace_back(std::string(value.value.s)); + sv_vec_.emplace_back(value.AsStringView()); Any dup_value; dup_value.set_string(sv_vec_[loc]); updated_edge_data_[csr_index][v].emplace( @@ -555,7 +556,8 @@ void UpdateTransaction::IngestWal(MutablePropertyFragment& graph, } else if (graph.lf_indexers_[idx].get_type() == PropertyType::kUInt32) { added_vertices.emplace_back( std::make_shared>()); - } else if (graph.lf_indexers_[idx].get_type() == PropertyType::kString) { + } else if (graph.lf_indexers_[idx].get_type() == + PropertyType::kStringView) { added_vertices.emplace_back( std::make_shared>()); } else { diff --git a/flex/engines/graph_db/grin/predefine.h b/flex/engines/graph_db/grin/predefine.h index 22f87a57b97e..6c3d62a514be 100644 --- a/flex/engines/graph_db/grin/predefine.h +++ b/flex/engines/graph_db/grin/predefine.h @@ -49,7 +49,7 @@ typedef enum { UInt64 = 4, ///< unsigned long int Float = 5, ///< float Double = 6, ///< double - String = 7, ///< string + StringView = 7, ///< string Date32 = 8, ///< date Time32 = 9, ///< Time32 Timestamp64 = 10, ///< Timestamp diff --git a/flex/engines/graph_db/grin/src/index/pk.cc b/flex/engines/graph_db/grin/src/index/pk.cc index ce0165c4cc77..5d4a924ccd23 100644 --- a/flex/engines/graph_db/grin/src/index/pk.cc +++ b/flex/engines/graph_db/grin/src/index/pk.cc @@ -54,7 +54,7 @@ GRIN_VERTEX grin_get_vertex_by_primary_keys_row(GRIN_GRAPH g, if (!_g->g.get_lid(label, oid, vid)) { return GRIN_NULL_VERTEX; } - } else if (type == gs::PropertyType::kString) { + } else if (type == gs::PropertyType::kStringView) { auto oid = *static_cast((*_r)[0]); if (!_g->g.get_lid(label, oid, vid)) { return GRIN_NULL_VERTEX; diff --git a/flex/engines/graph_db/grin/src/predefine.cc b/flex/engines/graph_db/grin/src/predefine.cc index 8bb94c10ed9e..299804fcde3a 100644 --- a/flex/engines/graph_db/grin/src/predefine.cc +++ b/flex/engines/graph_db/grin/src/predefine.cc @@ -11,8 +11,8 @@ GRIN_DATATYPE _get_data_type(const gs::PropertyType& type) { return GRIN_DATATYPE::Int64; } else if (type == gs::PropertyType::kUInt64) { return GRIN_DATATYPE::UInt64; - } else if (type == gs::PropertyType::kString) { - return GRIN_DATATYPE::String; + } else if (type == gs::PropertyType::kStringView) { + return GRIN_DATATYPE::StringView; } else if (type == gs::PropertyType::kDate) { return GRIN_DATATYPE::Timestamp64; } else if (type == gs::PropertyType::kDouble) { @@ -52,7 +52,7 @@ void init_cache(GRIN_GRAPH_T* g) { tmp.emplace_back(std::dynamic_pointer_cast( table.get_column_by_id(idx)) .get()); - } else if (type == gs::PropertyType::kString) { + } else if (type == gs::PropertyType::kStringView) { tmp.emplace_back(std::dynamic_pointer_cast( table.get_column_by_id(idx)) .get()); diff --git a/flex/engines/graph_db/grin/src/property/primarykey.cc b/flex/engines/graph_db/grin/src/property/primarykey.cc index 5cbee5e0b9a0..f749759ae0ea 100644 --- a/flex/engines/graph_db/grin/src/property/primarykey.cc +++ b/flex/engines/graph_db/grin/src/property/primarykey.cc @@ -42,8 +42,8 @@ GRIN_VERTEX_PROPERTY_LIST grin_get_primary_keys_by_vertex_type( vp += (GRIN_DATATYPE::UInt64 * 1u) << 16; } else if (type == gs::PropertyType::kUInt32) { vp += (GRIN_DATATYPE::UInt32 * 1u) << 16; - } else if (type == gs::PropertyType::kString) { - vp += (GRIN_DATATYPE::String * 1u) << 16; + } else if (type == gs::PropertyType::kStringView) { + vp += (GRIN_DATATYPE::StringView * 1u) << 16; } else { vp = GRIN_NULL_VERTEX_PROPERTY; } @@ -68,7 +68,7 @@ GRIN_ROW grin_get_vertex_primary_keys_row(GRIN_GRAPH g, GRIN_VERTEX v) { auto oid = _g->g.get_oid(label, vid).AsInt64(); auto p = new int64_t(oid); row->emplace_back(p); - } else if (type == gs::PropertyType::kString) { + } else if (type == gs::PropertyType::kStringView) { auto oid = _g->g.get_oid(label, vid).AsStringView(); auto p = new std::string_view(oid); row->emplace_back(p); diff --git a/flex/engines/graph_db/grin/src/property/property.cc b/flex/engines/graph_db/grin/src/property/property.cc index 0f3110073abd..74c1b19fa455 100644 --- a/flex/engines/graph_db/grin/src/property/property.cc +++ b/flex/engines/graph_db/grin/src/property/property.cc @@ -88,7 +88,7 @@ void grin_destroy_vertex_property(GRIN_GRAPH g, GRIN_VERTEX_PROPERTY vp) {} */ GRIN_DATATYPE grin_get_vertex_property_datatype(GRIN_GRAPH g, GRIN_VERTEX_PROPERTY vp) { - return (GRIN_DATATYPE)(vp >> 16); + return (GRIN_DATATYPE) (vp >> 16); } int grin_get_vertex_property_value_of_int32(GRIN_GRAPH g, GRIN_VERTEX v, @@ -203,7 +203,7 @@ const char* grin_get_vertex_property_value_of_string(GRIN_GRAPH g, auto pdt = (vp >> 16); auto pid = vp & (0xff); - if (label != plabel || pdt != GRIN_DATATYPE::String) { + if (label != plabel || pdt != GRIN_DATATYPE::StringView) { grin_error_code = INVALID_VALUE; return NULL; } @@ -341,7 +341,7 @@ const void* grin_get_vertex_property_value(GRIN_GRAPH g, GRIN_VERTEX v, return _col->extra_buffer().data() + vid - basic_size; } } - case GRIN_DATATYPE::String: { + case GRIN_DATATYPE::StringView: { auto _col = static_cast(col); auto s = _col->get_view(vid); auto len = s.size() + 1; @@ -475,7 +475,7 @@ const char* grin_get_edge_property_value_of_string(GRIN_GRAPH g, GRIN_EDGE e, GRIN_EDGE_PROPERTY ep) { auto _e = static_cast(e); auto idx = ep >> 24; - if (idx > 0 || _get_data_type(_e->data.type) != GRIN_DATATYPE::String) { + if (idx > 0 || _get_data_type(_e->data.type) != GRIN_DATATYPE::StringView) { grin_error_code = INVALID_VALUE; return NULL; } diff --git a/flex/engines/graph_db/grin/src/property/row.cc b/flex/engines/graph_db/grin/src/property/row.cc index 83d58f95c433..01c4ed8305d2 100644 --- a/flex/engines/graph_db/grin/src/property/row.cc +++ b/flex/engines/graph_db/grin/src/property/row.cc @@ -161,7 +161,7 @@ const void* grin_get_value_from_row(GRIN_GRAPH g, GRIN_ROW r, GRIN_DATATYPE dt, return static_cast((*_r)[idx]); case GRIN_DATATYPE::Double: return static_cast((*_r)[idx]); - case GRIN_DATATYPE::String: + case GRIN_DATATYPE::StringView: return static_cast((*_r)[idx]); case GRIN_DATATYPE::Date32: return static_cast((*_r)[idx]); @@ -244,7 +244,7 @@ GRIN_ROW grin_get_vertex_row(GRIN_GRAPH g, GRIN_VERTEX v) { } break; } - case GRIN_DATATYPE::String: { + case GRIN_DATATYPE::StringView: { auto _col = static_cast(col); auto s = _col->get_view(vid); auto len = s.size() + 1; @@ -317,7 +317,7 @@ GRIN_ROW grin_get_edge_row(GRIN_GRAPH g, GRIN_EDGE e) { r->emplace_back(new uint64_t(_e->data.value.ul)); break; } - case GRIN_DATATYPE::String: { + case GRIN_DATATYPE::StringView: { auto s = _e->data.value.s; auto len = s.size() + 1; char* out = new char[len]; diff --git a/flex/engines/graph_db/grin/src/topology/structure.cc b/flex/engines/graph_db/grin/src/topology/structure.cc index 12ce0499f2e1..835da3c8d39f 100644 --- a/flex/engines/graph_db/grin/src/topology/structure.cc +++ b/flex/engines/graph_db/grin/src/topology/structure.cc @@ -161,7 +161,7 @@ const void* grin_get_edge_data_value(GRIN_GRAPH, GRIN_EDGE e) { case GRIN_DATATYPE::Float: { return new float(_e->data.value.f); } - case GRIN_DATATYPE::String: { + case GRIN_DATATYPE::StringView: { auto s = _e->data.value.s; auto len = s.size() + 1; char* out = new char[len]; diff --git a/flex/engines/graph_db/grin/test/test.c b/flex/engines/graph_db/grin/test/test.c index 5997c3f2c66e..6aeb6ce48044 100644 --- a/flex/engines/graph_db/grin/test/test.c +++ b/flex/engines/graph_db/grin/test/test.c @@ -369,7 +369,7 @@ void test_property_vertex_property_value(const char* uri_str) { #else printf("%s %zu: %lld\n", v_names[__vt][vid], j, pv); #endif - } else if (dt == String) { + } else if (dt == StringView) { const char* pv = grin_get_vertex_property_value_of_string(g, v, vp); assert(grin_get_last_error_code() == NO_ERROR); #ifdef GRIN_ENABLE_ROW @@ -527,7 +527,7 @@ void test_property_edge_property_value(const char* uri_str, #else printf("%s %zu %lld: %lf\n", v_names[__vt][vid], j, uid, pv); #endif - } else if (dt == String) { + } else if (dt == StringView) { const char* pv = grin_get_edge_property_value_of_string(g, e, ep); assert(grin_get_last_error_code() == NO_ERROR); #ifdef GRIN_ENABLE_ROW diff --git a/flex/engines/hqps_db/core/operator/sink.h b/flex/engines/hqps_db/core/operator/sink.h index c852c9b7308d..01ab8a782b6b 100644 --- a/flex/engines/hqps_db/core/operator/sink.h +++ b/flex/engines/hqps_db/core/operator/sink.h @@ -114,8 +114,9 @@ void template_set_value(common::Value* value, T v) { } template ) &&( - !std::is_same_v)>::type* = nullptr> + typename std::enable_if< + (std::is_same_v) && + (!std::is_same_v)>::type* = nullptr> void template_set_value(common::Value* value, T v) { value->set_i64(v); } @@ -212,7 +213,7 @@ void set_any_to_element(const Any& any, results::Element* element) { element->mutable_object()->set_f64(any.value.f); } else if (any.type == PropertyType::Date()) { element->mutable_object()->set_i64(any.value.d.milli_second); - } else if (any.type == PropertyType::String()) { + } else if (any.type == PropertyType::StringView()) { element->mutable_object()->mutable_str()->assign(any.value.s.data(), any.value.s.size()); } else if (any.type == PropertyType::VertexGlobalId()) { @@ -260,7 +261,7 @@ void set_any_to_common_value(const Any& any, common::Value* value) { value->set_f64(any.value.f); } else if (any.type == PropertyType::Date()) { value->set_i64(any.value.d.milli_second); - } else if (any.type == PropertyType::String()) { + } else if (any.type == PropertyType::StringView()) { value->mutable_str()->assign(any.value.s.data(), any.value.s.size()); } else { LOG(WARNING) << "Unexpected property type: " diff --git a/flex/engines/hqps_db/database/mutable_csr_interface.h b/flex/engines/hqps_db/database/mutable_csr_interface.h index a37d9c6eb333..4d9547a0d3ff 100644 --- a/flex/engines/hqps_db/database/mutable_csr_interface.h +++ b/flex/engines/hqps_db/database/mutable_csr_interface.h @@ -892,7 +892,7 @@ class MutableCSRInterface { } else if (type == PropertyType::kUInt64) { return std::make_shared>( *std::dynamic_pointer_cast>(column)); - } else if (type == PropertyType::kString || type.IsVarchar()) { + } else if (type == PropertyType::kStringView || type.IsVarchar()) { return std::make_shared>( *std::dynamic_pointer_cast>(column)); } else if (type == PropertyType::kFloat) { diff --git a/flex/storages/rt_mutable_graph/loader/abstract_arrow_fragment_loader.cc b/flex/storages/rt_mutable_graph/loader/abstract_arrow_fragment_loader.cc index c30a065d27bd..eb93989c6765 100644 --- a/flex/storages/rt_mutable_graph/loader/abstract_arrow_fragment_loader.cc +++ b/flex/storages/rt_mutable_graph/loader/abstract_arrow_fragment_loader.cc @@ -197,7 +197,7 @@ void AbstractArrowFragmentLoader::AddVerticesRecordBatch( LOG(FATAL) << "Only support one primary key for vertex."; } auto type = std::get<0>(primary_keys[0]); - if (type != PropertyType::kInt64 && type != PropertyType::kString && + if (type != PropertyType::kInt64 && type != PropertyType::kStringView && type != PropertyType::kInt32 && type != PropertyType::kUInt32 && type != PropertyType::kUInt64) { LOG(FATAL) @@ -377,7 +377,8 @@ void AbstractArrowFragmentLoader::AddEdgesRecordBatch( } } else if (property_types[0].type_enum == impl::PropertyTypeImpl::kVarChar || - property_types[0].type_enum == impl::PropertyTypeImpl::kString) { + property_types[0].type_enum == + impl::PropertyTypeImpl::kStringView) { // Both varchar and string are treated as string. For String, we use the // default max length defined in PropertyType::STRING_DEFAULT_MAX_LENGTH const auto& prop = diff --git a/flex/storages/rt_mutable_graph/loader/abstract_arrow_fragment_loader.h b/flex/storages/rt_mutable_graph/loader/abstract_arrow_fragment_loader.h index 80cc1c738e91..d918efd0686d 100644 --- a/flex/storages/rt_mutable_graph/loader/abstract_arrow_fragment_loader.h +++ b/flex/storages/rt_mutable_graph/loader/abstract_arrow_fragment_loader.h @@ -256,7 +256,7 @@ static void append_edges(std::shared_ptr src_col, const std::shared_ptr& cur_col) { if (cur_indexer.get_type() == PropertyType::kInt64) { CHECK(cur_col->type()->Equals(arrow::int64())); - } else if (cur_indexer.get_type() == PropertyType::kString) { + } else if (cur_indexer.get_type() == PropertyType::kStringView) { CHECK(cur_col->type()->Equals(arrow::utf8()) || cur_col->type()->Equals(arrow::large_utf8())); } else if (cur_indexer.get_type() == PropertyType::kInt32) { diff --git a/flex/storages/rt_mutable_graph/mutable_property_fragment.cc b/flex/storages/rt_mutable_graph/mutable_property_fragment.cc index 04dcbe045a27..360d16ad0b8f 100644 --- a/flex/storages/rt_mutable_graph/mutable_property_fragment.cc +++ b/flex/storages/rt_mutable_graph/mutable_property_fragment.cc @@ -101,7 +101,7 @@ inline DualCsrBase* create_csr(EdgeStrategy oes, EdgeStrategy ies, } else if (properties[0].type_enum == impl::PropertyTypeImpl::kVarChar) { return new DualCsr( oes, ies, properties[0].additional_type_info.max_length); - } else if (properties[0] == PropertyType::kString) { + } else if (properties[0] == PropertyType::kStringView) { return new DualCsr(oes, ies, 256); } } else { diff --git a/flex/storages/rt_mutable_graph/schema.cc b/flex/storages/rt_mutable_graph/schema.cc index 9b143b14e1e6..e0052a6c38fa 100644 --- a/flex/storages/rt_mutable_graph/schema.cc +++ b/flex/storages/rt_mutable_graph/schema.cc @@ -717,7 +717,7 @@ static Status parse_vertex_schema(YAML::Node node, Schema& schema) { "Primary key " + primary_key_name + " is not found in properties"); } if (property_types[primary_key_inds[i]] != PropertyType::kInt64 && - property_types[primary_key_inds[i]] != PropertyType::kString && + property_types[primary_key_inds[i]] != PropertyType::kStringView && property_types[primary_key_inds[i]] != PropertyType::kUInt64 && property_types[primary_key_inds[i]] != PropertyType::kInt32 && property_types[primary_key_inds[i]] != PropertyType::kUInt32 && @@ -784,7 +784,7 @@ static Status parse_edge_schema(YAML::Node node, Schema& schema) { property_types, prop_names, schema.GetVersion())); - if (node["description"]) { + if (node["description"]) { description = node["description"].as(); } if (node["nullable"]) { diff --git a/flex/tests/rt_mutable_graph/multiple_props_edge_test.cc b/flex/tests/rt_mutable_graph/multiple_props_edge_test.cc index 4715cdb7aec5..045b90916667 100644 --- a/flex/tests/rt_mutable_graph/multiple_props_edge_test.cc +++ b/flex/tests/rt_mutable_graph/multiple_props_edge_test.cc @@ -52,7 +52,7 @@ class TestMultiplePropertiesEdge { auto data = oe->get_data().AsRecordView(); CHECK(data.size() == 2) << "Inconsistent size, Except: 2, Got " << data.size(); - CHECK(data[0].type == PropertyType::kString) + CHECK(data[0].type == PropertyType::kStringView) << "Inconsistent type, Except: string, Got " << data[0].type; CHECK(data[1].type == PropertyType::kInt32) << "Inconsistent type, Except: int, Got " << data[1].type; @@ -60,7 +60,7 @@ class TestMultiplePropertiesEdge { LOG(INFO) << "Finish test get edge\n"; } - void test_get_graph_view(int64_t src, const std::string& dst) { + void test_get_graph_view(int64_t src, const std::string_view& dst) { auto txn = db_.GetReadTransaction(); vid_t src_lid, dst_lid; @@ -109,7 +109,7 @@ class TestMultiplePropertiesEdge { { auto txn = db_.GetSingleEdgeInsertTransaction(); - std::string str = "test"; + std::string_view str = "test"; CHECK(txn.AddEdge(src_label_, src, dst_label_, dst, edge_label_, {Any::From(str), Any::From(2012)})) << "Add edge failed\n"; diff --git a/flex/tests/rt_mutable_graph/string_edge_property_test.cc b/flex/tests/rt_mutable_graph/string_edge_property_test.cc index 4b20e7e1039f..73c0604dbe4c 100644 --- a/flex/tests/rt_mutable_graph/string_edge_property_test.cc +++ b/flex/tests/rt_mutable_graph/string_edge_property_test.cc @@ -47,7 +47,7 @@ class TestStringEdgeProperty { auto oe = db_.graph().get_outgoing_edges(src_label_, src_lid, dst_label_, edge_label_); CHECK(oe != nullptr) << "Got nullptr oe\n"; - CHECK(oe->get_data().type == PropertyType::kString) + CHECK(oe->get_data().type == PropertyType::kStringView) << "Inconsistent type, Except: string, Got " << oe->get_data().type; std::cout << oe->get_data().AsStringView() << "\n"; LOG(INFO) << "Finish test get edge\n"; diff --git a/flex/tests/rt_mutable_graph/test_acid.cc b/flex/tests/rt_mutable_graph/test_acid.cc index 2150bd05b7f7..42ba41d6b588 100644 --- a/flex/tests/rt_mutable_graph/test_acid.cc +++ b/flex/tests/rt_mutable_graph/test_acid.cc @@ -43,7 +43,7 @@ oid_t generate_id() { void append_string_to_field(gs::UpdateTransaction::vertex_iterator& vit, int col_id, const std::string& str) { - std::string cur_str = vit.GetField(col_id).AsString(); + std::string cur_str = std::string(vit.GetField(col_id).AsStringView()); if (cur_str.empty()) { cur_str = str; } else { @@ -449,7 +449,7 @@ std::tuple G0Check(GraphDB& db, break; } } - std::string p1_version_history = vit1.GetField(1).AsString(); + std::string p1_version_history = std::string(vit1.GetField(1).AsStringView()); auto vit2 = txn.GetVertexIterator(person_label_id); for (; vit2.IsValid(); vit2.Next()) { @@ -457,7 +457,7 @@ std::tuple G0Check(GraphDB& db, break; } } - std::string p2_version_history = vit2.GetField(1).AsString(); + std::string p2_version_history = std::string(vit2.GetField(1).AsStringView()); auto oeit = txn.GetOutEdgeIterator(person_label_id, vit1.GetIndex(), person_label_id, knows_label_id); diff --git a/flex/utils/arrow_utils.cc b/flex/utils/arrow_utils.cc index 220f96881f1c..580b1b2591b2 100644 --- a/flex/utils/arrow_utils.cc +++ b/flex/utils/arrow_utils.cc @@ -34,7 +34,7 @@ std::shared_ptr PropertyTypeToArrowType(PropertyType type) { return arrow::timestamp(arrow::TimeUnit::MILLI); } else if (type == PropertyType::Day()) { return arrow::timestamp(arrow::TimeUnit::MILLI); - } else if (type == PropertyType::String()) { + } else if (type == PropertyType::StringView()) { return arrow::large_utf8(); } else if (type == PropertyType::StringMap()) { return arrow::large_utf8(); diff --git a/flex/utils/arrow_utils.h b/flex/utils/arrow_utils.h index ea9b6941854c..854fc9b57cdd 100644 --- a/flex/utils/arrow_utils.h +++ b/flex/utils/arrow_utils.h @@ -312,7 +312,7 @@ struct TypeConverter { }; template <> struct TypeConverter { - static PropertyType property_type() { return PropertyType::kString; } + static PropertyType property_type() { return PropertyType::kStringView; } using ArrowType = arrow::LargeStringType; using ArrowArrayType = arrow::LargeStringArray; static std::shared_ptr ArrowTypeValue() { @@ -322,7 +322,7 @@ struct TypeConverter { template <> struct TypeConverter { - static PropertyType property_type() { return PropertyType::kString; } + static PropertyType property_type() { return PropertyType::kStringView; } using ArrowType = arrow::LargeStringType; using ArrowArrayType = arrow::LargeStringArray; static std::shared_ptr ArrowTypeValue() { diff --git a/flex/utils/id_indexer.h b/flex/utils/id_indexer.h index 4e15df69f9f1..67f665513346 100644 --- a/flex/utils/id_indexer.h +++ b/flex/utils/id_indexer.h @@ -239,7 +239,7 @@ class LFIndexer { } else if (type.type_enum == impl::PropertyTypeImpl::kVarChar) { keys_ = new StringColumn(StorageStrategy::kMem, type.additional_type_info.max_length); - } else if (type.type_enum == impl::PropertyTypeImpl::kString) { + } else if (type.type_enum == impl::PropertyTypeImpl::kStringView) { LOG(WARNING) << "String type is a deprecated type, use varchar instead."; LOG(WARNING) << "Use default max length" << PropertyType::STRING_DEFAULT_MAX_LENGTH diff --git a/flex/utils/property/column.cc b/flex/utils/property/column.cc index 660f105b225a..8f2ec478266e 100644 --- a/flex/utils/property/column.cc +++ b/flex/utils/property/column.cc @@ -78,7 +78,7 @@ class TypedEmptyColumn : public ColumnBase { size_t size() const override { return 0; } void resize(size_t size) override {} - PropertyType type() const override { return PropertyType::kString; } + PropertyType type() const override { return PropertyType::kStringView; } void set_value(size_t index, const std::string_view& val) {} @@ -161,7 +161,7 @@ std::shared_ptr CreateColumn(PropertyType type, return std::make_shared(strategy); } else if (type == PropertyType::kStringMap) { return std::make_shared(strategy); - } else if (type == PropertyType::kString) { + } else if (type == PropertyType::kStringView) { return std::make_shared(strategy); } else if (type.type_enum == impl::PropertyTypeImpl::kVarChar) { return std::make_shared( diff --git a/flex/utils/property/column.h b/flex/utils/property/column.h index f1f328cf029b..df0d58089cd7 100644 --- a/flex/utils/property/column.h +++ b/flex/utils/property/column.h @@ -387,7 +387,7 @@ class TypedColumn : public ColumnBase { } void set_any(size_t idx, const Any& value) override { - set_value(idx, AnyConverter::from_any(value)); + set_value(idx, value.AsStringView()); } std::string_view get_view(size_t idx) const { @@ -480,7 +480,7 @@ class StringMapColumn : public ColumnBase { void set_value(size_t idx, const std::string_view& val); void set_any(size_t idx, const Any& value) override { - set_value(idx, AnyConverter::from_any(value)); + set_value(idx, value.AsStringView()); } std::string_view get_view(size_t idx) const; diff --git a/flex/utils/property/types.cc b/flex/utils/property/types.cc index 51d6700538e7..26c1b26bf035 100644 --- a/flex/utils/property/types.cc +++ b/flex/utils/property/types.cc @@ -33,7 +33,7 @@ std::string PrimitivePropertyTypeToString(PropertyType type) { return DT_DATE; } else if (type == PropertyType::kDay) { return DT_DAY; - } else if (type == PropertyType::kString) { + } else if (type == PropertyType::kStringView) { return DT_STRING; } else if (type == PropertyType::kStringMap) { return DT_STRINGMAP; @@ -180,8 +180,8 @@ const PropertyType PropertyType::kDate = PropertyType(impl::PropertyTypeImpl::kDate); const PropertyType PropertyType::kDay = PropertyType(impl::PropertyTypeImpl::kDay); -const PropertyType PropertyType::kString = - PropertyType(impl::PropertyTypeImpl::kString); +const PropertyType PropertyType::kStringView = + PropertyType(impl::PropertyTypeImpl::kStringView); const PropertyType PropertyType::kStringMap = PropertyType(impl::PropertyTypeImpl::kStringMap); const PropertyType PropertyType::kVertexGlobalId = @@ -192,6 +192,8 @@ const PropertyType PropertyType::kRecordView = PropertyType(impl::PropertyTypeImpl::kRecordView); const PropertyType PropertyType::kRecord = PropertyType(impl::PropertyTypeImpl::kRecord); +const PropertyType PropertyType::kString = + PropertyType(impl::PropertyTypeImpl::kString); bool PropertyType::operator==(const PropertyType& other) const { if (type_enum == impl::PropertyTypeImpl::kVarChar && @@ -199,10 +201,18 @@ bool PropertyType::operator==(const PropertyType& other) const { return additional_type_info.max_length == other.additional_type_info.max_length; } - if ((type_enum == impl::PropertyTypeImpl::kString && + if ((type_enum == impl::PropertyTypeImpl::kStringView && other.type_enum == impl::PropertyTypeImpl::kVarChar) || (type_enum == impl::PropertyTypeImpl::kVarChar && - other.type_enum == impl::PropertyTypeImpl::kString)) { + other.type_enum == impl::PropertyTypeImpl::kStringView)) { + return true; + } + if ((type_enum == impl::PropertyTypeImpl::kString && + (other.type_enum == impl::PropertyTypeImpl::kStringView || + other.type_enum == impl::PropertyTypeImpl::kVarChar)) || + (other.type_enum == impl::PropertyTypeImpl::kString && + (type_enum == impl::PropertyTypeImpl::kStringView || + type_enum == impl::PropertyTypeImpl::kVarChar))) { return true; } return type_enum == other.type_enum; @@ -257,6 +267,9 @@ PropertyType PropertyType::Day() { PropertyType PropertyType::String() { return PropertyType(impl::PropertyTypeImpl::kString); } +PropertyType PropertyType::StringView() { + return PropertyType(impl::PropertyTypeImpl::kStringView); +} PropertyType PropertyType::StringMap() { return PropertyType(impl::PropertyTypeImpl::kStringMap); } @@ -322,7 +335,12 @@ grape::InArchive& operator<<(grape::InArchive& in_archive, const Any& value) { in_archive << value.type << value.value.d.milli_second; } else if (value.type == PropertyType::Day()) { in_archive << value.type << value.value.day.to_u32(); - } else if (value.type == PropertyType::String()) { + } else if (value.type == impl::PropertyTypeImpl::kString) { + // serialize as string_view + auto s = *value.value.s_ptr; + auto type = PropertyType::StringView(); + in_archive << type << s; + } else if (value.type == PropertyType::StringView()) { in_archive << value.type << value.value.s; } else if (value.type == PropertyType::VertexGlobalId()) { in_archive << value.type << value.value.vertex_gid; @@ -371,7 +389,9 @@ grape::OutArchive& operator>>(grape::OutArchive& out_archive, Any& value) { uint32_t val; out_archive >> val; value.value.day.from_u32(val); - } else if (value.type == PropertyType::String()) { + } else if (value.type.type_enum == impl::PropertyTypeImpl::kString) { + LOG(FATAL) << "Not supported"; + } else if (value.type == PropertyType::StringView()) { out_archive >> value.value.s; } else if (value.type == PropertyType::VertexGlobalId()) { out_archive >> value.value.vertex_gid; diff --git a/flex/utils/property/types.h b/flex/utils/property/types.h index 66fd523f982b..7fd13bba8f2d 100644 --- a/flex/utils/property/types.h +++ b/flex/utils/property/types.h @@ -67,7 +67,7 @@ enum class PropertyTypeImpl { kInt32, kDate, kDay, - kString, + kStringView, kEmpty, kInt64, kDouble, @@ -83,6 +83,7 @@ enum class PropertyTypeImpl { kLabel, kRecordView, kRecord, + kString, }; // Stores additional type information for PropertyTypeImpl @@ -119,13 +120,14 @@ struct PropertyType { static PropertyType Double(); static PropertyType Date(); static PropertyType Day(); - static PropertyType String(); + static PropertyType StringView(); static PropertyType StringMap(); static PropertyType Varchar(uint16_t max_length); static PropertyType VertexGlobalId(); static PropertyType Label(); static PropertyType RecordView(); static PropertyType Record(); + static PropertyType String(); static const PropertyType kEmpty; static const PropertyType kBool; @@ -139,12 +141,13 @@ struct PropertyType { static const PropertyType kDouble; static const PropertyType kDate; static const PropertyType kDay; - static const PropertyType kString; + static const PropertyType kStringView; static const PropertyType kStringMap; static const PropertyType kVertexGlobalId; static const PropertyType kLabel; static const PropertyType kRecordView; static const PropertyType kRecord; + static const PropertyType kString; bool operator==(const PropertyType& other) const; bool operator!=(const PropertyType& other) const; @@ -310,6 +313,43 @@ struct Record { size_t len; Any* props; }; + +struct StringPtr { + StringPtr() : ptr(nullptr) {} + StringPtr(const std::string& str) : ptr(new std::string(str)) {} + StringPtr(const StringPtr& other) { + if (other.ptr) { + ptr = new std::string(*other.ptr); + } else { + ptr = nullptr; + } + } + StringPtr(StringPtr&& other) : ptr(other.ptr) { other.ptr = nullptr; } + StringPtr& operator=(const StringPtr& other) { + if (this == &other) { + return *this; + } + if (ptr) { + delete ptr; + } + if (other.ptr) { + ptr = new std::string(*other.ptr); + } else { + ptr = nullptr; + } + return *this; + } + ~StringPtr() { + if (ptr) { + delete ptr; + } + } + // return string_view + std::string_view operator*() const { + return std::string_view((*ptr).data(), (*ptr).size()); + } + std::string* ptr; +}; union AnyValue { AnyValue() {} ~AnyValue() {} @@ -333,6 +373,7 @@ union AnyValue { // Non-trivial types Record record; + StringPtr s_ptr; }; template @@ -344,6 +385,8 @@ struct Any { Any(const Any& other) : type(other.type) { if (type == PropertyType::kRecord) { new (&value.record) Record(other.value.record); + } else if (type.type_enum == impl::PropertyTypeImpl::kString) { + new (&value.s_ptr) StringPtr(other.value.s_ptr); } else { memcpy(static_cast(&value), static_cast(&other.value), sizeof(AnyValue)); @@ -353,6 +396,8 @@ struct Any { Any(Any&& other) : type(other.type) { if (type == PropertyType::kRecord) { new (&value.record) Record(std::move(other.value.record)); + } else if (type.type_enum == impl::PropertyTypeImpl::kString) { + new (&value.s_ptr) StringPtr(std::move(other.value.s_ptr)); } else { memcpy(static_cast(&value), static_cast(&other.value), sizeof(AnyValue)); @@ -368,12 +413,19 @@ struct Any { new (&value.record) Record(vec); } + Any(const std::string& str) { + type = PropertyType::kString; + new (&value.s_ptr) StringPtr(str); + } + template Any(const T& val) { Any a = Any::From(val); type = a.type; if (type == PropertyType::kRecord) { new (&value.record) Record(a.value.record); + } else if (type.type_enum == impl::PropertyTypeImpl::kString) { + new (&value.s_ptr) StringPtr(a.value.s_ptr); } else { memcpy(static_cast(&value), static_cast(&a.value), sizeof(AnyValue)); @@ -390,6 +442,8 @@ struct Any { type = other.type; if (type == PropertyType::kRecord) { new (&value.record) Record(other.value.record); + } else if (type.type_enum == impl::PropertyTypeImpl::kString) { + new (&value.s_ptr) StringPtr(other.value.s_ptr); } else { memcpy(static_cast(&value), static_cast(&other.value), sizeof(AnyValue)); @@ -400,6 +454,8 @@ struct Any { ~Any() { if (type == PropertyType::kRecord) { value.record.~Record(); + } else if (type.type_enum == impl::PropertyTypeImpl::kString) { + value.s_ptr.~StringPtr(); } } @@ -457,11 +513,16 @@ struct Any { value.day = v; } - void set_string(std::string_view v) { - type = PropertyType::kString; + void set_string_view(std::string_view v) { + type = PropertyType::kStringView; value.s = v; } + void set_string(const std::string& v) { + type = PropertyType::kString; + new (&value.s_ptr) StringPtr(v); + } + void set_float(float v) { type = PropertyType::kFloat; value.f = v; @@ -500,7 +561,9 @@ struct Any { return std::to_string(value.i); } else if (type == PropertyType::kInt64) { return std::to_string(value.l); - } else if (type == PropertyType::kString) { + } else if (type.type_enum == impl::PropertyTypeImpl::kString) { + return *value.s_ptr.ptr; + } else if (type == PropertyType::kStringView) { return std::string(value.s.data(), value.s.size()); // return value.s.to_string(); } else if (type == PropertyType::kDate) { @@ -534,9 +597,9 @@ struct Any { } } - std::string AsString() const { - assert(type == PropertyType::kString); - return std::string(value.s); + const std::string& AsString() const { + assert(type.type_enum == impl::PropertyTypeImpl::kString); + return *value.s_ptr.ptr; } int64_t AsInt64() const { @@ -574,9 +637,13 @@ struct Any { return value.f; } - const std::string_view& AsStringView() const { - assert(type == PropertyType::kString); - return value.s; + std::string_view AsStringView() const { + assert(type == PropertyType::kStringView); + if (type.type_enum != impl::PropertyTypeImpl::kString) { + return value.s; + } else { + return *value.s_ptr.ptr; + } } const Date& AsDate() const { @@ -624,8 +691,10 @@ struct Any { return value.d.milli_second == other.value.d.milli_second; } else if (type == PropertyType::kDay) { return value.day == other.value.day; - } else if (type == PropertyType::kString) { - return value.s == other.value.s; + } else if (type.type_enum == impl::PropertyTypeImpl::kString) { + return *value.s_ptr == other.AsStringView(); + } else if (type == PropertyType::kStringView) { + return value.s == other.AsStringView(); } else if (type == PropertyType::kEmpty) { return true; } else if (type == PropertyType::kDouble) { @@ -678,8 +747,10 @@ struct Any { return value.d.milli_second < other.value.d.milli_second; } else if (type == PropertyType::kDay) { return value.day < other.value.day; - } else if (type == PropertyType::kString) { - return value.s < other.value.s; + } else if (type.type_enum == impl::PropertyTypeImpl::kString) { + return *value.s_ptr < other.AsStringView(); + } else if (type == PropertyType::kStringView) { + return value.s < other.AsStringView(); } else if (type == PropertyType::kEmpty) { return false; } else if (type == PropertyType::kDouble) { @@ -811,15 +882,15 @@ struct ConvertAny { template <> struct ConvertAny { static void to(const Any& value, std::string& out) { - CHECK(value.type == PropertyType::kString); - out = std::string(value.value.s); + CHECK(value.type.type_enum == impl::PropertyTypeImpl::kString); + out = *value.value.s_ptr.ptr; } }; template <> struct ConvertAny { static void to(const Any& value, std::string_view& out) { - CHECK(value.type == PropertyType::kString); + CHECK(value.type == PropertyType::kStringView); out = value.value.s; } }; @@ -1056,16 +1127,17 @@ struct AnyConverter { template <> struct AnyConverter { - static PropertyType type() { return PropertyType::kString; } + static PropertyType type() { return PropertyType::kStringView; } static Any to_any(const std::string_view& value) { Any ret; - ret.set_string(value); + ret.set_string_view(value); return ret; } static const std::string_view& from_any(const Any& value) { - CHECK(value.type == PropertyType::kString); + CHECK(value.type == PropertyType::kStringView && + value.type.type_enum != impl::PropertyTypeImpl::kString); return value.value.s; } @@ -1084,13 +1156,13 @@ struct AnyConverter { return ret; } - static std::string from_any(const Any& value) { - CHECK(value.type == PropertyType::kString); - return std::string(value.value.s); + static std::string& from_any(const Any& value) { + CHECK(value.type.type_enum == impl::PropertyTypeImpl::kString); + return *value.value.s_ptr.ptr; } - static std::string from_any_value(const AnyValue& value) { - return std::string(value.s); + static std::string& from_any_value(const AnyValue& value) { + return *value.s_ptr.ptr; } }; @@ -1289,7 +1361,7 @@ inline ostream& operator<<(ostream& os, gs::PropertyType pt) { os << "date"; } else if (pt == gs::PropertyType::Day()) { os << "day"; - } else if (pt == gs::PropertyType::String()) { + } else if (pt == gs::PropertyType::StringView()) { os << "string"; } else if (pt == gs::PropertyType::StringMap()) { os << "string_map"; @@ -1329,7 +1401,7 @@ struct convert { } else if (config["string"]) { if (config["string"].IsMap()) { if (config["string"]["long_text"]) { - property_type = gs::PropertyType::String(); + property_type = gs::PropertyType::StringView(); } else if (config["string"]["var_char"]) { if (config["string"]["var_char"]["max_length"]) { property_type = gs::PropertyType::Varchar( @@ -1383,7 +1455,7 @@ struct convert { type == gs::PropertyType::Double()) { node["primitive_type"] = gs::config_parsing::PrimitivePropertyTypeToString(type); - } else if (type == gs::PropertyType::String() || + } else if (type == gs::PropertyType::StringView() || type == gs::PropertyType::StringMap()) { node["string"]["long_text"] = ""; } else if (type.IsVarchar()) { diff --git a/flex/utils/pt_indexer.h b/flex/utils/pt_indexer.h index a9e48f15ea7c..b85a46510e4a 100644 --- a/flex/utils/pt_indexer.h +++ b/flex/utils/pt_indexer.h @@ -50,7 +50,7 @@ struct murmurhash2_64 { } static inline hash_type hash(const Any& val, uint64_t seed) { - if (val.type == PropertyType::kString) { + if (val.type == PropertyType::kStringView) { return hash(val.AsStringView(), seed); } else if (val.type == PropertyType::kInt64) { return hash(val.AsInt64(), seed); diff --git a/flex/utils/service_utils.h b/flex/utils/service_utils.h index a5871e233dd2..7e6e026eb142 100644 --- a/flex/utils/service_utils.h +++ b/flex/utils/service_utils.h @@ -63,7 +63,8 @@ inline void to_json(nlohmann::json& j, const PropertyType& p) { j["temporal"]["timestamp"] = {}; } else if (p == PropertyType::Day()) { j["temporal"]["date32"] = {}; - } else if (p == PropertyType::String() || p == PropertyType::StringMap()) { + } else if (p == PropertyType::StringView() || + p == PropertyType::StringMap()) { j["string"]["long_text"] = {}; } else if (p.IsVarchar()) { j["string"]["var_char"]["max_length"] = p.additional_type_info.max_length; @@ -78,7 +79,7 @@ inline void from_json(const nlohmann::json& j, PropertyType& p) { j["primitive_type"].get()); } else if (j.contains("string")) { if (j["string"].contains("long_text")) { - p = PropertyType::String(); + p = PropertyType::StringView(); } else if (j.contains("string") && j["string"].contains("var_char")) { if (j["string"]["var_char"].contains("max_length")) { p = PropertyType::Varchar(