Skip to content

Commit

Permalink
fix(interactive): Support std::string as member of Any and rename kSt…
Browse files Browse the repository at this point in the history
…ring to kStringView (alibaba#3979)
  • Loading branch information
liulx20 authored Jun 27, 2024
1 parent 33601cc commit 56e4921
Show file tree
Hide file tree
Showing 33 changed files with 197 additions and 96 deletions.
2 changes: 1 addition & 1 deletion flex/codegen/src/hqps/hqps_scan_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 2 additions & 1 deletion flex/codegen/src/pegasus_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion flex/engines/graph_db/database/graph_db_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ std::shared_ptr<RefColumnBase> GraphDBSession::get_vertex_id_column(
dynamic_cast<const TypedColumn<uint32_t>&>(
db_.graph().lf_indexers_[label].get_keys()));
} else if (db_.graph().lf_indexers_[label].get_type() ==
PropertyType::kString) {
PropertyType::kStringView) {
return std::make_shared<TypedRefColumn<std::string_view>>(
dynamic_cast<const TypedColumn<std::string_view>&>(
db_.graph().lf_indexers_[label].get_keys()));
Expand Down
2 changes: 1 addition & 1 deletion flex/engines/graph_db/database/insert_transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions flex/engines/graph_db/database/transaction_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions flex/engines/graph_db/database/update_transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<IdIndexer<uint32_t, vid_t>>());
} 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<IdIndexer<std::string_view, vid_t>>());
} else {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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<IdIndexer<uint32_t, vid_t>>());
} 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<IdIndexer<std::string_view, vid_t>>());
} else {
Expand Down
2 changes: 1 addition & 1 deletion flex/engines/graph_db/grin/predefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion flex/engines/graph_db/grin/src/index/pk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<const std::string_view*>((*_r)[0]);
if (!_g->g.get_lid(label, oid, vid)) {
return GRIN_NULL_VERTEX;
Expand Down
6 changes: 3 additions & 3 deletions flex/engines/graph_db/grin/src/predefine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -52,7 +52,7 @@ void init_cache(GRIN_GRAPH_T* g) {
tmp.emplace_back(std::dynamic_pointer_cast<gs::BoolColumn>(
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<gs::StringColumn>(
table.get_column_by_id(idx))
.get());
Expand Down
6 changes: 3 additions & 3 deletions flex/engines/graph_db/grin/src/property/primarykey.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions flex/engines/graph_db/grin/src/property/property.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<const gs::StringColumn*>(col);
auto s = _col->get_view(vid);
auto len = s.size() + 1;
Expand Down Expand Up @@ -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<GRIN_EDGE_T*>(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;
}
Expand Down
6 changes: 3 additions & 3 deletions flex/engines/graph_db/grin/src/property/row.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const void* grin_get_value_from_row(GRIN_GRAPH g, GRIN_ROW r, GRIN_DATATYPE dt,
return static_cast<const float*>((*_r)[idx]);
case GRIN_DATATYPE::Double:
return static_cast<const double*>((*_r)[idx]);
case GRIN_DATATYPE::String:
case GRIN_DATATYPE::StringView:
return static_cast<const char*>((*_r)[idx]);
case GRIN_DATATYPE::Date32:
return static_cast<const int32_t*>((*_r)[idx]);
Expand Down Expand Up @@ -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<const gs::StringColumn*>(col);
auto s = _col->get_view(vid);
auto len = s.size() + 1;
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion flex/engines/graph_db/grin/src/topology/structure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions flex/engines/graph_db/grin/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions flex/engines/hqps_db/core/operator/sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ void template_set_value(common::Value* value, T v) {
}

template <typename T,
typename std::enable_if<(std::is_same_v<T, uint64_t>) &&(
!std::is_same_v<uint64_t, unsigned long>)>::type* = nullptr>
typename std::enable_if<
(std::is_same_v<T, uint64_t>) &&
(!std::is_same_v<uint64_t, unsigned long>)>::type* = nullptr>
void template_set_value(common::Value* value, T v) {
value->set_i64(v);
}
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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: "
Expand Down
2 changes: 1 addition & 1 deletion flex/engines/hqps_db/database/mutable_csr_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ class MutableCSRInterface {
} else if (type == PropertyType::kUInt64) {
return std::make_shared<TypedRefColumn<uint64_t>>(
*std::dynamic_pointer_cast<TypedColumn<uint64_t>>(column));
} else if (type == PropertyType::kString || type.IsVarchar()) {
} else if (type == PropertyType::kStringView || type.IsVarchar()) {
return std::make_shared<TypedRefColumn<std::string_view>>(
*std::dynamic_pointer_cast<TypedColumn<std::string_view>>(column));
} else if (type == PropertyType::kFloat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ static void append_edges(std::shared_ptr<arrow::Array> src_col,
const std::shared_ptr<arrow::Array>& 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ inline DualCsrBase* create_csr(EdgeStrategy oes, EdgeStrategy ies,
} else if (properties[0].type_enum == impl::PropertyTypeImpl::kVarChar) {
return new DualCsr<std::string_view>(
oes, ies, properties[0].additional_type_info.max_length);
} else if (properties[0] == PropertyType::kString) {
} else if (properties[0] == PropertyType::kStringView) {
return new DualCsr<std::string_view>(oes, ies, 256);
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions flex/storages/rt_mutable_graph/schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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<std::string>();
}
if (node["nullable"]) {
Expand Down
6 changes: 3 additions & 3 deletions flex/tests/rt_mutable_graph/multiple_props_edge_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ 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;
std::cout << data[0].AsStringView() << " " << data[1].AsInt32() << "\n";
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;

Expand Down Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion flex/tests/rt_mutable_graph/string_edge_property_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Loading

0 comments on commit 56e4921

Please sign in to comment.