20 #include <unordered_set>
23 #include "graphar/status.h"
24 #include "mini-yaml/yaml/Yaml.hpp"
26 #include "graphar/filesystem.h"
27 #include "graphar/graph_info.h"
28 #include "graphar/result.h"
29 #include "graphar/types.h"
30 #include "graphar/version_parser.h"
31 #include "graphar/yaml.h"
35 #define CHECK_HAS_ADJ_LIST_TYPE(adj_list_type) \
37 if (!HasAdjacentListType(adj_list_type)) { \
38 return Status::KeyError( \
39 "Adjacency list type: ", AdjListTypeToString(adj_list_type), \
40 " is not found in edge info."); \
46 std::string ConcatEdgeTriple(
const std::string& src_type,
47 const std::string& edge_type,
48 const std::string& dst_type) {
49 return src_type + REGULAR_SEPARATOR + edge_type + REGULAR_SEPARATOR +
53 template <
int NotFoundValue = -1>
54 int LookupKeyIndex(
const std::unordered_map<std::string, int>& key_to_index,
55 const std::string& type) {
56 auto it = key_to_index.find(type);
57 if (it == key_to_index.end()) {
64 std::vector<T> AddVectorElement(
const std::vector<T>& values, T new_element) {
66 out.reserve(values.size() + 1);
67 for (
size_t i = 0; i < values.size(); ++i) {
68 out.push_back(values[i]);
70 out.emplace_back(std::move(new_element));
75 std::vector<T> RemoveVectorElement(
const std::vector<T>& values,
size_t index) {
76 if (index >= values.size()) {
80 out.reserve(values.size() - 1);
81 for (
size_t i = 0; i < values.size(); ++i) {
83 out.push_back(values[i]);
89 std::string BuildPath(
const std::vector<std::string>& paths) {
91 for (
const auto& p : paths) {
92 if (p.back() ==
'/') {
102 bool operator==(
const Property& lhs,
const Property& rhs) {
103 return (lhs.name == rhs.name) && (lhs.type == rhs.type) &&
104 (lhs.is_primary == rhs.is_primary) &&
105 (lhs.is_nullable == rhs.is_nullable) &&
106 (lhs.cardinality == rhs.cardinality);
110 FileType file_type,
const std::string& prefix)
111 : properties_(properties), file_type_(file_type), prefix_(prefix) {
112 if (prefix_.empty() && !properties_.empty()) {
113 for (
const auto& p : properties_) {
114 prefix_ += p.name + REGULAR_SEPARATOR;
116 prefix_.back() =
'/';
124 bool PropertyGroup::HasProperty(
const std::string& property_name)
const {
125 for (
const auto& p : properties_) {
126 if (p.name == property_name) {
134 if (prefix_.empty() ||
135 (file_type_ != FileType::CSV && file_type_ != FileType::PARQUET &&
136 file_type_ != FileType::ORC)) {
139 if (properties_.empty()) {
142 std::unordered_set<std::string> check_property_unique_set;
143 for (
const auto& p : properties_) {
144 if (p.name.empty() || p.type ==
nullptr) {
147 if (check_property_unique_set.find(p.name) !=
148 check_property_unique_set.end()) {
151 check_property_unique_set.insert(p.name);
154 if (p.type->id() == Type::LIST && file_type_ == FileType::CSV) {
159 if (p.cardinality != Cardinality::SINGLE && file_type_ == FileType::CSV) {
167 std::shared_ptr<PropertyGroup> CreatePropertyGroup(
168 const std::vector<Property>& properties, FileType file_type,
169 const std::string& prefix) {
170 if (properties.empty()) {
174 return std::make_shared<PropertyGroup>(properties, file_type, prefix);
177 bool operator==(
const PropertyGroup& lhs,
const PropertyGroup& rhs) {
178 return (lhs.GetPrefix() == rhs.GetPrefix()) &&
179 (lhs.GetFileType() == rhs.GetFileType()) &&
180 (lhs.GetProperties() == rhs.GetProperties());
184 const std::string& prefix)
185 : type_(type), file_type_(file_type), prefix_(prefix) {
186 if (prefix_.empty()) {
187 prefix_ = std::string(AdjListTypeToString(type_)) +
"/";
192 if (type_ != AdjListType::unordered_by_source &&
193 type_ != AdjListType::ordered_by_source &&
194 type_ != AdjListType::unordered_by_dest &&
195 type_ != AdjListType::ordered_by_dest) {
198 if (prefix_.empty() ||
199 (file_type_ != FileType::CSV && file_type_ != FileType::PARQUET &&
200 file_type_ != FileType::ORC)) {
206 std::shared_ptr<AdjacentList> CreateAdjacentList(AdjListType type,
208 const std::string& prefix) {
209 return std::make_shared<AdjacentList>(type, file_type, prefix);
214 Impl(
const std::string& type, IdType chunk_size,
const std::string& prefix,
215 const PropertyGroupVector& property_groups,
216 const std::vector<std::string>& labels,
217 std::shared_ptr<const InfoVersion>
version)
219 chunk_size_(chunk_size),
220 property_groups_(std::move(property_groups)),
224 if (prefix_.empty()) {
225 prefix_ = type_ +
"/";
227 for (
size_t i = 0; i < property_groups_.size(); i++) {
228 const auto& pg = property_groups_[i];
232 for (
const auto& p : pg->GetProperties()) {
233 property_name_to_index_.emplace(p.name, i);
234 property_name_to_primary_.emplace(p.name, p.is_primary);
235 property_name_to_nullable_.emplace(p.name, p.is_nullable);
236 property_name_to_type_.emplace(p.name, p.type);
237 property_name_to_cardinality_.emplace(p.name, p.cardinality);
242 bool is_validated()
const noexcept {
243 if (type_.empty() || chunk_size_ <= 0 || prefix_.empty()) {
246 std::unordered_set<std::string> check_property_unique_set;
247 for (
const auto& pg : property_groups_) {
249 if (!pg || !pg->IsValidated()) {
253 for (
const auto& p : pg->GetProperties()) {
254 if (check_property_unique_set.find(p.name) !=
255 check_property_unique_set.end()) {
258 check_property_unique_set.insert(p.name);
268 PropertyGroupVector property_groups_;
269 std::vector<std::string> labels_;
271 std::shared_ptr<const InfoVersion> version_;
272 std::unordered_map<std::string, int> property_name_to_index_;
273 std::unordered_map<std::string, bool> property_name_to_primary_;
274 std::unordered_map<std::string, bool> property_name_to_nullable_;
275 std::unordered_map<std::string, std::shared_ptr<DataType>>
276 property_name_to_type_;
277 std::unordered_map<std::string, Cardinality> property_name_to_cardinality_;
281 const PropertyGroupVector& property_groups,
282 const std::vector<std::string>& labels,
283 const std::string& prefix,
284 std::shared_ptr<const InfoVersion> version)
285 : impl_(new
Impl(type, chunk_size, prefix, property_groups, labels,
288 VertexInfo::~VertexInfo() =
default;
297 return impl_->labels_;
301 return impl_->version_;
305 std::shared_ptr<PropertyGroup> property_group, IdType chunk_index)
const {
306 if (property_group ==
nullptr) {
309 return BuildPath({impl_->prefix_, property_group->GetPrefix()}) +
"chunk" +
310 std::to_string(chunk_index);
314 std::shared_ptr<PropertyGroup> property_group)
const {
315 if (property_group ==
nullptr) {
318 return BuildPath({impl_->prefix_, property_group->GetPrefix()});
322 return BuildPath({impl_->prefix_}) +
"vertex_count";
326 return static_cast<int>(impl_->property_groups_.size());
330 const std::string& property_name)
const {
331 int i = LookupKeyIndex(impl_->property_name_to_index_, property_name);
332 return i == -1 ? nullptr : impl_->property_groups_[i];
337 if (index < 0 || index >=
static_cast<int>(impl_->property_groups_.size())) {
340 return impl_->property_groups_[index];
344 return impl_->property_groups_;
348 auto it = impl_->property_name_to_primary_.find(property_name);
349 if (it == impl_->property_name_to_primary_.end()) {
356 auto it = impl_->property_name_to_nullable_.find(property_name);
357 if (it == impl_->property_name_to_nullable_.end()) {
364 return impl_->property_name_to_index_.find(property_name) !=
365 impl_->property_name_to_index_.end();
369 const std::shared_ptr<PropertyGroup>& property_group)
const {
370 if (property_group ==
nullptr) {
373 for (
const auto& pg : impl_->property_groups_) {
374 if (*pg == *property_group) {
382 const std::string& property_name)
const {
383 auto it = impl_->property_name_to_type_.find(property_name);
384 if (it == impl_->property_name_to_type_.end()) {
390 Result<Cardinality> VertexInfo::GetPropertyCardinality(
391 const std::string& property_name)
const {
392 auto it = impl_->property_name_to_cardinality_.find(property_name);
393 if (it == impl_->property_name_to_cardinality_.end()) {
400 std::shared_ptr<PropertyGroup> property_group)
const {
401 if (property_group ==
nullptr) {
404 for (
const auto& property : property_group->GetProperties()) {
406 return Status::Invalid(
"property in the property group already exists: ",
410 return std::make_shared<VertexInfo>(
411 impl_->type_, impl_->chunk_size_,
412 AddVectorElement(impl_->property_groups_, property_group), impl_->labels_,
413 impl_->prefix_, impl_->version_);
417 std::shared_ptr<PropertyGroup> property_group)
const {
418 if (property_group ==
nullptr) {
422 for (
size_t i = 0; i < impl_->property_groups_.size(); i++) {
423 if (*(impl_->property_groups_[i]) == *property_group) {
431 return std::make_shared<VertexInfo>(
432 impl_->type_, impl_->chunk_size_,
433 RemoveVectorElement(impl_->property_groups_,
static_cast<size_t>(idx)),
434 impl_->labels_, impl_->prefix_, impl_->version_);
439 std::shared_ptr<VertexInfo> CreateVertexInfo(
440 const std::string& type, IdType chunk_size,
441 const PropertyGroupVector& property_groups,
442 const std::vector<std::string>& labels,
const std::string& prefix,
443 std::shared_ptr<const InfoVersion> version) {
444 if (type.empty() || chunk_size <= 0) {
447 return std::make_shared<VertexInfo>(type, chunk_size, property_groups, labels,
452 std::shared_ptr<Yaml> yaml) {
453 if (yaml ==
nullptr) {
456 std::string type = yaml->operator[](
"type").As<std::string>();
458 static_cast<IdType
>(yaml->operator[](
"chunk_size").As<int64_t>());
460 if (!yaml->operator[](
"prefix").IsNone()) {
461 prefix = yaml->operator[](
"prefix").As<std::string>();
463 std::vector<std::string> labels;
464 const auto& labels_node = yaml->operator[](
"labels");
465 if (labels_node.IsSequence()) {
466 for (
auto it = labels_node.Begin(); it != labels_node.End(); it++) {
467 labels.push_back((*it).second.As<std::string>());
470 std::shared_ptr<const InfoVersion>
version =
nullptr;
471 if (!yaml->operator[](
"version").IsNone()) {
476 PropertyGroupVector property_groups;
477 auto property_groups_node = yaml->operator[](
"property_groups");
478 if (!property_groups_node.IsNone()) {
479 for (
auto it = property_groups_node.Begin();
480 it != property_groups_node.End(); it++) {
481 std::string pg_prefix;
482 auto& node = (*it).second;
483 if (!node[
"prefix"].IsNone()) {
484 pg_prefix = node[
"prefix"].As<std::string>();
486 auto file_type = StringToFileType(node[
"file_type"].As<std::string>());
487 std::vector<Property> property_vec;
488 auto& properties = node[
"properties"];
489 for (
auto iit = properties.Begin(); iit != properties.End(); iit++) {
490 auto& p_node = (*iit).second;
491 auto property_name = p_node[
"name"].As<std::string>();
493 DataType::TypeNameToDataType(p_node[
"data_type"].As<std::string>());
494 bool is_primary = p_node[
"is_primary"].As<
bool>();
496 p_node[
"is_nullable"].IsNone() || p_node[
"is_nullable"].As<
bool>();
497 Cardinality cardinality = Cardinality::SINGLE;
498 if (!p_node[
"cardinality"].IsNone()) {
500 StringToCardinality(p_node[
"cardinality"].As<std::string>());
502 property_vec.emplace_back(property_name, property_type, is_primary,
503 is_nullable, cardinality);
505 property_groups.push_back(
506 std::make_shared<PropertyGroup>(property_vec, file_type, pg_prefix));
509 return std::make_shared<VertexInfo>(type, chunk_size, property_groups, labels,
514 GAR_ASSIGN_OR_RAISE(
auto yaml,
Yaml::Load(input));
522 std::string dump_string;
525 node[
"type"] = impl_->type_;
526 node[
"chunk_size"] = std::to_string(impl_->chunk_size_);
527 node[
"prefix"] = impl_->prefix_;
528 if (impl_->labels_.size() > 0) {
530 for (
const auto& label : impl_->labels_) {
531 node[
"labels"].PushBack();
532 node[
"labels"][node[
"labels"].Size() - 1] = label;
535 for (
const auto& pg : impl_->property_groups_) {
536 ::Yaml::Node pg_node;
537 if (!pg->GetPrefix().empty()) {
538 pg_node[
"prefix"] = pg->GetPrefix();
540 pg_node[
"file_type"] = FileTypeToString(pg->GetFileType());
541 for (
const auto& p : pg->GetProperties()) {
543 p_node[
"name"] = p.name;
544 p_node[
"data_type"] = p.type->ToTypeName();
545 p_node[
"is_primary"] = p.is_primary ?
"true" :
"false";
546 p_node[
"is_nullable"] = p.is_nullable ?
"true" :
"false";
547 if (p.cardinality != Cardinality::SINGLE) {
548 p_node[
"cardinality"] = CardinalityToString(p.cardinality);
550 pg_node[
"properties"].PushBack();
551 pg_node[
"properties"][pg_node[
"properties"].Size() - 1] = p_node;
553 node[
"property_groups"].PushBack();
554 node[
"property_groups"][node[
"property_groups"].Size() - 1] = pg_node;
556 if (impl_->version_ !=
nullptr) {
557 node[
"version"] = impl_->version_->ToString();
559 ::Yaml::Serialize(node, dump_string);
560 }
catch (
const std::exception& e) {
567 std::string no_url_path;
568 GAR_ASSIGN_OR_RAISE(
auto fs, FileSystemFromUriOrPath(path, &no_url_path));
569 GAR_ASSIGN_OR_RAISE(
auto yaml_content, this->
Dump());
570 return fs->WriteValueToFile(yaml_content, no_url_path);
575 Impl(
const std::string& src_type,
const std::string& edge_type,
576 const std::string& dst_type, IdType chunk_size, IdType src_chunk_size,
577 IdType dst_chunk_size,
bool directed,
const std::string& prefix,
578 const AdjacentListVector& adjacent_lists,
579 const PropertyGroupVector& property_groups,
580 std::shared_ptr<const InfoVersion>
version)
581 : src_type_(src_type),
582 edge_type_(edge_type),
584 chunk_size_(chunk_size),
585 src_chunk_size_(src_chunk_size),
586 dst_chunk_size_(dst_chunk_size),
589 adjacent_lists_(std::move(adjacent_lists)),
590 property_groups_(std::move(property_groups)),
592 if (prefix_.empty()) {
593 prefix_ = src_type_ + REGULAR_SEPARATOR + edge_type_ + REGULAR_SEPARATOR +
596 for (
size_t i = 0; i < adjacent_lists_.size(); i++) {
597 if (!adjacent_lists_[i]) {
601 auto adj_list_type = adjacent_lists_[i]->GetType();
602 adjacent_list_type_to_index_[adj_list_type] = i;
604 for (
size_t i = 0; i < property_groups_.size(); i++) {
605 const auto& pg = property_groups_[i];
609 for (
const auto& p : pg->GetProperties()) {
610 property_name_to_index_.emplace(p.name, i);
611 property_name_to_primary_.emplace(p.name, p.is_primary);
612 property_name_to_nullable_.emplace(p.name, p.is_nullable);
613 property_name_to_type_.emplace(p.name, p.type);
618 bool is_validated()
const noexcept {
619 if (src_type_.empty() || edge_type_.empty() || dst_type_.empty() ||
620 chunk_size_ <= 0 || src_chunk_size_ <= 0 || dst_chunk_size_ <= 0 ||
621 prefix_.empty() || adjacent_lists_.empty()) {
625 for (
const auto& al : adjacent_lists_) {
626 if (!al || !al->IsValidated()) {
631 std::unordered_set<std::string> check_property_unique_set;
632 for (
const auto& pg : property_groups_) {
634 if (!pg || !pg->IsValidated()) {
638 for (
const auto& p : pg->GetProperties()) {
639 if (p.cardinality != Cardinality::SINGLE) {
642 <<
"Edge property only supports single cardinality, but got: "
643 << CardinalityToString(p.cardinality) << std::endl;
646 if (check_property_unique_set.find(p.name) !=
647 check_property_unique_set.end()) {
650 check_property_unique_set.insert(p.name);
654 if (adjacent_lists_.size() != adjacent_list_type_to_index_.size()) {
660 std::string src_type_;
661 std::string edge_type_;
662 std::string dst_type_;
664 IdType src_chunk_size_;
665 IdType dst_chunk_size_;
668 AdjacentListVector adjacent_lists_;
669 PropertyGroupVector property_groups_;
670 std::unordered_map<AdjListType, int> adjacent_list_type_to_index_;
671 std::unordered_map<std::string, int> property_name_to_index_;
672 std::unordered_map<std::string, bool> property_name_to_primary_;
673 std::unordered_map<std::string, bool> property_name_to_nullable_;
674 std::unordered_map<std::string, std::shared_ptr<DataType>>
675 property_name_to_type_;
676 std::shared_ptr<const InfoVersion> version_;
680 const std::string& dst_type, IdType chunk_size,
681 IdType src_chunk_size, IdType dst_chunk_size,
bool directed,
682 const AdjacentListVector& adjacent_lists,
683 const PropertyGroupVector& property_groups,
684 const std::string& prefix,
685 std::shared_ptr<const InfoVersion> version)
686 : impl_(new
Impl(src_type, edge_type, dst_type, chunk_size, src_chunk_size,
687 dst_chunk_size, directed, prefix, adjacent_lists,
688 property_groups, version)) {}
690 EdgeInfo::~EdgeInfo() =
default;
709 return impl_->version_;
713 return impl_->adjacent_list_type_to_index_.find(adj_list_type) !=
714 impl_->adjacent_list_type_to_index_.end();
718 return impl_->property_name_to_index_.find(property_name) !=
719 impl_->property_name_to_index_.end();
723 const std::shared_ptr<PropertyGroup>& property_group)
const {
724 if (property_group ==
nullptr) {
727 for (
const auto& pg : impl_->property_groups_) {
728 if (*pg == *property_group) {
735 std::shared_ptr<AdjacentList> EdgeInfo::GetAdjacentList(
736 AdjListType adj_list_type)
const {
737 auto it = impl_->adjacent_list_type_to_index_.find(adj_list_type);
738 if (it == impl_->adjacent_list_type_to_index_.end()) {
741 return impl_->adjacent_lists_[it->second];
745 return static_cast<int>(impl_->property_groups_.size());
749 return impl_->property_groups_;
753 const std::string& property_name)
const {
754 int i = LookupKeyIndex(impl_->property_name_to_index_, property_name);
755 return i == -1 ? nullptr : impl_->property_groups_[i];
760 if (index < 0 || index >=
static_cast<int>(impl_->property_groups_.size())) {
763 return impl_->property_groups_[index];
767 AdjListType adj_list_type)
const {
768 CHECK_HAS_ADJ_LIST_TYPE(adj_list_type);
769 int i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
770 return BuildPath({impl_->prefix_, impl_->adjacent_lists_[i]->GetPrefix()}) +
775 IdType vertex_chunk_index, AdjListType adj_list_type)
const {
776 CHECK_HAS_ADJ_LIST_TYPE(adj_list_type);
777 int i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
778 return BuildPath({impl_->prefix_, impl_->adjacent_lists_[i]->GetPrefix()}) +
779 "edge_count" + std::to_string(vertex_chunk_index);
783 IdType vertex_chunk_index, IdType edge_chunk_index,
784 AdjListType adj_list_type)
const {
785 CHECK_HAS_ADJ_LIST_TYPE(adj_list_type);
786 int i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
787 return BuildPath({impl_->prefix_, impl_->adjacent_lists_[i]->GetPrefix()}) +
788 "adj_list/part" + std::to_string(vertex_chunk_index) +
"/chunk" +
789 std::to_string(edge_chunk_index);
793 AdjListType adj_list_type)
const {
794 CHECK_HAS_ADJ_LIST_TYPE(adj_list_type);
795 int i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
796 return BuildPath({impl_->prefix_, impl_->adjacent_lists_[i]->GetPrefix()}) +
801 IdType vertex_chunk_index, AdjListType adj_list_type)
const {
802 CHECK_HAS_ADJ_LIST_TYPE(adj_list_type);
803 int i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
804 return BuildPath({impl_->prefix_, impl_->adjacent_lists_[i]->GetPrefix()}) +
805 "offset/chunk" + std::to_string(vertex_chunk_index);
809 AdjListType adj_list_type)
const {
810 CHECK_HAS_ADJ_LIST_TYPE(adj_list_type);
811 int i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
812 return BuildPath({impl_->prefix_, impl_->adjacent_lists_[i]->GetPrefix()}) +
817 const std::shared_ptr<PropertyGroup>& property_group,
818 AdjListType adj_list_type, IdType vertex_chunk_index,
819 IdType edge_chunk_index)
const {
820 if (property_group ==
nullptr) {
823 CHECK_HAS_ADJ_LIST_TYPE(adj_list_type);
824 int i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
825 return BuildPath({impl_->prefix_, impl_->adjacent_lists_[i]->GetPrefix(),
826 property_group->GetPrefix()}) +
827 "part" + std::to_string(vertex_chunk_index) +
"/chunk" +
828 std::to_string(edge_chunk_index);
832 const std::shared_ptr<PropertyGroup>& property_group,
833 AdjListType adj_list_type)
const {
834 if (property_group ==
nullptr) {
837 CHECK_HAS_ADJ_LIST_TYPE(adj_list_type);
838 int i = impl_->adjacent_list_type_to_index_.at(adj_list_type);
839 return BuildPath({impl_->prefix_, impl_->adjacent_lists_[i]->GetPrefix(),
840 property_group->GetPrefix()});
844 const std::string& property_name)
const {
845 auto it = impl_->property_name_to_type_.find(property_name);
846 if (it == impl_->property_name_to_type_.end()) {
853 auto it = impl_->property_name_to_primary_.find(property_name);
854 if (it == impl_->property_name_to_primary_.end()) {
861 auto it = impl_->property_name_to_nullable_.find(property_name);
862 if (it == impl_->property_name_to_nullable_.end()) {
869 std::shared_ptr<AdjacentList> adj_list)
const {
870 if (adj_list ==
nullptr) {
875 AdjListTypeToString(adj_list->GetType()));
877 return std::make_shared<EdgeInfo>(
878 impl_->src_type_, impl_->edge_type_, impl_->dst_type_, impl_->chunk_size_,
879 impl_->src_chunk_size_, impl_->dst_chunk_size_, impl_->directed_,
880 AddVectorElement(impl_->adjacent_lists_, adj_list),
881 impl_->property_groups_, impl_->prefix_, impl_->version_);
885 std::shared_ptr<AdjacentList> adj_list)
const {
886 if (adj_list ==
nullptr) {
890 for (
size_t i = 0; i < impl_->adjacent_lists_.size(); i++) {
891 if (impl_->adjacent_lists_[i]->GetType() == adj_list->GetType()) {
899 return std::make_shared<EdgeInfo>(
900 impl_->src_type_, impl_->edge_type_, impl_->dst_type_, impl_->chunk_size_,
901 impl_->src_chunk_size_, impl_->dst_chunk_size_, impl_->directed_,
902 RemoveVectorElement(impl_->adjacent_lists_,
static_cast<size_t>(idx)),
903 impl_->property_groups_, impl_->prefix_, impl_->version_);
907 std::shared_ptr<PropertyGroup> property_group)
const {
908 if (property_group ==
nullptr) {
911 for (
const auto& property : property_group->GetProperties()) {
917 return std::make_shared<EdgeInfo>(
918 impl_->src_type_, impl_->edge_type_, impl_->dst_type_, impl_->chunk_size_,
919 impl_->src_chunk_size_, impl_->dst_chunk_size_, impl_->directed_,
920 impl_->adjacent_lists_,
921 AddVectorElement(impl_->property_groups_, property_group), impl_->prefix_,
926 std::shared_ptr<PropertyGroup> property_group)
const {
927 if (property_group ==
nullptr) {
931 for (
size_t i = 0; i < impl_->property_groups_.size(); i++) {
932 if (*(impl_->property_groups_[i]) == *property_group) {
939 return std::make_shared<EdgeInfo>(
940 impl_->src_type_, impl_->edge_type_, impl_->dst_type_, impl_->chunk_size_,
941 impl_->src_chunk_size_, impl_->dst_chunk_size_, impl_->directed_,
942 impl_->adjacent_lists_,
943 RemoveVectorElement(impl_->property_groups_,
static_cast<size_t>(idx)),
944 impl_->prefix_, impl_->version_);
949 std::shared_ptr<EdgeInfo> CreateEdgeInfo(
950 const std::string& src_type,
const std::string& edge_type,
951 const std::string& dst_type, IdType chunk_size, IdType src_chunk_size,
952 IdType dst_chunk_size,
bool directed,
953 const AdjacentListVector& adjacent_lists,
954 const PropertyGroupVector& property_groups,
const std::string& prefix,
955 std::shared_ptr<const InfoVersion> version) {
956 if (src_type.empty() || edge_type.empty() || dst_type.empty() ||
957 chunk_size <= 0 || src_chunk_size <= 0 || dst_chunk_size <= 0 ||
958 adjacent_lists.empty()) {
961 return std::make_shared<EdgeInfo>(
962 src_type, edge_type, dst_type, chunk_size, src_chunk_size, dst_chunk_size,
963 directed, adjacent_lists, property_groups, prefix, version);
967 if (yaml ==
nullptr) {
970 std::string src_type = yaml->operator[](
"src_type").As<std::string>();
971 std::string edge_type = yaml->operator[](
"edge_type").As<std::string>();
972 std::string dst_type = yaml->operator[](
"dst_type").As<std::string>();
974 static_cast<IdType
>(yaml->operator[](
"chunk_size").As<int64_t>());
975 IdType src_chunk_size =
976 static_cast<IdType
>(yaml->operator[](
"src_chunk_size").As<int64_t>());
977 IdType dst_chunk_size =
978 static_cast<IdType
>(yaml->operator[](
"dst_chunk_size").As<int64_t>());
979 bool directed = yaml->operator[](
"directed").As<bool>();
981 if (!yaml->operator[](
"prefix").IsNone()) {
982 prefix = yaml->operator[](
"prefix").As<std::string>();
984 std::shared_ptr<const InfoVersion>
version =
nullptr;
985 if (!yaml->operator[](
"version").IsNone()) {
991 AdjacentListVector adjacent_lists;
992 PropertyGroupVector property_groups;
993 auto adj_lists_node = yaml->operator[](
"adj_lists");
994 if (adj_lists_node.IsSequence()) {
995 for (
auto it = adj_lists_node.Begin(); it != adj_lists_node.End(); it++) {
996 auto& node = (*it).second;
997 auto ordered = node[
"ordered"].As<
bool>();
998 auto aligned = node[
"aligned_by"].As<std::string>();
999 auto adj_list_type = OrderedAlignedToAdjListType(ordered, aligned);
1000 auto file_type = StringToFileType(node[
"file_type"].As<std::string>());
1001 std::string adj_list_prefix;
1002 if (!node[
"prefix"].IsNone()) {
1003 adj_list_prefix = node[
"prefix"].As<std::string>();
1005 adjacent_lists.push_back(std::make_shared<AdjacentList>(
1006 adj_list_type, file_type, adj_list_prefix));
1009 auto property_groups_node = yaml->operator[](
"property_groups");
1010 if (!property_groups_node.IsNone()) {
1011 for (
auto pg_it = property_groups_node.Begin();
1012 pg_it != property_groups_node.End(); pg_it++) {
1013 auto& pg_node = (*pg_it).second;
1014 std::string pg_prefix;
1015 if (!pg_node[
"prefix"].IsNone()) {
1016 pg_prefix = pg_node[
"prefix"].As<std::string>();
1018 auto file_type = StringToFileType(pg_node[
"file_type"].As<std::string>());
1019 auto properties = pg_node[
"properties"];
1020 std::vector<Property> property_vec;
1021 for (
auto p_it = properties.Begin(); p_it != properties.End(); p_it++) {
1022 auto& p_node = (*p_it).second;
1023 auto property_name = p_node[
"name"].As<std::string>();
1024 auto property_type =
1025 DataType::TypeNameToDataType(p_node[
"data_type"].As<std::string>());
1026 if (!p_node[
"cardinality"].IsNone() &&
1027 StringToCardinality(p_node[
"cardinality"].As<std::string>()) !=
1028 Cardinality::SINGLE) {
1030 "Unsupported set cardinality for edge property.");
1032 bool is_primary = p_node[
"is_primary"].As<
bool>();
1034 p_node[
"is_nullable"].IsNone() || p_node[
"is_nullable"].As<
bool>();
1035 property_vec.emplace_back(property_name, property_type, is_primary,
1038 property_groups.push_back(
1039 std::make_shared<PropertyGroup>(property_vec, file_type, pg_prefix));
1042 return std::make_shared<EdgeInfo>(
1043 src_type, edge_type, dst_type, chunk_size, src_chunk_size, dst_chunk_size,
1044 directed, adjacent_lists, property_groups, prefix,
version);
1048 GAR_ASSIGN_OR_RAISE(
auto yaml,
Yaml::Load(input));
1056 std::string dump_string;
1059 node[
"src_type"] = impl_->src_type_;
1060 node[
"edge_type"] = impl_->edge_type_;
1061 node[
"dst_type"] = impl_->dst_type_;
1062 node[
"chunk_size"] = std::to_string(impl_->chunk_size_);
1063 node[
"src_chunk_size"] = std::to_string(impl_->src_chunk_size_);
1064 node[
"dst_chunk_size"] = std::to_string(impl_->dst_chunk_size_);
1065 node[
"prefix"] = impl_->prefix_;
1066 node[
"directed"] = impl_->directed_ ?
"true" :
"false";
1067 for (
const auto& adjacent_list : impl_->adjacent_lists_) {
1068 ::Yaml::Node adj_list_node;
1069 auto adj_list_type = adjacent_list->GetType();
1070 auto pair = AdjListTypeToOrderedAligned(adj_list_type);
1071 adj_list_node[
"ordered"] = pair.first ?
"true" :
"false";
1072 adj_list_node[
"aligned_by"] = pair.second;
1073 adj_list_node[
"prefix"] = adjacent_list->GetPrefix();
1074 adj_list_node[
"file_type"] =
1075 FileTypeToString(adjacent_list->GetFileType());
1076 node[
"adj_lists"].PushBack();
1077 node[
"adj_lists"][node[
"adj_lists"].Size() - 1] = adj_list_node;
1079 for (
const auto& pg : impl_->property_groups_) {
1080 ::Yaml::Node pg_node;
1081 if (!pg->GetPrefix().empty()) {
1082 pg_node[
"prefix"] = pg->GetPrefix();
1084 pg_node[
"file_type"] = FileTypeToString(pg->GetFileType());
1085 for (
const auto& p : pg->GetProperties()) {
1086 ::Yaml::Node p_node;
1087 p_node[
"name"] = p.name;
1088 p_node[
"data_type"] = p.type->ToTypeName();
1089 p_node[
"is_primary"] = p.is_primary ?
"true" :
"false";
1090 p_node[
"is_nullable"] = p.is_nullable ?
"true" :
"false";
1091 pg_node[
"properties"].PushBack();
1092 pg_node[
"properties"][pg_node[
"properties"].Size() - 1] = p_node;
1094 node[
"property_groups"].PushBack();
1095 node[
"property_groups"][node[
"property_groups"].Size() - 1] = pg_node;
1097 if (impl_->version_ !=
nullptr) {
1098 node[
"version"] = impl_->version_->ToString();
1100 ::Yaml::Serialize(node, dump_string);
1101 }
catch (
const std::exception& e) {
1108 std::string no_url_path;
1109 GAR_ASSIGN_OR_RAISE(
auto fs, FileSystemFromUriOrPath(path, &no_url_path));
1110 GAR_ASSIGN_OR_RAISE(
auto yaml_content, this->
Dump());
1111 return fs->WriteValueToFile(yaml_content, no_url_path);
1116 static std::string PathToDirectory(
const std::string& path) {
1117 if (path.rfind(
"s3://", 0) == 0) {
1118 int t = path.find_last_of(
'?');
1119 std::string prefix = path.substr(0, t);
1120 std::string suffix = path.substr(t);
1121 const size_t last_slash_idx = prefix.rfind(
'/');
1122 if (std::string::npos != last_slash_idx) {
1123 return prefix.substr(0, last_slash_idx + 1) + suffix;
1126 const size_t last_slash_idx = path.rfind(
'/');
1127 if (std::string::npos != last_slash_idx) {
1128 return path.substr(0, last_slash_idx + 1);
1134 static Result<std::shared_ptr<GraphInfo>> ConstructGraphInfo(
1135 std::shared_ptr<Yaml> graph_meta,
const std::string& default_name,
1136 const std::string& default_prefix,
const std::shared_ptr<FileSystem> fs,
1137 const std::string& no_url_path) {
1138 std::string name = default_name;
1139 std::string prefix = default_prefix;
1140 if (!graph_meta->operator[](
"name").IsNone()) {
1141 name = graph_meta->operator[](
"name").As<std::string>();
1143 if (!graph_meta->operator[](
"prefix").IsNone()) {
1144 prefix = graph_meta->operator[](
"prefix").As<std::string>();
1146 std::shared_ptr<const InfoVersion> version =
nullptr;
1147 if (!graph_meta->operator[](
"version").IsNone()) {
1148 GAR_ASSIGN_OR_RAISE(
1150 graph_meta->operator[](
"version").As<std::string>()));
1152 std::unordered_map<std::string, std::string> extra_info;
1153 if (!graph_meta->operator[](
"extra_info").IsNone()) {
1154 auto& extra_info_node = graph_meta->operator[](
"extra_info");
1155 for (
auto it = extra_info_node.Begin(); it != extra_info_node.End(); it++) {
1156 auto node = (*it).second;
1157 auto key = node[
"key"].As<std::string>();
1158 auto value = node[
"value"].As<std::string>();
1159 extra_info.emplace(key, value);
1163 VertexInfoVector vertex_infos;
1164 EdgeInfoVector edge_infos;
1165 const auto& vertices = graph_meta->operator[](
"vertices");
1166 if (vertices.IsSequence()) {
1167 for (
auto it = vertices.Begin(); it != vertices.End(); it++) {
1168 std::string vertex_meta_file =
1169 no_url_path + (*it).second.As<std::string>();
1170 GAR_ASSIGN_OR_RAISE(
auto input,
1171 fs->ReadFileToValue<std::string>(vertex_meta_file));
1172 GAR_ASSIGN_OR_RAISE(
auto vertex_meta,
Yaml::Load(input));
1174 vertex_infos.push_back(vertex_info);
1177 const auto& edges = graph_meta->operator[](
"edges");
1178 if (edges.IsSequence()) {
1179 for (
auto it = edges.Begin(); it != edges.End(); it++) {
1180 std::string edge_meta_file = no_url_path + (*it).second.As<std::string>();
1181 GAR_ASSIGN_OR_RAISE(
auto input,
1182 fs->ReadFileToValue<std::string>(edge_meta_file));
1183 GAR_ASSIGN_OR_RAISE(
auto edge_meta,
Yaml::Load(input));
1185 edge_infos.push_back(edge_info);
1189 std::vector<std::string> labels;
1190 if (!graph_meta->operator[](
"labels").IsNone()) {
1191 const auto& labels_node = graph_meta->operator[](
"labels");
1192 if (labels_node.IsSequence()) {
1193 for (
auto it = labels_node.Begin(); it != labels_node.End(); it++) {
1194 labels.push_back((*it).second.As<std::string>());
1198 return std::make_shared<GraphInfo>(name, vertex_infos, edge_infos, labels,
1199 prefix, version, extra_info);
1206 Impl(
const std::string& graph_name, VertexInfoVector vertex_infos,
1207 EdgeInfoVector edge_infos,
const std::vector<std::string>& labels,
1208 const std::string& prefix, std::shared_ptr<const InfoVersion>
version,
1209 const std::unordered_map<std::string, std::string>& extra_info)
1210 : name_(graph_name),
1211 vertex_infos_(std::move(vertex_infos)),
1212 edge_infos_(std::move(edge_infos)),
1216 extra_info_(extra_info) {
1217 for (
size_t i = 0; i < vertex_infos_.size(); i++) {
1218 if (vertex_infos_[i] !=
nullptr) {
1219 vtype_to_index_[vertex_infos_[i]->GetType()] = i;
1222 for (
size_t i = 0; i < edge_infos_.size(); i++) {
1223 if (edge_infos_[i] !=
nullptr) {
1224 std::string edge_key = ConcatEdgeTriple(edge_infos_[i]->GetSrcType(),
1225 edge_infos_[i]->GetEdgeType(),
1226 edge_infos_[i]->GetDstType());
1227 etype_to_index_[edge_key] = i;
1232 bool is_validated()
const noexcept {
1233 if (name_.empty() || prefix_.empty()) {
1236 for (
const auto& v : vertex_infos_) {
1237 if (!v || !v->IsValidated()) {
1241 for (
const auto& e : edge_infos_) {
1242 if (!e || !e->IsValidated()) {
1246 if (vertex_infos_.size() != vtype_to_index_.size() ||
1247 edge_infos_.size() != etype_to_index_.size()) {
1254 VertexInfoVector vertex_infos_;
1255 EdgeInfoVector edge_infos_;
1256 std::vector<std::string> labels_;
1257 std::string prefix_;
1258 std::shared_ptr<const InfoVersion> version_;
1259 std::unordered_map<std::string, std::string> extra_info_;
1260 std::unordered_map<std::string, int> vtype_to_index_;
1261 std::unordered_map<std::string, int> etype_to_index_;
1265 const std::string& graph_name, VertexInfoVector vertex_infos,
1266 EdgeInfoVector edge_infos,
const std::vector<std::string>& labels,
1267 const std::string& prefix, std::shared_ptr<const InfoVersion> version,
1268 const std::unordered_map<std::string, std::string>& extra_info)
1269 : impl_(new
Impl(graph_name, std::move(vertex_infos), std::move(edge_infos),
1270 labels, prefix, version, extra_info)) {}
1272 GraphInfo::~GraphInfo() =
default;
1277 return impl_->labels_;
1283 return impl_->version_;
1288 return impl_->extra_info_;
1292 const std::string& type)
const {
1294 return i == -1 ? nullptr : impl_->vertex_infos_[i];
1298 return LookupKeyIndex(impl_->vtype_to_index_, type);
1302 const std::string& src_type,
const std::string& edge_type,
1303 const std::string& dst_type)
const {
1305 return i == -1 ? nullptr : impl_->edge_infos_[i];
1309 const std::string& edge_type,
1310 const std::string& dst_type)
const {
1311 std::string edge_key = ConcatEdgeTriple(src_type, edge_type, dst_type);
1312 return LookupKeyIndex(impl_->etype_to_index_, edge_key);
1316 return static_cast<int>(impl_->vertex_infos_.size());
1320 return static_cast<int>(impl_->edge_infos_.size());
1325 if (index < 0 || index >=
static_cast<int>(impl_->vertex_infos_.size())) {
1328 return impl_->vertex_infos_[index];
1332 if (index < 0 || index >=
static_cast<int>(impl_->edge_infos_.size())) {
1335 return impl_->edge_infos_[index];
1339 return impl_->vertex_infos_;
1343 return impl_->edge_infos_;
1349 std::shared_ptr<VertexInfo> vertex_info)
const {
1350 if (vertex_info ==
nullptr) {
1356 return std::make_shared<GraphInfo>(
1357 impl_->name_, AddVectorElement(impl_->vertex_infos_, vertex_info),
1358 impl_->edge_infos_, impl_->labels_, impl_->prefix_, impl_->version_);
1362 std::shared_ptr<VertexInfo> vertex_info)
const {
1363 if (vertex_info ==
nullptr) {
1370 return std::make_shared<GraphInfo>(
1372 RemoveVectorElement(impl_->vertex_infos_,
static_cast<size_t>(idx)),
1373 impl_->edge_infos_, impl_->labels_, impl_->prefix_, impl_->version_,
1374 impl_->extra_info_);
1378 std::shared_ptr<EdgeInfo> edge_info)
const {
1379 if (edge_info ==
nullptr) {
1383 edge_info->GetDstType()) != -1) {
1386 return std::make_shared<GraphInfo>(
1387 impl_->name_, impl_->vertex_infos_,
1388 AddVectorElement(impl_->edge_infos_, edge_info), impl_->labels_,
1389 impl_->prefix_, impl_->version_);
1393 std::shared_ptr<EdgeInfo> edge_info)
const {
1394 if (edge_info ==
nullptr) {
1397 int idx =
GetEdgeInfoIndex(edge_info->GetSrcType(), edge_info->GetEdgeType(),
1398 edge_info->GetDstType());
1402 return std::make_shared<GraphInfo>(
1403 impl_->name_, impl_->vertex_infos_,
1404 RemoveVectorElement(impl_->edge_infos_,
static_cast<size_t>(idx)),
1405 impl_->labels_, impl_->prefix_, impl_->version_, impl_->extra_info_);
1408 std::shared_ptr<GraphInfo> CreateGraphInfo(
1409 const std::string& name,
const VertexInfoVector& vertex_infos,
1410 const EdgeInfoVector& edge_infos,
const std::vector<std::string>& labels,
1411 const std::string& prefix, std::shared_ptr<const InfoVersion> version,
1412 const std::unordered_map<std::string, std::string>& extra_info) {
1416 return std::make_shared<GraphInfo>(name, vertex_infos, edge_infos, labels,
1417 prefix, version, extra_info);
1421 std::string no_url_path;
1422 GAR_ASSIGN_OR_RAISE(
auto fs, FileSystemFromUriOrPath(path, &no_url_path));
1423 GAR_ASSIGN_OR_RAISE(
auto yaml_content,
1424 fs->ReadFileToValue<std::string>(no_url_path));
1425 GAR_ASSIGN_OR_RAISE(
auto graph_meta,
Yaml::Load(yaml_content));
1426 std::string default_name =
"graph";
1427 std::string default_prefix = PathToDirectory(path);
1428 no_url_path = PathToDirectory(no_url_path);
1429 return ConstructGraphInfo(graph_meta, default_name, default_prefix, fs,
1434 const std::string& input,
const std::string& relative_location) {
1435 GAR_ASSIGN_OR_RAISE(
auto graph_meta,
Yaml::Load(input));
1436 std::string default_name =
"graph";
1437 std::string default_prefix =
1439 std::string no_url_path;
1440 GAR_ASSIGN_OR_RAISE(
auto fs,
1441 FileSystemFromUriOrPath(relative_location, &no_url_path));
1442 return ConstructGraphInfo(graph_meta, default_name, default_prefix, fs,
1451 std::string dump_string;
1453 node[
"name"] = impl_->name_;
1454 node[
"prefix"] = impl_->prefix_;
1458 node[
"vertices"].PushBack();
1459 node[
"vertices"][node[
"vertices"].Size() - 1] =
1460 vertex->GetType() +
".vertex.yaml";
1463 node[
"edges"].PushBack();
1464 node[
"edges"][node[
"edges"].Size() - 1] =
1465 ConcatEdgeTriple(edge->GetSrcType(), edge->GetEdgeType(),
1466 edge->GetDstType()) +
1469 if (impl_->labels_.size() > 0) {
1471 for (
const auto& label : impl_->labels_) {
1472 node[
"labels"].PushBack();
1473 node[
"labels"][node[
"labels"].Size() - 1] = label;
1476 if (impl_->version_ !=
nullptr) {
1477 node[
"version"] = impl_->version_->ToString();
1479 if (impl_->extra_info_.size() > 0) {
1481 for (
const auto& pair : impl_->extra_info_) {
1482 ::Yaml::Node extra_info_node;
1483 extra_info_node[
"key"] = pair.first;
1484 extra_info_node[
"value"] = pair.second;
1485 node[
"extra_info"].PushBack();
1486 node[
"extra_info"][node[
"extra_info"].Size() - 1] = extra_info_node;
1489 ::Yaml::Serialize(node, dump_string);
1490 }
catch (
const std::exception& e) {
1497 std::string no_url_path;
1498 GAR_ASSIGN_OR_RAISE(
auto fs, FileSystemFromUriOrPath(path, &no_url_path));
1499 GAR_ASSIGN_OR_RAISE(
auto yaml_content, this->
Dump());
1500 return fs->WriteValueToFile(yaml_content, no_url_path);
AdjacentList(AdjListType type, FileType file_type, const std::string &prefix="")
const std::string & GetEdgeType() const
static Result< std::shared_ptr< EdgeInfo > > Load(std::shared_ptr< Yaml > yaml)
Result< std::string > GetAdjListFilePath(IdType vertex_chunk_index, IdType edge_chunk_index, AdjListType adj_list_type) const
Get the file path of adj list topology chunk.
Status Save(const std::string &file_name) const
Result< std::shared_ptr< EdgeInfo > > RemovePropertyGroup(std::shared_ptr< PropertyGroup > property_group) const
Removes a property group from the EdgeInfo instance and returns a new EdgeInfo.
Result< std::shared_ptr< DataType > > GetPropertyType(const std::string &property_name) const
const std::string & GetPrefix() const
Result< std::string > GetEdgesNumFilePath(IdType vertex_chunk_index, AdjListType adj_list_type) const
Result< std::string > GetPropertyGroupPathPrefix(const std::shared_ptr< PropertyGroup > &property_group, AdjListType adj_list_type) const
bool IsPrimaryKey(const std::string &property_name) const
Result< std::string > GetAdjListOffsetFilePath(IdType vertex_chunk_index, AdjListType adj_list_type) const
Get the adjacency list offset chunk file path of vertex chunk the offset chunks is aligned with the v...
IdType GetChunkSize() const
bool HasProperty(const std::string &property_name) const
Returns whether the edge info contains the given property.
Result< std::shared_ptr< EdgeInfo > > AddAdjacentList(std::shared_ptr< AdjacentList > adj_list) const
Result< std::shared_ptr< EdgeInfo > > RemoveAdjacentList(std::shared_ptr< AdjacentList > adj_list) const
Removes an adjacency list from the EdgeInfo instance and returns a new EdgeInfo.
Result< std::string > Dump() const noexcept
bool IsNullableKey(const std::string &property_name) const
std::shared_ptr< PropertyGroup > GetPropertyGroupByIndex(int index) const
Get the property group at the specified index.
bool HasPropertyGroup(const std::shared_ptr< PropertyGroup > &property_group) const
Returns whether the edge info contains the given property group.
const std::shared_ptr< const InfoVersion > & version() const
Result< std::shared_ptr< EdgeInfo > > AddPropertyGroup(std::shared_ptr< PropertyGroup > property_group) const
const std::string & GetSrcType() const
bool HasAdjacentListType(AdjListType adj_list_type) const
Result< std::string > GetOffsetPathPrefix(AdjListType adj_list_type) const
Result< std::string > GetAdjListPathPrefix(AdjListType adj_list_type) const
Get the path prefix of the adjacency list topology chunk for the given adjacency list type.
EdgeInfo(const std::string &src_type, const std::string &edge_type, const std::string &dst_type, IdType chunk_size, IdType src_chunk_size, IdType dst_chunk_size, bool directed, const AdjacentListVector &adjacent_lists, const PropertyGroupVector &property_groups, const std::string &prefix="", std::shared_ptr< const InfoVersion > version=nullptr)
Construct an EdgeInfo object with the given information and property groups.
IdType GetDstChunkSize() const
Result< std::string > GetPropertyFilePath(const std::shared_ptr< PropertyGroup > &property_group, AdjListType adj_list_type, IdType vertex_chunk_index, IdType edge_chunk_index) const
Get the chunk file path of adj list property group the property group chunks is aligned with the adj ...
const std::string & GetDstType() const
IdType GetSrcChunkSize() const
const PropertyGroupVector & GetPropertyGroups() const
Get the property groups.
Result< std::string > GetVerticesNumFilePath(AdjListType adj_list_type) const
Get the file path for the number of vertices.
std::shared_ptr< PropertyGroup > GetPropertyGroup(const std::string &property) const
Get the property group containing the given property.
int PropertyGroupNum() const
Get the number of property groups.
int GetVertexInfoIndex(const std::string &type) const
Get the vertex info index with the given type.
const EdgeInfoVector & GetEdgeInfos() const
Get the edge infos of graph info.
GraphInfo(const std::string &graph_name, VertexInfoVector vertex_infos, EdgeInfoVector edge_infos, const std::vector< std::string > &labels={}, const std::string &prefix="./", std::shared_ptr< const InfoVersion > version=nullptr, const std::unordered_map< std::string, std::string > &extra_info={})
Constructs a GraphInfo instance.
Status Save(const std::string &path) const
const std::shared_ptr< VertexInfo > GetVertexInfoByIndex(int index) const
Get the vertex info at the specified index.
Result< std::shared_ptr< GraphInfo > > AddVertex(std::shared_ptr< VertexInfo > vertex_info) const
Adds a vertex info to the GraphInfo instance and returns a new GraphInfo.
const std::string & GetPrefix() const
Get the absolute path prefix of the chunk files.
static Result< std::shared_ptr< GraphInfo > > Load(const std::string &path)
Loads the input file as a GraphInfo instance.
Result< std::string > Dump() const
std::shared_ptr< EdgeInfo > GetEdgeInfo(const std::string &src_type, const std::string &edge_type, const std::string &dst_type) const
Get the edge info with the given source vertex type, edge type, and destination vertex type.
int EdgeInfoNum() const
Get the number of edge infos.
std::shared_ptr< VertexInfo > GetVertexInfo(const std::string &type) const
Get the vertex info with the given type.
const std::vector< std::string > & GetLabels() const
Get the vertex labels of the graph.
Result< std::shared_ptr< GraphInfo > > AddEdge(std::shared_ptr< EdgeInfo > edge_info) const
Adds an edge info to the GraphInfo instance and returns a new GraphInfo.
const VertexInfoVector & GetVertexInfos() const
Get the vertex infos of graph info.
const std::unordered_map< std::string, std::string > & GetExtraInfo() const
Get the extra metadata of the graph info object.
int GetEdgeInfoIndex(const std::string &src_type, const std::string &edge_type, const std::string &dst_type) const
Get the edge info index with the given source vertex type, edge type, and destination type.
int VertexInfoNum() const
Get the number of vertex infos.
const std::string & GetName() const
Get the name of the graph.
Result< std::shared_ptr< GraphInfo > > RemoveEdge(std::shared_ptr< EdgeInfo > edge_info) const
Removes an edge info from the GraphInfo instance and returns a new GraphInfo.
Result< std::shared_ptr< GraphInfo > > RemoveVertex(std::shared_ptr< VertexInfo > vertex_info) const
Removes a vertex info from the GraphInfo instance and returns a new GraphInfo.
const std::shared_ptr< const InfoVersion > & version() const
Get the version info of the graph info object.
const std::shared_ptr< EdgeInfo > GetEdgeInfoByIndex(int index) const
Get the edge info at the specified index.
static Result< std::shared_ptr< const InfoVersion > > Parse(const std::string &str) noexcept
PropertyGroup(const std::vector< Property > &properties, FileType file_type, const std::string &prefix="")
const std::vector< Property > & GetProperties() const
Status outcome object (success or error)
static Status YamlError(Args &&... args)
static Status Invalid(Args &&... args)
const std::string & GetType() const
std::shared_ptr< PropertyGroup > GetPropertyGroup(const std::string &property_name) const
Result< std::string > GetPathPrefix(std::shared_ptr< PropertyGroup > property_group) const
const std::vector< std::string > & GetLabels() const
IdType GetChunkSize() const
const std::shared_ptr< const InfoVersion > & version() const
Result< std::shared_ptr< VertexInfo > > AddPropertyGroup(std::shared_ptr< PropertyGroup > property_group) const
bool HasProperty(const std::string &property_name) const
bool HasPropertyGroup(const std::shared_ptr< PropertyGroup > &property_group) const
Result< std::string > GetFilePath(std::shared_ptr< PropertyGroup > property_group, IdType chunk_index) const
bool IsPrimaryKey(const std::string &property_name) const
int PropertyGroupNum() const
Result< std::shared_ptr< VertexInfo > > RemovePropertyGroup(std::shared_ptr< PropertyGroup > property_group) const
Removes a property group from the VertexInfo instance and returns a new VertexInfo.
const std::string & GetPrefix() const
Result< std::string > GetVerticesNumFilePath() const
Result< std::shared_ptr< DataType > > GetPropertyType(const std::string &property_name) const
VertexInfo(const std::string &type, IdType chunk_size, const PropertyGroupVector &property_groups, const std::vector< std::string > &labels={}, const std::string &prefix="", std::shared_ptr< const InfoVersion > version=nullptr)
bool IsNullableKey(const std::string &property_name) const
Result< std::string > Dump() const noexcept
static Result< std::shared_ptr< VertexInfo > > Load(std::shared_ptr< Yaml > yaml)
std::shared_ptr< PropertyGroup > GetPropertyGroupByIndex(int index) const
Status Save(const std::string &file_name) const
const PropertyGroupVector & GetPropertyGroups() const
static Result< std::shared_ptr< Yaml > > Load(const std::string &input)