Flex  0.17.9
mutable_property_fragment.h
Go to the documentation of this file.
1 
16 #ifndef GRAPHSCOPE_FRAGMENT_MUTABLE_PROPERTY_FRAGMENT_H_
17 #define GRAPHSCOPE_FRAGMENT_MUTABLE_PROPERTY_FRAGMENT_H_
18 
19 #include <thread>
20 #include <tuple>
21 #include <vector>
22 
24 
28 #include "flex/utils/arrow_utils.h"
29 #include "flex/utils/indexers.h"
31 #include "flex/utils/yaml_utils.h"
32 #include "grape/io/local_io_adaptor.h"
33 #include "grape/serialization/out_archive.h"
34 
35 namespace gs {
36 
38  public:
40 
42 
43  void IngestEdge(label_t src_label, vid_t src_lid, label_t dst_label,
44  vid_t dst_lid, label_t edge_label, timestamp_t ts,
45  grape::OutArchive& arc, Allocator& alloc);
46 
47  void UpdateEdge(label_t src_label, vid_t src_lid, label_t dst_label,
48  vid_t dst_lid, label_t edge_label, timestamp_t ts,
49  const Any& arc, Allocator& alloc);
50 
51  void Open(const std::string& work_dir, int memory_level);
52 
53  void Compact(uint32_t version);
54 
55  void Warmup(int thread_num);
56 
57  void Dump(const std::string& work_dir, uint32_t version);
58 
59  void DumpSchema(const std::string& filename);
60 
61  const Schema& schema() const;
62 
64 
65  void Clear();
66 
67  inline Table& get_vertex_table(label_t vertex_label) {
68  return vertex_data_[vertex_label];
69  }
70 
71  inline const Table& get_vertex_table(label_t vertex_label) const {
72  return vertex_data_[vertex_label];
73  }
74 
75  vid_t vertex_num(label_t vertex_label) const;
76 
77  size_t edge_num(label_t src_label, label_t edge_label,
78  label_t dst_label) const;
79 
80  bool get_lid(label_t label, const Any& oid, vid_t& lid) const;
81 
82  Any get_oid(label_t label, vid_t lid) const;
83 
84  vid_t add_vertex(label_t label, const Any& id);
85  std::shared_ptr<CsrConstEdgeIterBase> get_outgoing_edges(
86  label_t label, vid_t u, label_t neighbor_label, label_t edge_label) const;
87 
88  std::shared_ptr<CsrConstEdgeIterBase> get_incoming_edges(
89  label_t label, vid_t u, label_t neighbor_label, label_t edge_label) const;
90 
91  std::shared_ptr<CsrEdgeIterBase> get_outgoing_edges_mut(
92  label_t label, vid_t u, label_t neighbor_label, label_t edge_label);
93 
94  std::shared_ptr<CsrEdgeIterBase> get_incoming_edges_mut(
95  label_t label, vid_t u, label_t neighbor_label, label_t edge_label);
96 
98  label_t neighbor_label,
99  label_t edge_label) const;
100 
102  label_t neighbor_label,
103  label_t edge_label) const;
104 
105  inline CsrBase* get_oe_csr(label_t label, label_t neighbor_label,
106  label_t edge_label) {
107  size_t index = label * vertex_label_num_ * edge_label_num_ +
108  neighbor_label * edge_label_num_ + edge_label;
109  return oe_[index];
110  }
111 
112  inline const CsrBase* get_oe_csr(label_t label, label_t neighbor_label,
113  label_t edge_label) const {
114  size_t index = label * vertex_label_num_ * edge_label_num_ +
115  neighbor_label * edge_label_num_ + edge_label;
116  return oe_[index];
117  }
118 
119  inline CsrBase* get_ie_csr(label_t label, label_t neighbor_label,
120  label_t edge_label) {
121  size_t index = neighbor_label * vertex_label_num_ * edge_label_num_ +
122  label * edge_label_num_ + edge_label;
123  return ie_[index];
124  }
125 
126  inline const CsrBase* get_ie_csr(label_t label, label_t neighbor_label,
127  label_t edge_label) const {
128  size_t index = neighbor_label * vertex_label_num_ * edge_label_num_ +
129  label * edge_label_num_ + edge_label;
130  return ie_[index];
131  }
132 
133  void loadSchema(const std::string& filename);
134  inline std::shared_ptr<ColumnBase> get_vertex_property_column(
135  uint8_t label, const std::string& prop) const {
136  return vertex_data_[label].get_column(prop);
137  }
138 
139  inline std::shared_ptr<RefColumnBase> get_vertex_id_column(
140  uint8_t label) const {
141  if (lf_indexers_[label].get_type() == PropertyType::kInt64) {
142  return std::make_shared<TypedRefColumn<int64_t>>(
143  dynamic_cast<const TypedColumn<int64_t>&>(
144  lf_indexers_[label].get_keys()));
145  } else if (lf_indexers_[label].get_type() == PropertyType::kInt32) {
146  return std::make_shared<TypedRefColumn<int32_t>>(
147  dynamic_cast<const TypedColumn<int32_t>&>(
148  lf_indexers_[label].get_keys()));
149  } else if (lf_indexers_[label].get_type() == PropertyType::kUInt64) {
150  return std::make_shared<TypedRefColumn<uint64_t>>(
151  dynamic_cast<const TypedColumn<uint64_t>&>(
152  lf_indexers_[label].get_keys()));
153  } else if (lf_indexers_[label].get_type() == PropertyType::kUInt32) {
154  return std::make_shared<TypedRefColumn<uint32_t>>(
155  dynamic_cast<const TypedColumn<uint32_t>&>(
156  lf_indexers_[label].get_keys()));
157  } else if (lf_indexers_[label].get_type() == PropertyType::kStringView) {
158  return std::make_shared<TypedRefColumn<std::string_view>>(
159  dynamic_cast<const TypedColumn<std::string_view>&>(
160  lf_indexers_[label].get_keys()));
161  } else {
162  LOG(ERROR) << "Unsupported vertex id type: "
163  << lf_indexers_[label].get_type();
164  return nullptr;
165  }
166  }
167 
168  void generateStatistics(const std::string& work_dir) const;
169 
171  std::vector<IndexerType> lf_indexers_;
172  std::vector<CsrBase*> ie_, oe_;
173  std::vector<DualCsrBase*> dual_csr_list_;
174  std::vector<Table> vertex_data_;
175 
177 };
178 
179 } // namespace gs
180 
181 #endif // GRAPHSCOPE_FRAGMENT_MUTABLE_PROPERTY_FRAGMENT_H_
gs::MutablePropertyFragment::loadSchema
void loadSchema(const std::string &filename)
Definition: mutable_property_fragment.cc:47
indexers.h
gs::MutablePropertyFragment::schema_
Schema schema_
Definition: mutable_property_fragment.h:170
gs::MutablePropertyFragment::get_vertex_table
Table & get_vertex_table(label_t vertex_label)
Definition: mutable_property_fragment.h:67
gs::MutablePropertyFragment::get_outgoing_edges_mut
std::shared_ptr< CsrEdgeIterBase > get_outgoing_edges_mut(label_t label, vid_t u, label_t neighbor_label, label_t edge_label)
Definition: mutable_property_fragment.cc:448
gs::MutablePropertyFragment::vertex_data_
std::vector< Table > vertex_data_
Definition: mutable_property_fragment.h:174
gs::MutablePropertyFragment::ie_
std::vector< CsrBase * > ie_
Definition: mutable_property_fragment.h:172
gs::Any
Definition: types.h:399
gs::MutablePropertyFragment::get_oe_csr
const CsrBase * get_oe_csr(label_t label, label_t neighbor_label, label_t edge_label) const
Definition: mutable_property_fragment.h:112
gs::MutablePropertyFragment::add_vertex
vid_t add_vertex(label_t label, const Any &id)
Definition: mutable_property_fragment.cc:419
gs::timestamp_t
uint32_t timestamp_t
Definition: types.h:30
arrow_utils.h
gs::CsrBase
Definition: csr_base.h:61
gs::MutablePropertyFragment::schema
const Schema & schema() const
Definition: mutable_property_fragment.cc:391
schema.h
gs::vid_t
uint32_t vid_t
Definition: types.h:31
gs::MutablePropertyFragment::Clear
void Clear()
Definition: mutable_property_fragment.cc:54
gs::MutablePropertyFragment::get_vertex_id_column
std::shared_ptr< RefColumnBase > get_vertex_id_column(uint8_t label) const
Definition: mutable_property_fragment.h:139
gs::MutablePropertyFragment::edge_label_num_
size_t edge_label_num_
Definition: mutable_property_fragment.h:176
gs::MutablePropertyFragment::get_ie_csr
const CsrBase * get_ie_csr(label_t label, label_t neighbor_label, label_t edge_label) const
Definition: mutable_property_fragment.h:126
gs
Definition: adj_list.h:23
gs::TypedColumn
Definition: column.h:67
gs::MutablePropertyFragment::dual_csr_list_
std::vector< DualCsrBase * > dual_csr_list_
Definition: mutable_property_fragment.h:173
gs::PropertyType::kUInt64
static const PropertyType kUInt64
Definition: types.h:145
gs::MutablePropertyFragment::vertex_num
vid_t vertex_num(label_t vertex_label) const
Definition: mutable_property_fragment.cc:395
gs::MutablePropertyFragment::get_vertex_table
const Table & get_vertex_table(label_t vertex_label) const
Definition: mutable_property_fragment.h:71
gs::MutablePropertyFragment::get_oid
Any get_oid(label_t label, vid_t lid) const
Definition: mutable_property_fragment.cc:415
gs::Table
Definition: table.h:30
gs::MutablePropertyFragment::get_vertex_property_column
std::shared_ptr< ColumnBase > get_vertex_property_column(uint8_t label, const std::string &prop) const
Definition: mutable_property_fragment.h:134
gs::ArenaAllocator
Definition: allocators.h:29
gs::MutablePropertyFragment
Definition: mutable_property_fragment.h:37
gs::MutablePropertyFragment::get_outgoing_edges_raw
CsrConstEdgeIterBase * get_outgoing_edges_raw(label_t label, vid_t u, label_t neighbor_label, label_t edge_label) const
Definition: mutable_property_fragment.cc:437
gs::MutablePropertyFragment::mutable_schema
Schema & mutable_schema()
Definition: mutable_property_fragment.cc:393
gs::PropertyType::kStringView
static const PropertyType kStringView
Definition: types.h:149
gs::MutablePropertyFragment::get_incoming_edges_raw
CsrConstEdgeIterBase * get_incoming_edges_raw(label_t label, vid_t u, label_t neighbor_label, label_t edge_label) const
Definition: mutable_property_fragment.cc:442
gs::MutablePropertyFragment::DumpSchema
void DumpSchema(const std::string &filename)
Definition: mutable_property_fragment.cc:70
gs::CsrConstEdgeIterBase
Definition: csr_base.h:27
dual_csr.h
gs::TypedColumn< std::string_view >
Definition: column.h:347
gs::Schema
Definition: schema.h:29
gs::MutablePropertyFragment::IngestEdge
void IngestEdge(label_t src_label, vid_t src_lid, label_t dst_label, vid_t dst_lid, label_t edge_label, timestamp_t ts, grape::OutArchive &arc, Allocator &alloc)
Definition: mutable_property_fragment.cc:373
gs::MutablePropertyFragment::MutablePropertyFragment
MutablePropertyFragment()
Definition: mutable_property_fragment.cc:24
gs::PropertyType::kUInt32
static const PropertyType kUInt32
Definition: types.h:142
yaml_utils.h
gs::MutablePropertyFragment::Dump
void Dump(const std::string &work_dir, uint32_t version)
Definition: mutable_property_fragment.cc:301
gs::MutablePropertyFragment::Open
void Open(const std::string &work_dir, int memory_level)
Definition: mutable_property_fragment.cc:119
gs::MutablePropertyFragment::vertex_label_num_
size_t vertex_label_num_
Definition: mutable_property_fragment.h:176
gs::MutablePropertyFragment::get_incoming_edges_mut
std::shared_ptr< CsrEdgeIterBase > get_incoming_edges_mut(label_t label, vid_t u, label_t neighbor_label, label_t edge_label)
Definition: mutable_property_fragment.cc:455
gs::MutablePropertyFragment::UpdateEdge
void UpdateEdge(label_t src_label, vid_t src_lid, label_t dst_label, vid_t dst_lid, label_t edge_label, timestamp_t ts, const Any &arc, Allocator &alloc)
Definition: mutable_property_fragment.cc:383
gs::MutablePropertyFragment::Compact
void Compact(uint32_t version)
Definition: mutable_property_fragment.cc:273
gs::MutablePropertyFragment::oe_
std::vector< CsrBase * > oe_
Definition: mutable_property_fragment.h:172
gs::PropertyType::kInt64
static const PropertyType kInt64
Definition: types.h:144
gs::MutablePropertyFragment::edge_num
size_t edge_num(label_t src_label, label_t edge_label, label_t dst_label) const
Definition: mutable_property_fragment.cc:399
types.h
gs::MutablePropertyFragment::get_ie_csr
CsrBase * get_ie_csr(label_t label, label_t neighbor_label, label_t edge_label)
Definition: mutable_property_fragment.h:119
gs::MutablePropertyFragment::get_lid
bool get_lid(label_t label, const Any &oid, vid_t &lid) const
Definition: mutable_property_fragment.cc:410
gs::MutablePropertyFragment::Warmup
void Warmup(int thread_num)
Definition: mutable_property_fragment.cc:360
mutable_csr.h
gs::MutablePropertyFragment::get_outgoing_edges
std::shared_ptr< CsrConstEdgeIterBase > get_outgoing_edges(label_t label, vid_t u, label_t neighbor_label, label_t edge_label) const
Definition: mutable_property_fragment.cc:424
gs::MutablePropertyFragment::lf_indexers_
std::vector< IndexerType > lf_indexers_
Definition: mutable_property_fragment.h:171
gs::label_t
uint8_t label_t
Definition: types.h:32
gs::MutablePropertyFragment::generateStatistics
void generateStatistics(const std::string &work_dir) const
Definition: mutable_property_fragment.cc:461
gs::MutablePropertyFragment::get_oe_csr
CsrBase * get_oe_csr(label_t label, label_t neighbor_label, label_t edge_label)
Definition: mutable_property_fragment.h:105
gs::MutablePropertyFragment::~MutablePropertyFragment
~MutablePropertyFragment()
Definition: mutable_property_fragment.cc:26
table.h
gs::MutablePropertyFragment::get_incoming_edges
std::shared_ptr< CsrConstEdgeIterBase > get_incoming_edges(label_t label, vid_t u, label_t neighbor_label, label_t edge_label) const
Definition: mutable_property_fragment.cc:431
gs::PropertyType::kInt32
static const PropertyType kInt32
Definition: types.h:141