20 #include "graphar/chunk_info_writer.h"
21 #include "graphar/filesystem.h"
22 #include "graphar/graph_info.h"
23 #include "graphar/result.h"
24 #include "graphar/types.h"
25 #include "graphar/util.h"
30 const std::shared_ptr<VertexInfo>& vertex_info,
const std::string& prefix,
31 const ValidateLevel& validate_level)
32 : vertex_info_(vertex_info),
34 validate_level_(validate_level) {
35 if (validate_level_ == ValidateLevel::default_validate) {
36 throw std::runtime_error(
37 "default_validate is not allowed to be set as the global validate "
38 "level for VertexPropertyWriter");
40 GAR_ASSIGN_OR_RAISE_ERROR(fs_, FileSystemFromUriOrPath(prefix, &prefix_));
44 Status VertexChunkInfoWriter::validate(
45 const std::shared_ptr<PropertyGroup>& property_group, IdType chunk_index,
46 ValidateLevel validate_level)
const {
48 if (validate_level == ValidateLevel::default_validate)
49 validate_level = validate_level_;
51 if (validate_level == ValidateLevel::no_validate)
54 if (!vertex_info_->HasPropertyGroup(property_group)) {
56 vertex_info_->GetLabel(),
" vertex info.");
58 if (chunk_index < 0) {
64 Status VertexChunkInfoWriter::WriteChunk(
65 const std::string& file_name,
66 const std::shared_ptr<PropertyGroup>& property_group, IdType chunk_index,
67 ValidateLevel validate_level)
const {
68 GAR_RETURN_NOT_OK(validate(property_group, chunk_index, validate_level));
69 GAR_ASSIGN_OR_RAISE(
auto suffix,
70 vertex_info_->GetFilePath(property_group, chunk_index));
71 std::string path = prefix_ + suffix;
72 return fs_->CopyFile(file_name, path);
75 EdgeChunkInfoWriter::EdgeChunkInfoWriter(
76 const std::shared_ptr<EdgeInfo>& edge_info,
const std::string& prefix,
77 AdjListType adj_list_type,
const ValidateLevel& validate_level)
78 : edge_info_(edge_info),
79 adj_list_type_(adj_list_type),
80 validate_level_(validate_level) {
81 if (validate_level_ == ValidateLevel::default_validate) {
82 throw std::runtime_error(
83 "default_validate is not allowed to be set as the global validate "
84 "level for EdgeChunkWriter");
86 GAR_ASSIGN_OR_RAISE_ERROR(fs_, FileSystemFromUriOrPath(prefix, &prefix_));
87 chunk_size_ = edge_info_->GetChunkSize();
88 switch (adj_list_type) {
89 case AdjListType::unordered_by_source:
90 vertex_chunk_size_ = edge_info_->GetSrcChunkSize();
92 case AdjListType::ordered_by_source:
93 vertex_chunk_size_ = edge_info_->GetSrcChunkSize();
95 case AdjListType::unordered_by_dest:
96 vertex_chunk_size_ = edge_info_->GetDstChunkSize();
98 case AdjListType::ordered_by_dest:
99 vertex_chunk_size_ = edge_info_->GetDstChunkSize();
102 vertex_chunk_size_ = edge_info_->GetSrcChunkSize();
107 Status EdgeChunkInfoWriter::validate(IdType count_or_index1,
108 IdType count_or_index2,
109 ValidateLevel validate_level)
const {
111 if (validate_level == ValidateLevel::default_validate)
112 validate_level = validate_level_;
114 if (validate_level == ValidateLevel::no_validate)
117 if (!edge_info_->HasAdjacentListType(adj_list_type_)) {
119 "Adj list type ", AdjListTypeToString(adj_list_type_),
120 " does not exist in the ", edge_info_->GetEdgeLabel(),
" edge info.");
123 if (count_or_index1 < 0 || count_or_index2 < 0) {
125 "The count or index must be non-negative, but got ", count_or_index1,
126 " and ", count_or_index2,
".");
132 Status EdgeChunkInfoWriter::validate(
133 const std::shared_ptr<PropertyGroup>& property_group,
134 IdType vertex_chunk_index, IdType chunk_index,
135 ValidateLevel validate_level)
const {
137 if (validate_level == ValidateLevel::default_validate)
138 validate_level = validate_level_;
140 if (validate_level == ValidateLevel::no_validate)
143 GAR_RETURN_NOT_OK(validate(vertex_chunk_index, chunk_index, validate_level));
145 if (!edge_info_->HasPropertyGroup(property_group)) {
147 edge_info_->GetEdgeLabel(),
" edge info.");
152 Status EdgeChunkInfoWriter::WriteAdjListChunk(
153 const std::string& file_name, IdType vertex_chunk_index, IdType chunk_index,
154 ValidateLevel validate_level)
const {
155 GAR_RETURN_NOT_OK(validate(vertex_chunk_index, chunk_index, validate_level));
157 auto suffix, edge_info_->GetAdjListFilePath(vertex_chunk_index,
158 chunk_index, adj_list_type_));
159 std::string path = prefix_ + suffix;
160 return fs_->CopyFile(file_name, path);
163 Status EdgeChunkInfoWriter::WriteOffsetChunk(
164 const std::string& file_name, IdType vertex_chunk_index,
165 ValidateLevel validate_level)
const {
166 GAR_RETURN_NOT_OK(validate(vertex_chunk_index, 0, validate_level));
167 GAR_ASSIGN_OR_RAISE(
auto suffix, edge_info_->GetAdjListOffsetFilePath(
168 vertex_chunk_index, adj_list_type_));
169 std::string path = prefix_ + suffix;
170 return fs_->CopyFile(file_name, path);
173 Status EdgeChunkInfoWriter::WritePropertyChunk(
174 const std::string& file_name,
175 const std::shared_ptr<PropertyGroup>& property_group,
176 IdType vertex_chunk_index, IdType chunk_index,
177 ValidateLevel validate_level)
const {
178 GAR_RETURN_NOT_OK(validate(property_group, vertex_chunk_index, chunk_index,
180 GAR_ASSIGN_OR_RAISE(
auto suffix, edge_info_->GetPropertyFilePath(
181 property_group, adj_list_type_,
182 vertex_chunk_index, chunk_index));
183 std::string path = prefix_ + suffix;
184 return fs_->CopyFile(file_name, path);
Status outcome object (success or error)
static Status IndexError(Args &&... args)
static Status KeyError(Args &&... args)
VertexChunkInfoWriter(const std::shared_ptr< VertexInfo > &vertex_info, const std::string &prefix, const ValidateLevel &validate_level=ValidateLevel::no_validate)
Copy a file as a vertex property group chunk.