-
Notifications
You must be signed in to change notification settings - Fork 122
/
arrow_fragment.vineyard-mod
792 lines (644 loc) · 29.2 KB
/
arrow_fragment.vineyard-mod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
/** Copyright 2020-2023 Alibaba Group Holding Limited.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef MODULES_GRAPH_FRAGMENT_ARROW_FRAGMENT_VINEYARD_MOD_
#define MODULES_GRAPH_FRAGMENT_ARROW_FRAGMENT_VINEYARD_MOD_
#include <cstddef>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "arrow/api.h"
#include "arrow/io/api.h"
#include "grape/fragment/fragment_base.h"
#include "grape/graph/adj_list.h"
#include "grape/utils/vertex_array.h"
#include "client/ds/core_types.h"
#include "client/ds/object_meta.h"
#include "basic/ds/arrow.h"
#include "basic/ds/arrow_utils.h"
#include "common/util/typename.h"
#include "graph/fragment/arrow_fragment_base.h"
#include "graph/fragment/fragment_traits.h"
#include "graph/fragment/graph_schema.h"
#include "graph/fragment/property_graph_types.h"
#include "graph/utils/error.h"
#include "graph/vertex_map/arrow_local_vertex_map.h"
#include "graph/vertex_map/arrow_vertex_map.h"
namespace vineyard {
inline std::string generate_name_with_suffix(
const std::string& prefix, property_graph_types::LABEL_ID_TYPE label) {
return prefix + "_" + std::to_string(label);
}
inline std::string generate_name_with_suffix(
const std::string& prefix, property_graph_types::LABEL_ID_TYPE v_label,
property_graph_types::LABEL_ID_TYPE e_label) {
return prefix + "_" + std::to_string(v_label) + "_" + std::to_string(e_label);
}
template <typename OID_T, typename VID_T, typename VERTEX_MAP_T, bool COMPACT>
class ArrowFragmentBaseBuilder;
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
#endif
template <typename OID_T, typename VID_T,
typename VERTEX_MAP_T =
ArrowVertexMap<typename InternalType<OID_T>::type, VID_T>,
bool COMPACT = false>
class [[vineyard]] ArrowFragment
: public ArrowFragmentBase,
public vineyard::BareRegistered<
ArrowFragment<OID_T, VID_T, VERTEX_MAP_T, COMPACT>> {
public:
using oid_t = OID_T;
using vid_t = VID_T;
using internal_oid_t = typename InternalType<oid_t>::type;
using eid_t = property_graph_types::EID_TYPE;
using prop_id_t = property_graph_types::PROP_ID_TYPE;
using label_id_t = property_graph_types::LABEL_ID_TYPE;
using vertex_range_t = grape::VertexRange<vid_t>;
using inner_vertices_t = vertex_range_t;
using outer_vertices_t = vertex_range_t;
using vertices_t = vertex_range_t;
using nbr_t = property_graph_utils::Nbr<vid_t, eid_t>;
using nbr_unit_t = property_graph_utils::NbrUnit<vid_t, eid_t>;
using adj_list_t = property_graph_utils::AdjList<vid_t, eid_t>;
using compact_adj_list_t = property_graph_utils::CompactAdjList<vid_t, eid_t>;
using raw_adj_list_t = property_graph_utils::RawAdjList<vid_t, eid_t>;
using vertex_map_t = VERTEX_MAP_T;
using vertex_t = grape::Vertex<vid_t>;
static constexpr bool compact_v = COMPACT;
using ovg2l_map_t =
ska::flat_hash_map<vid_t, vid_t, typename Hashmap<vid_t, vid_t>::KeyHash>;
using vid_array_t = ArrowArrayType<vid_t>;
using vid_vineyard_array_t = ArrowVineyardArrayType<vid_t>;
using vid_vineyard_builder_t = ArrowVineyardBuilderType<vid_t>;
using eid_array_t = ArrowArrayType<eid_t>;
using eid_vineyard_array_t = ArrowVineyardArrayType<eid_t>;
using eid_vineyard_builder_t = ArrowVineyardBuilderType<eid_t>;
using vid_builder_t = ArrowBuilderType<vid_t>;
template <typename DATA_T>
using vertex_array_t = grape::VertexArray<vertices_t, DATA_T>;
template <typename DATA_T>
using inner_vertex_array_t = grape::VertexArray<inner_vertices_t, DATA_T>;
template <typename DATA_T>
using outer_vertex_array_t = grape::VertexArray<outer_vertices_t, DATA_T>;
static constexpr grape::LoadStrategy load_strategy =
grape::LoadStrategy::kBothOutIn;
public:
~ArrowFragment() = default;
vineyard::ObjectID vertex_map_id() const override { return vm_ptr_->id(); }
bool local_vertex_map() const override { return local_vertex_map_; }
bool compact_edges() const override { return compact_edges_; }
bool use_perfect_hash() const override { return vm_ptr_->use_perfect_hash(); }
bool directed() const override { return directed_; }
const PropertyGraphSchema& schema() const override { return schema_; }
bool is_multigraph() const override { return is_multigraph_; }
const std::string vid_typename() const override { return vid_type; }
const std::string oid_typename() const override { return oid_type; }
void PostConstruct(const vineyard::ObjectMeta& meta) override;
fid_t fid() const { return fid_; }
fid_t fnum() const { return fnum_; }
label_id_t vertex_label(const vertex_t& v) const {
return vid_parser_.GetLabelId(v.GetValue());
}
int64_t vertex_offset(const vertex_t& v) const {
return vid_parser_.GetOffset(v.GetValue());
}
label_id_t vertex_label_num() const { return schema_.vertex_label_num(); }
label_id_t edge_label_num() const { return schema_.edge_label_num(); }
prop_id_t vertex_property_num(label_id_t label) const {
return static_cast<prop_id_t>(
schema_.GetEntry(label, PropertyGraphSchema::VERTEX_TYPE_NAME)
.property_num());
}
std::shared_ptr<arrow::DataType> vertex_property_type(label_id_t label,
prop_id_t prop) const {
return vertex_tables_[label]->schema()->field(prop)->type();
}
prop_id_t edge_property_num(label_id_t label) const {
return static_cast<prop_id_t>(
schema_.GetEntry(label, PropertyGraphSchema::EDGE_TYPE_NAME)
.property_num());
}
std::shared_ptr<arrow::DataType> edge_property_type(label_id_t label,
prop_id_t prop) const {
return edge_tables_[label]->schema()->field(prop)->type();
}
std::shared_ptr<arrow::Table> vertex_data_table(label_id_t i) const {
return vertex_tables_[i]->GetTable();
}
std::shared_ptr<arrow::Table> edge_data_table(label_id_t i) const {
return edge_tables_[i]->GetTable();
}
template <typename DATA_T>
property_graph_utils::EdgeDataColumn<DATA_T, nbr_unit_t> edge_data_column(
label_id_t label, prop_id_t prop) const {
if (edge_tables_[label]->num_rows() == 0) {
return property_graph_utils::EdgeDataColumn<DATA_T, nbr_unit_t>();
} else {
// the finalized etables are guaranteed to have been concatenated
return property_graph_utils::EdgeDataColumn<DATA_T, nbr_unit_t>(
edge_tables_[label]->column(prop)->chunk(0));
}
}
template <typename DATA_T>
property_graph_utils::VertexDataColumn<DATA_T, vid_t> vertex_data_column(
label_id_t label, prop_id_t prop) const {
if (vertex_tables_[label]->num_rows() == 0) {
return property_graph_utils::VertexDataColumn<DATA_T, vid_t>(
InnerVertices(label));
} else {
// the finalized vtables are guaranteed to have been concatenated
return property_graph_utils::VertexDataColumn<DATA_T, vid_t>(
InnerVertices(label), vertex_tables_[label]->column(prop)->chunk(0));
}
}
vertex_range_t Vertices(label_id_t label_id) const {
return vertex_range_t(
vid_parser_.GenerateId(0, label_id, 0),
vid_parser_.GenerateId(0, label_id, tvnums_[label_id]));
}
vertex_range_t InnerVertices(label_id_t label_id) const {
return vertex_range_t(
vid_parser_.GenerateId(0, label_id, 0),
vid_parser_.GenerateId(0, label_id, ivnums_[label_id]));
}
vertex_range_t OuterVertices(label_id_t label_id) const {
return vertex_range_t(
vid_parser_.GenerateId(0, label_id, ivnums_[label_id]),
vid_parser_.GenerateId(0, label_id, tvnums_[label_id]));
}
vertex_range_t InnerVerticesSlice(label_id_t label_id, vid_t start,
vid_t end) const {
CHECK(start <= end && start <= ivnums_[label_id]);
if (end <= ivnums_[label_id]) {
return vertex_range_t(vid_parser_.GenerateId(0, label_id, start),
vid_parser_.GenerateId(0, label_id, end));
} else {
return vertex_range_t(
vid_parser_.GenerateId(0, label_id, start),
vid_parser_.GenerateId(0, label_id, ivnums_[label_id]));
}
}
inline vid_t GetVerticesNum(label_id_t label_id) const {
return tvnums_[label_id];
}
bool GetVertex(label_id_t label, const oid_t& oid, vertex_t& v) const {
vid_t gid;
if (vm_ptr_->GetGid(label, internal_oid_t(oid), gid)) {
return (vid_parser_.GetFid(gid) == fid_) ? InnerVertexGid2Vertex(gid, v)
: OuterVertexGid2Vertex(gid, v);
} else {
return false;
}
}
oid_t GetId(const vertex_t& v) const {
return IsInnerVertex(v) ? GetInnerVertexId(v) : GetOuterVertexId(v);
}
internal_oid_t GetInternalId(const vertex_t& v) const {
return IsInnerVertex(v) ? GetInnerVertexInternalId(v)
: GetOuterVertexInternalId(v);
}
fid_t GetFragId(const vertex_t& u) const {
return IsInnerVertex(u) ? fid_ : vid_parser_.GetFid(GetOuterVertexGid(u));
}
fid_t GetFragId(const vid_t& gid) const { return vid_parser_.GetFid(gid); }
size_t GetTotalNodesNum() const { return vm_ptr_->GetTotalNodesNum(); }
size_t GetTotalVerticesNum() const { return vm_ptr_->GetTotalNodesNum(); }
size_t GetTotalVerticesNum(label_id_t label) const {
return vm_ptr_->GetTotalNodesNum(label);
}
size_t GetEdgeNum() const { return directed_ ? oenum_ + ienum_ : oenum_; }
size_t GetInEdgeNum() const { return ienum_; }
size_t GetOutEdgeNum() const { return oenum_; }
template <typename T>
T GetData(const vertex_t& v, prop_id_t prop_id) const {
return property_graph_utils::ValueGetter<T>::Value(
vertex_tables_columns_[vid_parser_.GetLabelId(v.GetValue())][prop_id],
vid_parser_.GetOffset(v.GetValue()));
}
bool HasChild(const vertex_t& v, label_id_t e_label) const {
return GetLocalOutDegree(v, e_label) != 0;
}
bool HasParent(const vertex_t& v, label_id_t e_label) const {
return GetLocalInDegree(v, e_label) != 0;
}
int GetLocalOutDegree(const vertex_t& v, label_id_t e_label) const {
return GetOutgoingAdjList(v, e_label).Size();
}
int GetLocalInDegree(const vertex_t& v, label_id_t e_label) const {
return GetIncomingAdjList(v, e_label).Size();
}
// FIXME: grape message buffer compatibility
bool Gid2Vertex(const vid_t& gid, vertex_t& v) const {
return (vid_parser_.GetFid(gid) == fid_) ? InnerVertexGid2Vertex(gid, v)
: OuterVertexGid2Vertex(gid, v);
}
vid_t Vertex2Gid(const vertex_t& v) const {
return IsInnerVertex(v) ? GetInnerVertexGid(v) : GetOuterVertexGid(v);
}
inline vid_t GetInnerVerticesNum(label_id_t label_id) const {
return ivnums_[label_id];
}
inline vid_t GetOuterVerticesNum(label_id_t label_id) const {
return ovnums_[label_id];
}
inline bool IsInnerVertex(const vertex_t& v) const {
return vid_parser_.GetOffset(v.GetValue()) <
static_cast<int64_t>(ivnums_[vid_parser_.GetLabelId(v.GetValue())]);
}
inline bool IsOuterVertex(const vertex_t& v) const {
vid_t offset = vid_parser_.GetOffset(v.GetValue());
label_id_t label = vid_parser_.GetLabelId(v.GetValue());
return offset < tvnums_[label] && offset >= ivnums_[label];
}
bool GetInnerVertex(label_id_t label, const oid_t& oid, vertex_t& v) const {
vid_t gid;
if (vm_ptr_->GetGid(fid_, label, internal_oid_t(oid), gid)) {
v.SetValue(vid_parser_.GetLid(gid));
return true;
}
return false;
}
bool GetOuterVertex(label_id_t label, const oid_t& oid, vertex_t& v) const {
vid_t gid;
if (vm_ptr_->GetGid(label, internal_oid_t(oid), gid)) {
return OuterVertexGid2Vertex(gid, v);
}
return false;
}
inline oid_t GetInnerVertexId(const vertex_t& v) const {
return oid_t(GetInnerVertexInternalId(v));
}
inline internal_oid_t GetInnerVertexInternalId(const vertex_t& v) const {
internal_oid_t internal_oid;
vid_t gid =
vid_parser_.GenerateId(fid_, vid_parser_.GetLabelId(v.GetValue()),
vid_parser_.GetOffset(v.GetValue()));
CHECK(vm_ptr_->GetOid(gid, internal_oid));
return internal_oid;
}
inline oid_t GetOuterVertexId(const vertex_t& v) const {
return oid_t(GetOuterVertexInternalId(v));
}
inline internal_oid_t GetOuterVertexInternalId(const vertex_t& v) const {
vid_t gid = GetOuterVertexGid(v);
internal_oid_t internal_oid;
CHECK(vm_ptr_->GetOid(gid, internal_oid));
return internal_oid;
}
inline oid_t Gid2Oid(const vid_t& gid) const {
internal_oid_t internal_oid;
CHECK(vm_ptr_->GetOid(gid, internal_oid));
return oid_t(internal_oid);
}
inline bool Oid2Gid(label_id_t label, const oid_t& oid, vid_t& gid) const {
return vm_ptr_->GetGid(label, internal_oid_t(oid), gid);
}
inline bool Oid2Gid(label_id_t label, const oid_t& oid, vertex_t& v) const {
vid_t gid;
if (vm_ptr_->GetGid(label, internal_oid_t(oid), gid)) {
v.SetValue(gid);
return true;
}
return false;
}
inline bool InnerVertexGid2Vertex(const vid_t& gid, vertex_t& v) const {
v.SetValue(vid_parser_.GetLid(gid));
return true;
}
inline bool OuterVertexGid2Vertex(const vid_t& gid, vertex_t& v) const {
auto map = ovg2l_maps_ptr_[vid_parser_.GetLabelId(gid)];
auto iter = map->find(gid);
if (iter != map->end()) {
v.SetValue(iter->second);
return true;
} else {
return false;
}
}
inline vid_t GetOuterVertexGid(const vertex_t& v) const {
label_id_t v_label = vid_parser_.GetLabelId(v.GetValue());
return ovgid_lists_ptr_[v_label][vid_parser_.GetOffset(v.GetValue()) -
static_cast<int64_t>(ivnums_[v_label])];
}
inline vid_t GetInnerVertexGid(const vertex_t& v) const {
return vid_parser_.GenerateId(fid_, vid_parser_.GetLabelId(v.GetValue()),
vid_parser_.GetOffset(v.GetValue()));
}
template <bool COMPACT_ = COMPACT>
inline typename std::enable_if<!COMPACT_, adj_list_t>::type
GetIncomingAdjList(const vertex_t& v, label_id_t e_label) const {
vid_t vid = v.GetValue();
label_id_t v_label = vid_parser_.GetLabelId(vid);
int64_t v_offset = vid_parser_.GetOffset(vid);
const int64_t* offset_array = ie_offsets_ptr_lists_[v_label][e_label];
const nbr_unit_t* ie = ie_ptr_lists_[v_label][e_label];
return adj_list_t(&ie[offset_array[v_offset]],
&ie[offset_array[v_offset + 1]],
flatten_edge_tables_columns_[e_label]);
}
template <bool COMPACT_ = COMPACT>
inline typename std::enable_if<COMPACT_, compact_adj_list_t>::type
GetIncomingAdjList(const vertex_t& v, label_id_t e_label) const {
vid_t vid = v.GetValue();
label_id_t v_label = vid_parser_.GetLabelId(vid);
int64_t v_offset = vid_parser_.GetOffset(vid);
const int64_t* offset_array = ie_offsets_ptr_lists_[v_label][e_label];
const int64_t* boffset_array = ie_boffsets_ptr_lists_[v_label][e_label];
const uint8_t* ptr = compact_ie_ptr_lists_[v_label][e_label];
return compact_adj_list_t(
ptr + boffset_array[v_offset], ptr + boffset_array[v_offset + 1],
offset_array[v_offset + 1] - offset_array[v_offset],
flatten_edge_tables_columns_[e_label]);
}
template <bool COMPACT_ = COMPACT>
inline typename std::enable_if<!COMPACT_, raw_adj_list_t>::type
GetIncomingRawAdjList(const vertex_t& v, label_id_t e_label) const {
vid_t vid = v.GetValue();
label_id_t v_label = vid_parser_.GetLabelId(vid);
int64_t v_offset = vid_parser_.GetOffset(vid);
const int64_t* offset_array = ie_offsets_ptr_lists_[v_label][e_label];
const nbr_unit_t* ie = ie_ptr_lists_[v_label][e_label];
return raw_adj_list_t(&ie[offset_array[v_offset]],
&ie[offset_array[v_offset + 1]]);
}
template <bool COMPACT_ = COMPACT>
inline typename std::enable_if<!COMPACT_, adj_list_t>::type
GetOutgoingAdjList(const vertex_t& v, label_id_t e_label) const {
vid_t vid = v.GetValue();
label_id_t v_label = vid_parser_.GetLabelId(vid);
int64_t v_offset = vid_parser_.GetOffset(vid);
const int64_t* offset_array = oe_offsets_ptr_lists_[v_label][e_label];
const nbr_unit_t* oe = oe_ptr_lists_[v_label][e_label];
return adj_list_t(&oe[offset_array[v_offset]],
&oe[offset_array[v_offset + 1]],
flatten_edge_tables_columns_[e_label]);
}
template <bool COMPACT_ = COMPACT>
inline typename std::enable_if<COMPACT_, compact_adj_list_t>::type
GetOutgoingAdjList(const vertex_t& v, label_id_t e_label) const {
vid_t vid = v.GetValue();
label_id_t v_label = vid_parser_.GetLabelId(vid);
int64_t v_offset = vid_parser_.GetOffset(vid);
const int64_t* offset_array = oe_offsets_ptr_lists_[v_label][e_label];
const int64_t* boffset_array = oe_boffsets_ptr_lists_[v_label][e_label];
const uint8_t* ptr = compact_oe_ptr_lists_[v_label][e_label];
return compact_adj_list_t(
ptr + boffset_array[v_offset], ptr + boffset_array[v_offset + 1],
offset_array[v_offset + 1] - offset_array[v_offset],
flatten_edge_tables_columns_[e_label]);
}
template <bool COMPACT_ = COMPACT>
inline typename std::enable_if<!COMPACT_, raw_adj_list_t>::type
GetOutgoingRawAdjList(const vertex_t& v, label_id_t e_label) const {
vid_t vid = v.GetValue();
label_id_t v_label = vid_parser_.GetLabelId(vid);
int64_t v_offset = vid_parser_.GetOffset(vid);
const int64_t* offset_array = oe_offsets_ptr_lists_[v_label][e_label];
const nbr_unit_t* oe = oe_ptr_lists_[v_label][e_label];
return raw_adj_list_t(&oe[offset_array[v_offset]],
&oe[offset_array[v_offset + 1]]);
}
/**
* N.B.: as an temporary solution, for POC of graph-learn, will be removed
* later.
*/
inline const int64_t* GetIncomingOffsetArray(label_id_t v_label,
label_id_t e_label) const {
return ie_offsets_ptr_lists_[v_label][e_label];
}
inline const int64_t* GetOutgoingOffsetArray(label_id_t v_label,
label_id_t e_label) const {
return oe_offsets_ptr_lists_[v_label][e_label];
}
inline int64_t GetIncomingOffsetLength(label_id_t v_label,
label_id_t e_label) const {
return ie_offsets_lists_[v_label][e_label]->length();
}
inline int64_t GetOutgoingOffsetLength(label_id_t v_label,
label_id_t e_label) const {
return oe_offsets_lists_[v_label][e_label]->length();
}
inline std::pair<int64_t, int64_t> GetOutgoingAdjOffsets(
const vertex_t& v, label_id_t e_label) const {
vid_t vid = v.GetValue();
label_id_t v_label = vid_parser_.GetLabelId(vid);
int64_t v_offset = vid_parser_.GetOffset(vid);
const int64_t* offset_array = oe_offsets_ptr_lists_[v_label][e_label];
return std::make_pair(offset_array[v_offset], offset_array[v_offset + 1]);
}
inline grape::DestList IEDests(const vertex_t& v, label_id_t e_label) const {
int64_t offset = vid_parser_.GetOffset(v.GetValue());
auto v_label = vertex_label(v);
return grape::DestList(idoffset_[v_label][e_label][offset],
idoffset_[v_label][e_label][offset + 1]);
}
inline grape::DestList OEDests(const vertex_t& v, label_id_t e_label) const {
int64_t offset = vid_parser_.GetOffset(v.GetValue());
auto v_label = vertex_label(v);
return grape::DestList(odoffset_[v_label][e_label][offset],
odoffset_[v_label][e_label][offset + 1]);
}
inline grape::DestList IOEDests(const vertex_t& v, label_id_t e_label) const {
int64_t offset = vid_parser_.GetOffset(v.GetValue());
auto v_label = vertex_label(v);
return grape::DestList(iodoffset_[v_label][e_label][offset],
iodoffset_[v_label][e_label][offset + 1]);
}
const std::shared_ptr<vertex_map_t> GetVertexMap() const { return vm_ptr_; }
std::shared_ptr<vertex_map_t> GetVertexMap() { return vm_ptr_; }
void PrepareToRunApp(const grape::CommSpec& comm_spec,
grape::PrepareConf conf);
boost::leaf::result<ObjectID> AddVerticesAndEdges(
Client& client,
std::map<label_id_t, std::shared_ptr<arrow::Table>>&& vertex_tables_map,
std::map<label_id_t, std::shared_ptr<arrow::Table>>&& edge_tables_map,
ObjectID vm_id,
const std::vector<std::set<std::pair<std::string, std::string>>>&
edge_relations,
const int concurrency = std::thread::hardware_concurrency()) override;
boost::leaf::result<ObjectID> AddVertices(
Client& client,
std::map<label_id_t, std::shared_ptr<arrow::Table>>&& vertex_tables_map,
ObjectID vm_id,
const int concurrency = std::thread::hardware_concurrency()) override;
boost::leaf::result<ObjectID> AddEdges(
Client& client,
std::map<label_id_t, std::shared_ptr<arrow::Table>>&& edge_tables_map,
const std::vector<std::set<std::pair<std::string, std::string>>>&
edge_relations,
const int concurrency = std::thread::hardware_concurrency()) override;
/// Add a set of new vertex labels and a set of new edge labels to graph.
/// Vertex label id started from vertex_label_num_, and edge label id
/// started from edge_label_num_.
boost::leaf::result<ObjectID> AddNewVertexEdgeLabels(
Client& client,
std::vector<std::shared_ptr<arrow::Table>>&& vertex_tables,
std::vector<std::shared_ptr<arrow::Table>>&& edge_tables, ObjectID vm_id,
const std::vector<std::set<std::pair<std::string, std::string>>>&
edge_relations,
const int concurrency = std::thread::hardware_concurrency()) override;
/// Add a set of new vertex labels to graph. Vertex label id started from
/// vertex_label_num_.
boost::leaf::result<ObjectID> AddNewVertexLabels(
Client& client,
std::vector<std::shared_ptr<arrow::Table>>&& vertex_tables,
ObjectID vm_id,
const int concurrency = std::thread::hardware_concurrency()) override;
boost::leaf::result<ObjectID> AddVerticesToExistedLabel(
Client& client, label_id_t label_id,
std::shared_ptr<arrow::Table>&& vertex_table, ObjectID vm_id,
const int concurrency = std::thread::hardware_concurrency()) override;
boost::leaf::result<ObjectID> AddEdgesToExistedLabel(
Client& client, label_id_t label_id,
std::shared_ptr<arrow::Table>&& edge_table,
const std::set<std::pair<std::string, std::string>>& edge_relations,
const int concurrency = std::thread::hardware_concurrency()) override;
/// Add a set of new edge labels to graph. Edge label id started from
/// edge_label_num_.
boost::leaf::result<ObjectID> AddNewEdgeLabels(
Client& client, std::vector<std::shared_ptr<arrow::Table>>&& edge_tables,
const std::vector<std::set<std::pair<std::string, std::string>>>&
edge_relations,
const int concurrency = std::thread::hardware_concurrency()) override;
boost::leaf::result<vineyard::ObjectID> AddVertexColumns(
vineyard::Client& client,
const std::map<
label_id_t,
std::vector<std::pair<std::string, std::shared_ptr<arrow::Array>>>>
columns,
bool replace = false) override;
boost::leaf::result<vineyard::ObjectID> AddVertexColumns(
vineyard::Client& client,
const std::map<label_id_t,
std::vector<std::pair<
std::string, std::shared_ptr<arrow::ChunkedArray>>>>
columns,
bool replace = false) override;
template <typename ArrayType = arrow::Array>
boost::leaf::result<vineyard::ObjectID> AddVertexColumnsImpl(
vineyard::Client& client,
const std::map<
label_id_t,
std::vector<std::pair<std::string, std::shared_ptr<ArrayType>>>>
columns,
bool replace = false);
boost::leaf::result<vineyard::ObjectID> AddEdgeColumns(
vineyard::Client& client,
const std::map<
label_id_t,
std::vector<std::pair<std::string, std::shared_ptr<arrow::Array>>>>
columns,
bool replace = false) override;
boost::leaf::result<vineyard::ObjectID> AddEdgeColumns(
vineyard::Client& client,
const std::map<label_id_t,
std::vector<std::pair<
std::string, std::shared_ptr<arrow::ChunkedArray>>>>
columns,
bool replace = false) override;
template <typename ArrayType = arrow::Array>
boost::leaf::result<vineyard::ObjectID> AddEdgeColumnsImpl(
vineyard::Client& client,
const std::map<
label_id_t,
std::vector<std::pair<std::string, std::shared_ptr<ArrayType>>>>
columns,
bool replace = false);
boost::leaf::result<vineyard::ObjectID> Project(
vineyard::Client& client,
std::map<label_id_t, std::vector<prop_id_t>> vertices,
std::map<label_id_t, std::vector<prop_id_t>> edges);
boost::leaf::result<vineyard::ObjectID> TransformDirection(
vineyard::Client& client, int concurrency);
boost::leaf::result<vineyard::ObjectID> ConsolidateVertexColumns(
vineyard::Client& client, const label_id_t vlabel,
std::vector<std::string> const& prop_names,
std::string const& consolidate_name);
boost::leaf::result<vineyard::ObjectID> ConsolidateVertexColumns(
vineyard::Client& client, const label_id_t vlabel,
std::vector<prop_id_t> const& props, std::string const& consolidate_name);
boost::leaf::result<vineyard::ObjectID> ConsolidateEdgeColumns(
vineyard::Client& client, const label_id_t elabel,
std::vector<std::string> const& prop_names,
std::string const& consolidate_name);
boost::leaf::result<vineyard::ObjectID> ConsolidateEdgeColumns(
vineyard::Client& client, const label_id_t elabel,
std::vector<prop_id_t> const& props, std::string const& consolidate_name);
private:
void initPointers();
void initDestFidList(
const grape::CommSpec& comm_spec, const bool in_edge, const bool out_edge,
std::vector<std::vector<std::vector<fid_t>>>& fid_lists,
std::vector<std::vector<std::vector<fid_t*>>>& fid_lists_offset);
void directedCSR2Undirected(
vineyard::Client& client,
std::vector<std::vector<std::shared_ptr<PodArrayBuilder<nbr_unit_t>>>>&
oe_lists,
std::vector<std::vector<std::shared_ptr<FixedInt64Builder>>>&
oe_offsets_lists,
const int concurrency, bool& is_multigraph);
[[shared]] fid_t fid_, fnum_;
[[shared]] bool directed_;
[[shared]] bool local_vertex_map_;
[[shared]] bool compact_edges_;
[[shared]] bool is_multigraph_;
[[shared]] property_graph_types::LABEL_ID_TYPE vertex_label_num_;
[[shared]] property_graph_types::LABEL_ID_TYPE edge_label_num_;
size_t oenum_, ienum_; // FIXME: should be pre-computable
[[shared]] String oid_type, vid_type;
[[shared]] vineyard::Array<vid_t> ivnums_, ovnums_, tvnums_;
[[shared]] List<std::shared_ptr<Table>> vertex_tables_;
std::vector<std::vector<const void*>> vertex_tables_columns_;
[[shared]] List<std::shared_ptr<vid_vineyard_array_t>> ovgid_lists_;
std::vector<const vid_t*> ovgid_lists_ptr_;
[[shared]] List<std::shared_ptr<vineyard::Hashmap<vid_t, vid_t>>> ovg2l_maps_;
std::vector<vineyard::Hashmap<vid_t, vid_t>*> ovg2l_maps_ptr_;
[[shared]] List<std::shared_ptr<Table>> edge_tables_;
std::vector<std::vector<const void*>> edge_tables_columns_;
std::vector<const void**> flatten_edge_tables_columns_;
[[shared]] List<List<std::shared_ptr<FixedSizeBinaryArray>>> ie_lists_,
oe_lists_;
std::vector<std::vector<const nbr_unit_t*>> ie_ptr_lists_, oe_ptr_lists_;
[[shared]] List<List<std::shared_ptr<UInt8Array>>> compact_ie_lists_,
compact_oe_lists_;
std::vector<std::vector<const uint8_t*>> compact_ie_ptr_lists_,
compact_oe_ptr_lists_;
[[shared]] List<List<std::shared_ptr<Int64Array>>> ie_offsets_lists_,
oe_offsets_lists_;
std::vector<std::vector<const int64_t*>> ie_offsets_ptr_lists_,
oe_offsets_ptr_lists_;
[[shared]] List<List<std::shared_ptr<Int64Array>>> ie_boffsets_lists_,
oe_boffsets_lists_;
std::vector<std::vector<const int64_t*>> ie_boffsets_ptr_lists_,
oe_boffsets_ptr_lists_;
std::vector<std::vector<std::vector<fid_t>>> idst_, odst_, iodst_;
std::vector<std::vector<std::vector<fid_t*>>> idoffset_, odoffset_,
iodoffset_;
[[shared]] std::shared_ptr<vertex_map_t> vm_ptr_;
vineyard::IdParser<vid_t> vid_parser_;
[[shared]] json schema_json_;
PropertyGraphSchema schema_;
friend class ArrowFragmentBaseBuilder<OID_T, VID_T, VERTEX_MAP_T, COMPACT>;
template <typename _OID_T, typename _VID_T, typename VDATA_T,
typename EDATA_T, typename _VERTEX_MAP_T, bool _COMPACT>
friend class gs::ArrowProjectedFragment;
};
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
} // namespace vineyard
#endif // MODULES_GRAPH_FRAGMENT_ARROW_FRAGMENT_VINEYARD_MOD_
// vim: syntax=cpp