Flex  0.17.9
types.h
Go to the documentation of this file.
1 
16 #ifndef GRAPHSCOPE_TYPES_H_
17 #define GRAPHSCOPE_TYPES_H_
18 
19 #include <assert.h>
20 
21 #include <chrono>
22 #include <istream>
23 #include <ostream>
24 #include <vector>
25 
26 #include <boost/date_time/posix_time/posix_time.hpp>
27 
28 #include "grape/serialization/in_archive.h"
29 #include "grape/serialization/out_archive.h"
30 
31 #include <yaml-cpp/yaml.h>
32 
33 namespace grape {
34 
35 inline bool operator<(const EmptyType& lhs, const EmptyType& rhs) {
36  return false;
37 }
38 
39 } // namespace grape
40 
41 namespace gs {
42 
43 // primitive types
44 static constexpr const char* DT_UNSIGNED_INT8 = "DT_UNSIGNED_INT8";
45 static constexpr const char* DT_UNSIGNED_INT16 = "DT_UNSIGNED_INT16";
46 static constexpr const char* DT_SIGNED_INT32 = "DT_SIGNED_INT32";
47 static constexpr const char* DT_UNSIGNED_INT32 = "DT_UNSIGNED_INT32";
48 static constexpr const char* DT_SIGNED_INT64 = "DT_SIGNED_INT64";
49 static constexpr const char* DT_UNSIGNED_INT64 = "DT_UNSIGNED_INT64";
50 static constexpr const char* DT_BOOL = "DT_BOOL";
51 static constexpr const char* DT_FLOAT = "DT_FLOAT";
52 static constexpr const char* DT_DOUBLE = "DT_DOUBLE";
53 static constexpr const char* DT_STRING = "DT_STRING";
54 static constexpr const char* DT_STRINGMAP = "DT_STRINGMAP";
55 static constexpr const char* DT_DATE = "DT_DATE32";
56 static constexpr const char* DT_DAY = "DT_DAY32";
57 
58 enum class StorageStrategy {
59  kNone,
60  kMem,
61  kDisk,
62 };
63 
64 namespace impl {
65 
66 enum class PropertyTypeImpl {
67  kInt32,
68  kDate,
69  kDay,
71  kEmpty,
72  kInt64,
73  kDouble,
74  kUInt32,
75  kUInt64,
76  kBool,
77  kFloat,
78  kUInt8,
79  kUInt16,
80  kStringMap,
81  kVarChar,
83  kLabel,
85  kRecord,
86  kString,
87 };
88 
89 // Stores additional type information for PropertyTypeImpl
91  uint16_t max_length; // for varchar
92 };
93 } // namespace impl
94 
95 struct PropertyType {
96  static constexpr const uint16_t STRING_DEFAULT_MAX_LENGTH = 256;
99 
100  constexpr PropertyType()
103  : type_enum(type), additional_type_info() {}
104  constexpr PropertyType(impl::PropertyTypeImpl type, uint16_t max_length)
105  : type_enum(type), additional_type_info({.max_length = max_length}) {
106  assert(type == impl::PropertyTypeImpl::kVarChar);
107  }
108 
109  bool IsVarchar() const;
110  std::string ToString() const;
111 
112  static PropertyType Empty();
113  static PropertyType Bool();
114  static PropertyType UInt8();
115  static PropertyType UInt16();
116  static PropertyType Int32();
117  static PropertyType UInt32();
118  static PropertyType Float();
119  static PropertyType Int64();
120  static PropertyType UInt64();
121  static PropertyType Double();
122  static PropertyType Date();
123  static PropertyType Day();
124  static PropertyType StringView();
125  static PropertyType StringMap();
126  static PropertyType Varchar(uint16_t max_length);
127  static PropertyType VertexGlobalId();
128  static PropertyType Label();
129  static PropertyType RecordView();
130  static PropertyType Record();
131  static PropertyType String();
132 
133  static const PropertyType kEmpty;
134  static const PropertyType kBool;
135  static const PropertyType kUInt8;
136  static const PropertyType kUInt16;
137  static const PropertyType kInt32;
138  static const PropertyType kUInt32;
139  static const PropertyType kFloat;
140  static const PropertyType kInt64;
141  static const PropertyType kUInt64;
142  static const PropertyType kDouble;
143  static const PropertyType kDate;
144  static const PropertyType kDay;
145  static const PropertyType kStringView;
146  static const PropertyType kStringMap;
148  static const PropertyType kLabel;
149  static const PropertyType kRecordView;
150  static const PropertyType kRecord;
151  static const PropertyType kString;
152 
153  bool operator==(const PropertyType& other) const;
154  bool operator!=(const PropertyType& other) const;
155 };
156 
157 namespace config_parsing {
159 PropertyType StringToPrimitivePropertyType(const std::string& str);
160 } // namespace config_parsing
161 
162 // encoded with label_id and vid_t.
163 struct GlobalId {
164  using label_id_t = uint8_t;
165  using vid_t = uint32_t;
166  using gid_t = uint64_t;
167  static constexpr int32_t label_id_offset = 64 - sizeof(label_id_t) * 8;
168  static constexpr uint64_t vid_mask = (1ULL << label_id_offset) - 1;
169 
170  static label_id_t get_label_id(gid_t gid);
171  static vid_t get_vid(gid_t gid);
172 
173  uint64_t global_id;
174 
175  GlobalId();
177  GlobalId(gid_t gid);
178 
179  label_id_t label_id() const;
180  vid_t vid() const;
181 
182  std::string to_string() const;
183 };
184 
185 inline bool operator==(const GlobalId& lhs, const GlobalId& rhs) {
186  return lhs.global_id == rhs.global_id;
187 }
188 
189 inline bool operator!=(const GlobalId& lhs, const GlobalId& rhs) {
190  return lhs.global_id != rhs.global_id;
191 }
192 inline bool operator<(const GlobalId& lhs, const GlobalId& rhs) {
193  return lhs.global_id < rhs.global_id;
194 }
195 
196 inline bool operator>(const GlobalId& lhs, const GlobalId& rhs) {
197  return lhs.global_id > rhs.global_id;
198 }
199 
200 struct __attribute__((packed)) Date {
201  Date() = default;
202  ~Date() = default;
203  Date(int64_t x);
204 
205  std::string to_string() const;
206 
207  bool operator<(const Date& rhs) const {
208  return milli_second < rhs.milli_second;
209  }
210 
211  bool operator==(const Date& rhs) const {
212  return milli_second == rhs.milli_second;
213  }
214 
215  int64_t milli_second;
216 };
217 
218 struct DayValue {
219  uint32_t year : 18;
220  uint32_t month : 4;
221  uint32_t day : 5;
222  uint32_t hour : 5;
223 };
224 
225 struct Day {
226  Day() = default;
227  ~Day() = default;
228 
229  Day(int64_t ts);
230 
231  std::string to_string() const;
232 
233  uint32_t to_u32() const;
234  void from_u32(uint32_t val);
235 
236  int64_t to_timestamp() const {
237  const boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1));
238 
239  boost::gregorian::date new_date(year(), month(), day());
240  boost::posix_time::ptime new_time_point(
241  new_date, boost::posix_time::time_duration(hour(), 0, 0));
242  boost::posix_time::time_duration diff = new_time_point - epoch;
243  int64_t new_timestamp_sec = diff.total_seconds();
244 
245  return new_timestamp_sec * 1000;
246  }
247 
248  void from_timestamp(int64_t ts) {
249  const boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1));
250  int64_t ts_sec = ts / 1000;
251  boost::posix_time::ptime time_point =
252  epoch + boost::posix_time::seconds(ts_sec);
253  boost::posix_time::ptime::date_type date = time_point.date();
254  boost::posix_time::time_duration td = time_point.time_of_day();
255  this->value.internal.year = date.year();
256  this->value.internal.month = date.month().as_number();
257  this->value.internal.day = date.day();
258  this->value.internal.hour = td.hours();
259 
260  assert(ts == to_timestamp());
261  }
262 
263  bool operator<(const Day& rhs) const { return this->to_u32() < rhs.to_u32(); }
264  bool operator==(const Day& rhs) const {
265  return this->to_u32() == rhs.to_u32();
266  }
267 
268  int year() const;
269  int month() const;
270  int day() const;
271  int hour() const;
272 
273  union {
274  DayValue internal;
275  uint32_t integer;
276  } value;
277 };
278 
279 struct LabelKey {
280  using label_data_type = uint8_t;
281  int32_t label_id;
282  LabelKey() = default;
284 };
285 
286 class Table;
287 struct Any;
288 struct RecordView {
289  RecordView() = default;
290  RecordView(size_t offset, const Table* table)
291  : offset(offset), table(table) {}
292  size_t size() const;
293  Any operator[](size_t idx) const;
294 
295  template <typename T>
296  T get_field(int col_id) const;
297 
298  inline bool operator==(const RecordView& other) const {
299  if (size() != other.size()) {
300  return false;
301  }
302  return table == other.table && offset == other.offset;
303  }
304 
305  std::string to_string() const;
306 
307  size_t offset;
308  const Table* table;
309 };
310 
311 struct Any;
312 struct Record {
313  Record() : len(0), props(nullptr) {}
314  Record(size_t len);
315  Record(const Record& other);
316  Record(Record&& other);
317  Record& operator=(const Record& other);
318  Record(const std::vector<Any>& vec);
319  Record(const std::initializer_list<Any>& list);
320  ~Record();
321  size_t size() const { return len; }
322  Any operator[](size_t idx) const;
323  Any* begin() const;
324  Any* end() const;
325 
326  size_t len;
328 };
329 
330 struct StringPtr {
331  StringPtr() : ptr(nullptr) {}
332  StringPtr(const std::string& str) : ptr(new std::string(str)) {}
333  StringPtr(const StringPtr& other) {
334  if (other.ptr) {
335  ptr = new std::string(*other.ptr);
336  } else {
337  ptr = nullptr;
338  }
339  }
340  StringPtr(StringPtr&& other) : ptr(other.ptr) { other.ptr = nullptr; }
341  StringPtr& operator=(const StringPtr& other) {
342  if (this == &other) {
343  return *this;
344  }
345  if (ptr) {
346  delete ptr;
347  }
348  if (other.ptr) {
349  ptr = new std::string(*other.ptr);
350  } else {
351  ptr = nullptr;
352  }
353  return *this;
354  }
356  if (ptr) {
357  delete ptr;
358  }
359  }
360  // return string_view
361  std::string_view operator*() const {
362  return std::string_view((*ptr).data(), (*ptr).size());
363  }
364  std::string* ptr;
365 };
366 union AnyValue {
367  AnyValue() {}
369 
370  bool b;
371  int32_t i;
372  uint32_t ui;
373  float f;
374  int64_t l;
375  uint64_t ul;
378 
379  Date d;
381  std::string_view s;
382  double db;
383  uint8_t u8;
384  uint16_t u16;
386 
387  // Non-trivial types
390 };
391 
392 template <typename T>
394 
395 struct Any {
396  Any() : type(PropertyType::kEmpty) {}
397 
398  Any(const Any& other) : type(other.type) {
399  if (type == PropertyType::kRecord) {
400  new (&value.record) Record(other.value.record);
402  new (&value.s_ptr) StringPtr(other.value.s_ptr);
403  } else {
404  memcpy(static_cast<void*>(&value), static_cast<const void*>(&other.value),
405  sizeof(AnyValue));
406  }
407  }
408 
409  Any(Any&& other) : type(other.type) {
410  if (type == PropertyType::kRecord) {
411  new (&value.record) Record(std::move(other.value.record));
413  new (&value.s_ptr) StringPtr(std::move(other.value.s_ptr));
414  } else {
415  memcpy(static_cast<void*>(&value), static_cast<const void*>(&other.value),
416  sizeof(AnyValue));
417  }
418  }
419 
420  Any(const std::initializer_list<Any>& list) {
422  new (&value.record) Record(list);
423  }
424  Any(const std::vector<Any>& vec) {
426  new (&value.record) Record(vec);
427  }
428 
429  Any(const std::string& str) {
431  new (&value.s_ptr) StringPtr(str);
432  }
433 
434  template <typename T>
435  Any(const T& val) {
436  Any a = Any::From(val);
437  type = a.type;
438  if (type == PropertyType::kRecord) {
439  new (&value.record) Record(a.value.record);
441  new (&value.s_ptr) StringPtr(a.value.s_ptr);
442  } else {
443  memcpy(static_cast<void*>(&value), static_cast<const void*>(&a.value),
444  sizeof(AnyValue));
445  }
446  }
447 
448  Any& operator=(const Any& other) {
449  if (this == &other) {
450  return *this;
451  }
452  if (type == PropertyType::kRecord) {
453  value.record.~Record();
454  }
455  type = other.type;
456  if (type == PropertyType::kRecord) {
457  new (&value.record) Record(other.value.record);
459  new (&value.s_ptr) StringPtr(other.value.s_ptr);
460  } else {
461  memcpy(static_cast<void*>(&value), static_cast<const void*>(&other.value),
462  sizeof(AnyValue));
463  }
464  return *this;
465  }
466 
467  ~Any() {
468  if (type == PropertyType::kRecord) {
469  value.record.~Record();
472  }
473  }
474 
475  int64_t get_long() const {
476  assert(type == PropertyType::kInt64);
477  return value.l;
478  }
479  void set_bool(bool v) {
481  value.b = v;
482  }
483 
484  void set_i32(int32_t v) {
486  value.i = v;
487  }
488 
489  void set_u32(uint32_t v) {
491  value.ui = v;
492  }
493 
494  void set_i64(int64_t v) {
496  value.l = v;
497  }
498 
499  void set_u64(uint64_t v) {
501  value.ul = v;
502  }
503 
506  value.vertex_gid = v;
507  }
508 
511  value.label_key = v;
512  }
513 
514  void set_date(int64_t v) {
516  value.d.milli_second = v;
517  }
518 
519  void set_date(Date v) {
521  value.d = v;
522  }
523 
524  void set_day(Day v) {
526  value.day = v;
527  }
528 
529  void set_string_view(std::string_view v) {
531  value.s = v;
532  }
533 
534  void set_string(const std::string& v) {
536  new (&value.s_ptr) StringPtr(v);
537  }
538 
539  void set_float(float v) {
541  value.f = v;
542  }
543 
544  void set_double(double db) {
546  value.db = db;
547  }
548 
549  void set_u8(uint8_t v) {
551  value.u8 = v;
552  }
553 
554  void set_u16(uint16_t v) {
556  value.u16 = v;
557  }
558 
561  value.record_view = v;
562  }
563 
564  void set_record(Record v) {
565  if (type == PropertyType::kRecord) {
566  value.record.~Record();
567  }
569  new (&(value.record)) Record(v);
570  }
571 
572  std::string to_string() const {
573  if (type == PropertyType::kInt32) {
574  return std::to_string(value.i);
575  } else if (type == PropertyType::kInt64) {
576  return std::to_string(value.l);
578  return *value.s_ptr.ptr;
579  } else if (type == PropertyType::kStringView) {
580  return std::string(value.s.data(), value.s.size());
581  // return value.s.to_string();
582  } else if (type == PropertyType::kDate) {
583  return value.d.to_string();
584  } else if (type == PropertyType::kDay) {
585  return value.day.to_string();
586  } else if (type == PropertyType::kEmpty) {
587  return "NULL";
588  } else if (type == PropertyType::kDouble) {
589  return std::to_string(value.db);
590  } else if (type == PropertyType::kUInt8) {
591  return std::to_string(value.u8);
592  } else if (type == PropertyType::kUInt16) {
593  return std::to_string(value.u16);
594  } else if (type == PropertyType::kUInt32) {
595  return std::to_string(value.ui);
596  } else if (type == PropertyType::kUInt64) {
597  return std::to_string(value.ul);
598  } else if (type == PropertyType::kBool) {
599  return value.b ? "true" : "false";
600  } else if (type == PropertyType::kFloat) {
601  return std::to_string(value.f);
602  } else if (type == PropertyType::kVertexGlobalId) {
603  return value.vertex_gid.to_string();
604  } else if (type == PropertyType::kLabel) {
606  } else {
607  LOG(FATAL) << "Unexpected property type: "
608  << static_cast<int>(type.type_enum);
609  return "";
610  }
611  }
612 
613  const std::string& AsString() const {
615  return *value.s_ptr.ptr;
616  }
617 
618  int64_t AsInt64() const {
619  assert(type == PropertyType::kInt64);
620  return value.l;
621  }
622 
623  uint64_t AsUInt64() const {
624  assert(type == PropertyType::kUInt64);
625  return value.ul;
626  }
627 
628  int32_t AsInt32() const {
629  assert(type == PropertyType::kInt32);
630  return value.i;
631  }
632 
633  uint32_t AsUInt32() const {
634  assert(type == PropertyType::kUInt32);
635  return value.ui;
636  }
637 
638  bool AsBool() const {
639  assert(type == PropertyType::kBool);
640  return value.b;
641  }
642 
643  double AsDouble() const {
644  assert(type == PropertyType::kDouble);
645  return value.db;
646  }
647 
648  float AsFloat() const {
649  assert(type == PropertyType::kFloat);
650  return value.f;
651  }
652 
653  std::string_view AsStringView() const {
654  assert(type == PropertyType::kStringView);
656  return value.s;
657  } else {
658  return *value.s_ptr.ptr;
659  }
660  }
661 
662  const Date& AsDate() const {
663  assert(type == PropertyType::kDate);
664  return value.d;
665  }
666 
667  const Day& AsDay() const {
668  assert(type == PropertyType::kDay);
669  return value.day;
670  }
671 
672  const GlobalId& AsGlobalId() const {
674  return value.vertex_gid;
675  }
676 
677  const LabelKey& AsLabelKey() const {
678  assert(type == PropertyType::kLabel);
679  return value.label_key;
680  }
681 
682  const RecordView& AsRecordView() const {
683  assert(type == PropertyType::kRecordView);
684  return value.record_view;
685  }
686 
687  const Record& AsRecord() const {
688  assert(type == PropertyType::kRecord);
689  return value.record;
690  }
691 
692  template <typename T>
693  static Any From(const T& value) {
695  }
696 
697  bool operator==(const Any& other) const {
698  if (type == other.type) {
699  if (type == PropertyType::kInt32) {
700  return value.i == other.value.i;
701  } else if (type == PropertyType::kInt64) {
702  return value.l == other.value.l;
703  } else if (type == PropertyType::kDate) {
704  return value.d.milli_second == other.value.d.milli_second;
705  } else if (type == PropertyType::kDay) {
706  return value.day == other.value.day;
708  return *value.s_ptr == other.AsStringView();
709  } else if (type == PropertyType::kStringView) {
710  return value.s == other.AsStringView();
711  } else if (type == PropertyType::kEmpty) {
712  return true;
713  } else if (type == PropertyType::kDouble) {
714  return value.db == other.value.db;
715  } else if (type == PropertyType::kUInt32) {
716  return value.ui == other.value.ui;
717  } else if (type == PropertyType::kUInt64) {
718  return value.ul == other.value.ul;
719  } else if (type == PropertyType::kBool) {
720  return value.b == other.value.b;
721  } else if (type == PropertyType::kFloat) {
722  return value.f == other.value.f;
723  } else if (type == PropertyType::kVertexGlobalId) {
724  return value.vertex_gid == other.value.vertex_gid;
725  } else if (type == PropertyType::kLabel) {
729  return false;
730  }
731  return value.s == other.value.s;
732  } else {
733  return false;
734  }
735  } else if (type == PropertyType::kRecordView) {
736  return value.record_view.offset == other.value.record_view.offset &&
738  } else if (type == PropertyType::kRecord) {
739  if (value.record.len != other.value.record.len) {
740  return false;
741  }
742  for (size_t i = 0; i < value.record.len; ++i) {
743  if (!(value.record.props[i] == other.value.record.props[i])) {
744  return false;
745  }
746  }
747  return true;
748  } else {
749  return false;
750  }
751  }
752 
753  bool operator<(const Any& other) const {
754  if (type == other.type) {
755  if (type == PropertyType::kInt32) {
756  return value.i < other.value.i;
757  } else if (type == PropertyType::kInt64) {
758  return value.l < other.value.l;
759  } else if (type == PropertyType::kDate) {
760  return value.d.milli_second < other.value.d.milli_second;
761  } else if (type == PropertyType::kDay) {
762  return value.day < other.value.day;
764  return *value.s_ptr < other.AsStringView();
765  } else if (type == PropertyType::kStringView) {
766  return value.s < other.AsStringView();
767  } else if (type == PropertyType::kEmpty) {
768  return false;
769  } else if (type == PropertyType::kDouble) {
770  return value.db < other.value.db;
771  } else if (type == PropertyType::kUInt32) {
772  return value.ui < other.value.ui;
773  } else if (type == PropertyType::kUInt64) {
774  return value.ul < other.value.ul;
775  } else if (type == PropertyType::kBool) {
776  return value.b < other.value.b;
777  } else if (type == PropertyType::kFloat) {
778  return value.f < other.value.f;
779  } else if (type == PropertyType::kVertexGlobalId) {
780  return value.vertex_gid < other.value.vertex_gid;
781  } else if (type == PropertyType::kLabel) {
783  } else if (type == PropertyType::kRecord) {
784  for (size_t i = 0; i < value.record.len; ++i) {
785  if (i >= other.value.record.len) {
786  return false;
787  }
788  if (value.record.props[i] < other.value.record.props[i]) {
789  return true;
790  } else if (other.value.record.props[i] < value.record.props[i]) {
791  return false;
792  }
793  }
794  return false;
795  } else {
796  return false;
797  }
798  } else {
799  LOG(FATAL) << "Type [" << static_cast<int>(type.type_enum) << "] and ["
800  << static_cast<int>(other.type.type_enum)
801  << "] cannot be compared..";
802  }
803  }
804 
807 };
808 
809 template <typename T>
810 struct ConvertAny {
811  static void to(const Any& value, T& out) {
812  LOG(FATAL) << "Unexpected convert type...";
813  }
814 };
815 
816 template <>
817 struct ConvertAny<bool> {
818  static void to(const Any& value, bool& out) {
819  assert(value.type == PropertyType::kBool);
820  out = value.value.b;
821  }
822 };
823 
824 template <>
825 struct ConvertAny<int32_t> {
826  static void to(const Any& value, int32_t& out) {
827  assert(value.type == PropertyType::kInt32);
828  out = value.value.i;
829  }
830 };
831 
832 template <>
833 struct ConvertAny<uint32_t> {
834  static void to(const Any& value, uint32_t& out) {
835  assert(value.type == PropertyType::kUInt32);
836  out = value.value.ui;
837  }
838 };
839 
840 template <>
841 struct ConvertAny<int64_t> {
842  static void to(const Any& value, int64_t& out) {
843  assert(value.type == PropertyType::kInt64);
844  out = value.value.l;
845  }
846 };
847 
848 template <>
849 struct ConvertAny<uint64_t> {
850  static void to(const Any& value, uint64_t& out) {
851  assert(value.type == PropertyType::kUInt64);
852  out = value.value.ul;
853  }
854 };
855 
856 template <>
858  static void to(const Any& value, GlobalId& out) {
859  assert(value.type == PropertyType::kVertexGlobalId);
860  out = value.value.vertex_gid;
861  }
862 };
863 
864 template <>
866  static void to(const Any& value, LabelKey& out) {
867  assert(value.type == PropertyType::kLabel);
868  out = value.value.label_key;
869  }
870 };
871 
872 template <>
873 struct ConvertAny<Date> {
874  static void to(const Any& value, Date& out) {
875  assert(value.type == PropertyType::kDate);
876  out = value.value.d;
877  }
878 };
879 
880 template <>
881 struct ConvertAny<Day> {
882  static void to(const Any& value, Day& out) {
883  assert(value.type == PropertyType::kDay);
884  out = value.value.day;
885  }
886 };
887 
888 template <>
889 struct ConvertAny<grape::EmptyType> {
890  static void to(const Any& value, grape::EmptyType& out) {
891  assert(value.type == PropertyType::kEmpty);
892  }
893 };
894 
895 template <>
896 struct ConvertAny<std::string> {
897  static void to(const Any& value, std::string& out) {
899  out = *value.value.s_ptr.ptr;
900  }
901 };
902 
903 template <>
904 struct ConvertAny<std::string_view> {
905  static void to(const Any& value, std::string_view& out) {
906  assert(value.type == PropertyType::kStringView);
907  out = value.value.s;
908  }
909 };
910 
911 template <>
912 struct ConvertAny<float> {
913  static void to(const Any& value, float& out) {
914  assert(value.type == PropertyType::kFloat);
915  out = value.value.f;
916  }
917 };
918 
919 template <>
920 struct ConvertAny<double> {
921  static void to(const Any& value, double& out) {
922  assert(value.type == PropertyType::kDouble);
923  out = value.value.db;
924  }
925 };
926 
927 template <>
929  static void to(const Any& value, RecordView& out) {
930  assert(value.type == PropertyType::kRecordView);
931  out.offset = value.value.record_view.offset;
932  out.table = value.value.record_view.table;
933  }
934 };
935 
936 template <>
938  static void to(const Any& value, Record& out) {
939  assert(value.type == PropertyType::kRecord);
940  out = value.value.record;
941  }
942 };
943 
944 template <typename T>
945 struct AnyConverter {};
946 
947 // specialization for bool
948 template <>
949 struct AnyConverter<bool> {
950  static PropertyType type() { return PropertyType::kBool; }
951 
952  static Any to_any(const bool& value) {
953  Any ret;
954  ret.set_bool(value);
955  return ret;
956  }
957  static const bool& from_any(const Any& value) {
958  assert(value.type == PropertyType::kBool);
959  return value.value.b;
960  }
961 
962  static const bool& from_any_value(const AnyValue& value) { return value.b; }
963 };
964 
965 template <>
966 struct AnyConverter<uint8_t> {
968  static Any to_any(const uint8_t& value) {
969  Any ret;
970  ret.set_u8(value);
971  return ret;
972  }
973  static const uint8_t& from_any(const Any& value) {
974  assert(value.type == PropertyType::kUInt8);
975  return value.value.u8;
976  }
977 };
978 
979 template <>
980 struct AnyConverter<uint16_t> {
982  static Any to_any(const uint16_t& value) {
983  Any ret;
984  ret.set_u16(value);
985  return ret;
986  }
987  static const uint16_t& from_any(const Any& value) {
988  assert(value.type == PropertyType::kUInt8);
989  return value.value.u16;
990  }
991 };
992 
993 template <>
994 struct AnyConverter<int32_t> {
996 
997  static Any to_any(const int32_t& value) {
998  Any ret;
999  ret.set_i32(value);
1000  return ret;
1001  }
1002 
1003  static const int32_t& from_any(const Any& value) {
1004  assert(value.type == PropertyType::kInt32);
1005  return value.value.i;
1006  }
1007 
1008  static const int32_t& from_any_value(const AnyValue& value) {
1009  return value.i;
1010  }
1011 };
1012 
1013 template <>
1014 struct AnyConverter<uint32_t> {
1016 
1017  static Any to_any(const uint32_t& value) {
1018  Any ret;
1019  ret.set_u32(value);
1020  return ret;
1021  }
1022 
1023  static const uint32_t& from_any(const Any& value) {
1024  assert(value.type == PropertyType::kUInt32);
1025  return value.value.ui;
1026  }
1027 
1028  static const uint32_t& from_any_value(const AnyValue& value) {
1029  return value.ui;
1030  }
1031 };
1032 template <>
1033 struct AnyConverter<int64_t> {
1035 
1036  static Any to_any(const int64_t& value) {
1037  Any ret;
1038  ret.set_i64(value);
1039  return ret;
1040  }
1041 
1042  static const int64_t& from_any(const Any& value) {
1043  assert(value.type == PropertyType::kInt64);
1044  return value.value.l;
1045  }
1046 
1047  static const int64_t& from_any_value(const AnyValue& value) {
1048  return value.l;
1049  }
1050 };
1051 
1052 template <>
1053 struct AnyConverter<uint64_t> {
1055 
1056  static Any to_any(const uint64_t& value) {
1057  Any ret;
1058  ret.set_u64(value);
1059  return ret;
1060  }
1061 
1062  static const uint64_t& from_any(const Any& value) {
1063  assert(value.type == PropertyType::kUInt64);
1064  return value.value.ul;
1065  }
1066 
1067  static const uint64_t& from_any_value(const AnyValue& value) {
1068  return value.ul;
1069  }
1070 };
1071 
1072 template <>
1075 
1076  static Any to_any(const GlobalId& value) {
1077  Any ret;
1078  ret.set_vertex_gid(value);
1079  return ret;
1080  }
1081 
1082  static const GlobalId& from_any(const Any& value) {
1083  assert(value.type == PropertyType::kVertexGlobalId);
1084  return value.value.vertex_gid;
1085  }
1086 
1087  static const GlobalId& from_any_value(const AnyValue& value) {
1088  return value.vertex_gid;
1089  }
1090 };
1091 
1092 template <>
1093 struct AnyConverter<Date> {
1095 
1096  static Any to_any(const Date& value) {
1097  Any ret;
1098  ret.set_date(value);
1099  return ret;
1100  }
1101 
1102  static Any to_any(int64_t value) {
1103  Any ret;
1104  ret.set_date(value);
1105  return ret;
1106  }
1107 
1108  static const Date& from_any(const Any& value) {
1109  assert(value.type == PropertyType::kDate);
1110  return value.value.d;
1111  }
1112 
1113  static const Date& from_any_value(const AnyValue& value) { return value.d; }
1114 };
1115 
1116 template <>
1118  static PropertyType type() { return PropertyType::kDay; }
1119 
1120  static Any to_any(const Day& value) {
1121  Any ret;
1122  ret.set_day(value);
1123  return ret;
1124  }
1125 
1126  static Any to_any(int64_t value) {
1127  Day dval(value);
1128  Any ret;
1129  ret.set_day(dval);
1130  return ret;
1131  }
1132 
1133  static const Day& from_any(const Any& value) {
1134  assert(value.type == PropertyType::kDay);
1135  return value.value.day;
1136  }
1137 
1138  static const Day& from_any_value(const AnyValue& value) { return value.day; }
1139 };
1140 
1141 template <>
1142 struct AnyConverter<std::string_view> {
1144 
1145  static Any to_any(const std::string_view& value) {
1146  Any ret;
1147  ret.set_string_view(value);
1148  return ret;
1149  }
1150 
1151  static const std::string_view& from_any(const Any& value) {
1152  assert(value.type == PropertyType::kStringView &&
1154  return value.value.s;
1155  }
1156 
1157  static const std::string_view& from_any_value(const AnyValue& value) {
1158  return value.s;
1159  }
1160 };
1161 
1162 template <>
1163 struct AnyConverter<std::string> {
1165 
1166  static Any to_any(const std::string& value) {
1167  Any ret;
1168  ret.set_string(value);
1169  return ret;
1170  }
1171 
1172  static std::string& from_any(const Any& value) {
1174  return *value.value.s_ptr.ptr;
1175  }
1176 
1177  static std::string& from_any_value(const AnyValue& value) {
1178  return *value.s_ptr.ptr;
1179  }
1180 };
1181 
1182 template <>
1183 struct AnyConverter<grape::EmptyType> {
1185 
1186  static Any to_any(const grape::EmptyType& value) {
1187  Any ret;
1188  return ret;
1189  }
1190 
1191  static grape::EmptyType from_any(const Any& value) {
1192  assert(value.type == PropertyType::kEmpty);
1193  return grape::EmptyType();
1194  }
1195 
1196  static grape::EmptyType from_any_value(const AnyValue& value) {
1197  return grape::EmptyType();
1198  }
1199 };
1200 
1201 template <>
1202 struct AnyConverter<double> {
1204 
1205  static Any to_any(const double& value) {
1206  Any ret;
1207  ret.set_double(value);
1208  return ret;
1209  }
1210 
1211  static const double& from_any(const Any& value) {
1212  assert(value.type == PropertyType::kDouble);
1213  return value.value.db;
1214  }
1215 
1216  static const double& from_any_value(const AnyValue& value) {
1217  return value.db;
1218  }
1219 };
1220 
1221 // specialization for float
1222 template <>
1223 struct AnyConverter<float> {
1225 
1226  static Any to_any(const float& value) {
1227  Any ret;
1228  ret.set_float(value);
1229  return ret;
1230  }
1231 
1232  static const float& from_any(const Any& value) {
1233  assert(value.type == PropertyType::kFloat);
1234  return value.value.f;
1235  }
1236 
1237  static const float& from_any_value(const AnyValue& value) { return value.f; }
1238 };
1239 
1240 template <>
1243 
1244  static Any to_any(const LabelKey& value) {
1245  Any ret;
1246  ret.set_label_key(value);
1247  return ret;
1248  }
1249 
1250  static const LabelKey& from_any(const Any& value) {
1251  assert(value.type == PropertyType::kLabel);
1252  return value.value.label_key;
1253  }
1254 
1255  static const LabelKey& from_any_value(const AnyValue& value) {
1256  return value.label_key;
1257  }
1258 };
1259 Any ConvertStringToAny(const std::string& value, const gs::PropertyType& type);
1260 
1261 template <>
1264 
1265  static Any to_any(const RecordView& value) {
1266  Any ret;
1267  ret.set_record_view(value);
1268  return ret;
1269  }
1270 
1271  static const RecordView& from_any(const Any& value) {
1272  assert(value.type == PropertyType::kRecordView);
1273  return value.value.record_view;
1274  }
1275 
1276  static const RecordView& from_any_value(const AnyValue& value) {
1277  return value.record_view;
1278  }
1279 };
1280 
1281 template <>
1284 
1285  static Any to_any(const Record& value) {
1286  Any ret;
1287  ret.set_record(value);
1288  return ret;
1289  }
1290 
1291  static const Record& from_any(const Any& value) {
1292  assert(value.type == PropertyType::kRecord);
1293  return value.value.record;
1294  }
1295 
1296  static const Record& from_any_value(const AnyValue& value) {
1297  return value.record;
1298  }
1299 };
1300 
1301 template <typename T>
1302 T RecordView::get_field(int col_id) const {
1303  auto val = operator[](col_id);
1304  T ret{};
1305  ConvertAny<T>::to(val, ret);
1306  return ret;
1307 }
1308 
1309 grape::InArchive& operator<<(grape::InArchive& in_archive,
1310  const PropertyType& value);
1311 grape::OutArchive& operator>>(grape::OutArchive& out_archive,
1312  PropertyType& value);
1313 
1314 grape::InArchive& operator<<(grape::InArchive& in_archive, const Any& value);
1315 grape::OutArchive& operator>>(grape::OutArchive& out_archive, Any& value);
1316 
1317 grape::InArchive& operator<<(grape::InArchive& in_archive,
1318  const std::string_view& value);
1319 grape::OutArchive& operator>>(grape::OutArchive& out_archive,
1320  std::string_view& value);
1321 
1322 grape::InArchive& operator<<(grape::InArchive& in_archive,
1323  const GlobalId& value);
1324 grape::OutArchive& operator>>(grape::OutArchive& out_archive, GlobalId& value);
1325 
1326 } // namespace gs
1327 
1328 namespace boost {
1329 // override boost hash function for EmptyType
1330 inline std::size_t hash_value(const grape::EmptyType& value) { return 0; }
1331 inline std::size_t hash_value(const gs::GlobalId& value) {
1332  return std::hash<uint64_t>()(value.global_id);
1333 }
1334 // overload hash_value for LabelKey
1335 inline std::size_t hash_value(const gs::LabelKey& key) {
1336  return std::hash<int32_t>()(key.label_id);
1337 }
1338 
1339 } // namespace boost
1340 
1341 namespace std {
1342 
1343 inline ostream& operator<<(ostream& os, const gs::Date& dt) {
1344  os << dt.to_string();
1345  return os;
1346 }
1347 
1348 inline ostream& operator<<(ostream& os, const gs::Day& dt) {
1349  os << dt.to_string();
1350  return os;
1351 }
1352 
1353 inline ostream& operator<<(ostream& os, gs::PropertyType pt) {
1354  if (pt == gs::PropertyType::Bool()) {
1355  os << "bool";
1356  } else if (pt == gs::PropertyType::Empty()) {
1357  os << "empty";
1358  } else if (pt == gs::PropertyType::UInt8()) {
1359  os << "uint8";
1360  } else if (pt == gs::PropertyType::UInt16()) {
1361  os << "uint16";
1362  } else if (pt == gs::PropertyType::Int32()) {
1363  os << "int32";
1364  } else if (pt == gs::PropertyType::UInt32()) {
1365  os << "uint32";
1366  } else if (pt == gs::PropertyType::Float()) {
1367  os << "float";
1368  } else if (pt == gs::PropertyType::Int64()) {
1369  os << "int64";
1370  } else if (pt == gs::PropertyType::UInt64()) {
1371  os << "uint64";
1372  } else if (pt == gs::PropertyType::Double()) {
1373  os << "double";
1374  } else if (pt == gs::PropertyType::Date()) {
1375  os << "date";
1376  } else if (pt == gs::PropertyType::Day()) {
1377  os << "day";
1378  } else if (pt == gs::PropertyType::StringView()) {
1379  os << "string";
1380  } else if (pt == gs::PropertyType::StringMap()) {
1381  os << "string_map";
1383  os << "varchar(" << pt.additional_type_info.max_length << ")";
1384  } else if (pt == gs::PropertyType::VertexGlobalId()) {
1385  os << "vertex_global_id";
1386  } else if (pt == gs::PropertyType::Label()) {
1387  os << "label";
1388  } else if (pt == gs::PropertyType::RecordView()) {
1389  os << "record_view";
1390  } else if (pt == gs::PropertyType::Record()) {
1391  os << "record";
1392  } else {
1393  os << "unknown";
1394  }
1395  return os;
1396 }
1397 
1398 template <>
1399 struct hash<gs::GlobalId> {
1400  size_t operator()(const gs::GlobalId& value) const {
1401  return std::hash<uint64_t>()(value.global_id);
1402  }
1403 };
1404 
1405 } // namespace std
1406 
1407 namespace grape {
1408 inline bool operator==(const EmptyType& a, const EmptyType& b) { return true; }
1409 
1410 inline bool operator!=(const EmptyType& a, const EmptyType& b) { return false; }
1411 } // namespace grape
1412 
1413 namespace YAML {
1414 template <>
1415 struct convert<gs::PropertyType> {
1416  // concurrently preseve backwards compatibility with old config files
1417  static bool decode(const Node& config, gs::PropertyType& property_type) {
1418  if (config["primitive_type"]) {
1420  config["primitive_type"].as<std::string>());
1421  } else if (config["string"]) {
1422  if (config["string"].IsMap()) {
1423  if (config["string"]["long_text"]) {
1424  property_type = gs::PropertyType::StringView();
1425  } else if (config["string"]["var_char"]) {
1426  if (config["string"]["var_char"]["max_length"]) {
1427  property_type = gs::PropertyType::Varchar(
1428  config["string"]["var_char"]["max_length"].as<int32_t>());
1429  } else {
1430  property_type = gs::PropertyType::Varchar(
1432  }
1433  } else {
1434  LOG(ERROR) << "Unrecognized string type";
1435  }
1436  } else {
1437  LOG(ERROR) << "string should be a map";
1438  }
1439  } else if (config["temporal"]) {
1440  if (config["temporal"]["date32"]) {
1441  property_type = gs::PropertyType::Day();
1442  } else if (config["temporal"]["timestamp"]) {
1443  property_type = gs::PropertyType::Date();
1444  } else {
1445  LOG(ERROR) << "Unrecognized temporal type";
1446  }
1447  }
1448  // compatibility with old config files
1449  else if (config["day"]) {
1451  config["day"].as<std::string>());
1452  } else if (config["varchar"]) {
1453  if (config["varchar"]["max_length"]) {
1454  property_type = gs::PropertyType::Varchar(
1455  config["varchar"]["max_length"].as<int32_t>());
1456  } else {
1457  property_type = gs::PropertyType::Varchar(
1459  }
1460  } else if (config["date"]) {
1461  property_type = gs::PropertyType::Date();
1462  } else {
1463  LOG(ERROR) << "Unrecognized property type: " << config;
1464  return false;
1465  }
1466  return true;
1467  }
1468 
1469  static Node encode(const gs::PropertyType& type) {
1470  YAML::Node node;
1471  if (type == gs::PropertyType::Bool() || type == gs::PropertyType::Int32() ||
1472  type == gs::PropertyType::UInt32() ||
1473  type == gs::PropertyType::Float() ||
1474  type == gs::PropertyType::Int64() ||
1475  type == gs::PropertyType::UInt64() ||
1476  type == gs::PropertyType::Double()) {
1477  node["primitive_type"] =
1479  } else if (type == gs::PropertyType::StringView() ||
1480  type == gs::PropertyType::StringMap()) {
1481  node["string"]["long_text"] = "";
1482  } else if (type.IsVarchar()) {
1483  node["string"]["var_char"]["max_length"] =
1485  } else if (type == gs::PropertyType::Date()) {
1486  node["temporal"]["timestamp"] = "";
1487  } else if (type == gs::PropertyType::Day()) {
1488  node["temporal"]["date32"] = "";
1489  } else {
1490  LOG(ERROR) << "Unrecognized property type: " << type;
1491  }
1492  return node;
1493  }
1494 };
1495 } // namespace YAML
1496 
1497 #endif // GRAPHSCOPE_TYPES_H_
gs::AnyValue::db
double db
Definition: types.h:382
grape
Definition: types.h:33
gs::AnyConverter< LabelKey >::to_any
static Any to_any(const LabelKey &value)
Definition: types.h:1244
gs::AnyConverter< bool >::type
static PropertyType type()
Definition: types.h:950
gs::Day::operator==
bool operator==(const Day &rhs) const
Definition: types.h:264
gs::AnyConverter< uint16_t >::to_any
static Any to_any(const uint16_t &value)
Definition: types.h:982
gs::PropertyType::kFloat
static const PropertyType kFloat
Definition: types.h:139
gs::impl::PropertyTypeImpl::kDay
@ kDay
gs::PropertyType::UInt64
static PropertyType UInt64()
Definition: types.cc:314
gs::PropertyType::String
static PropertyType String()
Definition: types.cc:326
gs::ConvertAny< std::string >::to
static void to(const Any &value, std::string &out)
Definition: types.h:897
gs::AnyConverter< GlobalId >::type
static PropertyType type()
Definition: types.h:1074
gs::impl::PropertyTypeImpl::kUInt8
@ kUInt8
gs::Record::~Record
~Record()
Definition: types.cc:164
gs::AnyConverter< grape::EmptyType >::type
static PropertyType type()
Definition: types.h:1184
gs::DayValue::year
uint32_t year
Definition: types.h:219
gs::PropertyType::VertexGlobalId
static PropertyType VertexGlobalId()
Definition: types.cc:339
gs::AnyConverter< RecordView >::to_any
static Any to_any(const RecordView &value)
Definition: types.h:1265
gs::Any::AsBool
bool AsBool() const
Definition: types.h:638
gs::impl::PropertyTypeImpl::kEmpty
@ kEmpty
gs::AnyValue::s_ptr
StringPtr s_ptr
Definition: types.h:389
gs::impl::PropertyTypeImpl::kRecord
@ kRecord
gs::AnyConverter< Date >::from_any_value
static const Date & from_any_value(const AnyValue &value)
Definition: types.h:1113
gs::AnyConverter< Day >::to_any
static Any to_any(const Day &value)
Definition: types.h:1120
gs::Any::AsUInt64
uint64_t AsUInt64() const
Definition: types.h:623
gs::Any
Definition: types.h:395
gs::Any::operator==
bool operator==(const Any &other) const
Definition: types.h:697
gs::GlobalId::to_string
std::string to_string() const
Definition: types.cc:537
gs::PropertyType::kUInt8
static const PropertyType kUInt8
Definition: types.h:135
gs::AnyValue::l
int64_t l
Definition: types.h:374
gs::StringPtr
Definition: types.h:330
gs::ConvertAny< Date >::to
static void to(const Any &value, Date &out)
Definition: types.h:874
gs::PropertyType::Empty
static PropertyType Empty()
Definition: types.cc:290
gs::AnyConverter< double >::from_any_value
static const double & from_any_value(const AnyValue &value)
Definition: types.h:1216
gs::Any::set_vertex_gid
void set_vertex_gid(GlobalId v)
Definition: types.h:504
gs::AnyValue::record
Record record
Definition: types.h:388
gs::Day
Definition: types.h:225
gs::RecordView::to_string
std::string to_string() const
Definition: types.cc:93
gs::AnyConverter< grape::EmptyType >::from_any_value
static grape::EmptyType from_any_value(const AnyValue &value)
Definition: types.h:1196
gs::Any::set_label_key
void set_label_key(LabelKey v)
Definition: types.h:509
gs::ConvertStringToAny
Any ConvertStringToAny(const std::string &value, const gs::PropertyType &type)
Definition: types.cc:563
gs::Record::begin
Any * begin() const
Definition: types.cc:161
gs::AnyConverter< double >::to_any
static Any to_any(const double &value)
Definition: types.h:1205
gs::DayValue::month
uint32_t month
Definition: types.h:220
gs::AnyConverter< bool >::from_any
static const bool & from_any(const Any &value)
Definition: types.h:957
gs::ConvertAny< bool >::to
static void to(const Any &value, bool &out)
Definition: types.h:818
gs::ConvertAny< grape::EmptyType >::to
static void to(const Any &value, grape::EmptyType &out)
Definition: types.h:890
gs::Any::AsLabelKey
const LabelKey & AsLabelKey() const
Definition: types.h:677
gs::AnyConverter< std::string >::type
static PropertyType type()
Definition: types.h:1164
gs::PropertyType::kString
static const PropertyType kString
Definition: types.h:151
gs::Any::set_u32
void set_u32(uint32_t v)
Definition: types.h:489
gs::operator>
bool operator>(const GlobalId &lhs, const GlobalId &rhs)
Definition: types.h:196
gs::AnyConverter< Day >::from_any
static const Day & from_any(const Any &value)
Definition: types.h:1133
gs::AnyValue::i
int32_t i
Definition: types.h:371
gs::AnyConverter< std::string_view >::to_any
static Any to_any(const std::string_view &value)
Definition: types.h:1145
gs::operator<
bool operator<(const GlobalId &lhs, const GlobalId &rhs)
Definition: types.h:192
gs::AnyConverter< std::string_view >::from_any
static const std::string_view & from_any(const Any &value)
Definition: types.h:1151
gs::StringPtr::StringPtr
StringPtr(const std::string &str)
Definition: types.h:332
gs::AnyValue
Definition: types.h:366
gs::AnyConverter< float >::from_any
static const float & from_any(const Any &value)
Definition: types.h:1232
gs::DT_DOUBLE
static constexpr const char * DT_DOUBLE
Definition: types.h:52
gs::Any::From
static Any From(const T &value)
Definition: types.h:693
gs::PropertyType::Label
static PropertyType Label()
Definition: types.cc:343
gs::DT_STRING
static constexpr const char * DT_STRING
Definition: types.h:53
gs::Any::Any
Any(const std::string &str)
Definition: types.h:429
gs::ConvertAny< uint32_t >::to
static void to(const Any &value, uint32_t &out)
Definition: types.h:834
gs::AnyConverter< Date >::to_any
static Any to_any(int64_t value)
Definition: types.h:1102
gs::AnyConverter< grape::EmptyType >::from_any
static grape::EmptyType from_any(const Any &value)
Definition: types.h:1191
gs::AnyConverter< Record >::from_any
static const Record & from_any(const Any &value)
Definition: types.h:1291
gs::Any::set_i64
void set_i64(int64_t v)
Definition: types.h:494
gs::PropertyType::StringView
static PropertyType StringView()
Definition: types.cc:329
gs::AnyConverter< int32_t >::from_any_value
static const int32_t & from_any_value(const AnyValue &value)
Definition: types.h:1008
gs::operator!=
bool operator!=(const GlobalId &lhs, const GlobalId &rhs)
Definition: types.h:189
gs::PropertyType::Varchar
static PropertyType Varchar(uint16_t max_length)
Definition: types.cc:335
std::to_string
std::string to_string(const gs::flex::interactive::Code &status)
Definition: result.h:166
gs::impl::PropertyTypeImpl::kDouble
@ kDouble
gs::Day::operator<
bool operator<(const Day &rhs) const
Definition: types.h:263
gs::PropertyType::kDay
static const PropertyType kDay
Definition: types.h:144
gs::PropertyType::UInt32
static PropertyType UInt32()
Definition: types.cc:305
gs::AnyConverter< float >::type
static PropertyType type()
Definition: types.h:1224
gs::GlobalId
Definition: types.h:163
gs::PropertyType::Bool
static PropertyType Bool()
Definition: types.cc:293
gs::impl::PropertyTypeImpl::kInt64
@ kInt64
gs::GlobalId::vid_mask
static constexpr uint64_t vid_mask
Definition: types.h:168
gs::StorageStrategy::kDisk
@ kDisk
boost
Definition: types.h:1328
gs::GlobalId::vid_t
uint32_t vid_t
Definition: types.h:165
gs::Day::to_u32
uint32_t to_u32() const
Definition: types.cc:551
gs::PropertyType::kDate
static const PropertyType kDate
Definition: types.h:143
gs::LabelKey::label_data_type
uint8_t label_data_type
Definition: types.h:280
gs::DT_DATE
static constexpr const char * DT_DATE
Definition: types.h:55
gs::AnyConverter< Date >::to_any
static Any to_any(const Date &value)
Definition: types.h:1096
gs::ConvertAny::to
static void to(const Any &value, T &out)
Definition: types.h:811
gs::DT_FLOAT
static constexpr const char * DT_FLOAT
Definition: types.h:51
gs
Definition: adj_list.h:23
gs::Any::set_string
void set_string(const std::string &v)
Definition: types.h:534
gs::RecordView::offset
size_t offset
Definition: types.h:307
gs::RecordView::operator[]
Any operator[](size_t idx) const
Definition: types.cc:89
gs::AnyValue::record_view
RecordView record_view
Definition: types.h:385
gs::PropertyType::kLabel
static const PropertyType kLabel
Definition: types.h:148
gs::AnyConverter< RecordView >::from_any_value
static const RecordView & from_any_value(const AnyValue &value)
Definition: types.h:1276
gs::AnyConverter< LabelKey >::from_any
static const LabelKey & from_any(const Any &value)
Definition: types.h:1250
gs::AnyConverter< LabelKey >::from_any_value
static const LabelKey & from_any_value(const AnyValue &value)
Definition: types.h:1255
gs::DT_STRINGMAP
static constexpr const char * DT_STRINGMAP
Definition: types.h:54
gs::AnyConverter< grape::EmptyType >::to_any
static Any to_any(const grape::EmptyType &value)
Definition: types.h:1186
gs::PropertyType::kUInt64
static const PropertyType kUInt64
Definition: types.h:141
gs::impl::PropertyTypeImpl::kDate
@ kDate
YAML
Definition: types.h:1413
gs::Any::AsInt32
int32_t AsInt32() const
Definition: types.h:628
gs::PropertyType::kEmpty
static const PropertyType kEmpty
Definition: types.h:133
gs::AnyConverter< int32_t >::to_any
static Any to_any(const int32_t &value)
Definition: types.h:997
gs::StorageStrategy
StorageStrategy
Definition: types.h:58
gs::Any::AsInt64
int64_t AsInt64() const
Definition: types.h:618
gs::PropertyType::type_enum
impl::PropertyTypeImpl type_enum
Definition: types.h:97
gs::PropertyType::ToString
std::string ToString() const
Definition: types.cc:241
gs::Any::set_date
void set_date(int64_t v)
Definition: types.h:514
gs::impl::PropertyTypeImpl::kUInt32
@ kUInt32
gs::Record::operator[]
Any operator[](size_t idx) const
Definition: types.cc:154
gs::ConvertAny< int32_t >::to
static void to(const Any &value, int32_t &out)
Definition: types.h:826
gs::Any::set_u8
void set_u8(uint8_t v)
Definition: types.h:549
grape::operator==
bool operator==(const EmptyType &a, const EmptyType &b)
Definition: types.h:1408
gs::Any::set_double
void set_double(double db)
Definition: types.h:544
gs::impl::PropertyTypeImpl::kFloat
@ kFloat
gs::Any::set_bool
void set_bool(bool v)
Definition: types.h:479
gs::Table
Definition: table.h:30
gs::Any::AsUInt32
uint32_t AsUInt32() const
Definition: types.h:633
gs::ConvertAny< RecordView >::to
static void to(const Any &value, RecordView &out)
Definition: types.h:929
gs::AnyConverter< std::string >::from_any_value
static std::string & from_any_value(const AnyValue &value)
Definition: types.h:1177
gs::ConvertAny< int64_t >::to
static void to(const Any &value, int64_t &out)
Definition: types.h:842
gs::Day::to_timestamp
int64_t to_timestamp() const
Definition: types.h:236
gs::Record::len
size_t len
Definition: types.h:326
gs::AnyConverter< int32_t >::from_any
static const int32_t & from_any(const Any &value)
Definition: types.h:1003
gs::config_parsing::StringToPrimitivePropertyType
PropertyType StringToPrimitivePropertyType(const std::string &str)
Definition: types.cc:55
gs::PropertyType::Date
static PropertyType Date()
Definition: types.cc:320
gs::Record::end
Any * end() const
Definition: types.cc:162
grape::operator<
bool operator<(const EmptyType &lhs, const EmptyType &rhs)
Definition: types.h:35
gs::Record::props
Any * props
Definition: types.h:327
gs::Any::AsGlobalId
const GlobalId & AsGlobalId() const
Definition: types.h:672
gs::PropertyType::STRING_DEFAULT_MAX_LENGTH
static constexpr const uint16_t STRING_DEFAULT_MAX_LENGTH
Definition: types.h:96
gs::Any::set_i32
void set_i32(int32_t v)
Definition: types.h:484
gs::PropertyType::kStringView
static const PropertyType kStringView
Definition: types.h:145
gs::AnyConverter< uint64_t >::type
static PropertyType type()
Definition: types.h:1054
gs::AnyValue::b
bool b
Definition: types.h:370
gs::Any::AsDouble
double AsDouble() const
Definition: types.h:643
gs::AnyConverter< double >::from_any
static const double & from_any(const Any &value)
Definition: types.h:1211
gs::AnyConverter< GlobalId >::from_any_value
static const GlobalId & from_any_value(const AnyValue &value)
Definition: types.h:1087
gs::Any::Any
Any(const std::initializer_list< Any > &list)
Definition: types.h:420
gs::AnyConverter< int64_t >::from_any
static const int64_t & from_any(const Any &value)
Definition: types.h:1042
gs::PropertyType::PropertyType
constexpr PropertyType(impl::PropertyTypeImpl type, uint16_t max_length)
Definition: types.h:104
gs::AnyConverter< Record >::to_any
static Any to_any(const Record &value)
Definition: types.h:1285
gs::AnyConverter< uint32_t >::from_any
static const uint32_t & from_any(const Any &value)
Definition: types.h:1023
gs::ConvertAny< double >::to
static void to(const Any &value, double &out)
Definition: types.h:921
gs::Any::Any
Any()
Definition: types.h:396
gs::Any::Any
Any(const Any &other)
Definition: types.h:398
gs::AnyConverter< GlobalId >::from_any
static const GlobalId & from_any(const Any &value)
Definition: types.h:1082
gs::PropertyType::Int64
static PropertyType Int64()
Definition: types.cc:311
gs::GlobalId::gid_t
uint64_t gid_t
Definition: types.h:166
gs::impl::PropertyTypeImpl::kLabel
@ kLabel
gs::AnyConverter< int32_t >::type
static PropertyType type()
Definition: types.h:995
gs::Any::value
AnyValue value
Definition: types.h:806
gs::Record
Definition: types.h:312
gs::GlobalId::vid
vid_t vid() const
Definition: types.cc:533
gs::Day::day
int day() const
Definition: types.cc:559
gs::ConvertAny< float >::to
static void to(const Any &value, float &out)
Definition: types.h:913
gs::ConvertAny< Day >::to
static void to(const Any &value, Day &out)
Definition: types.h:882
gs::LabelKey::label_id
int32_t label_id
Definition: types.h:281
gs::AnyConverter< Date >::type
static PropertyType type()
Definition: types.h:1094
gs::PropertyType::kUInt32
static const PropertyType kUInt32
Definition: types.h:138
gs::AnyConverter< std::string >::from_any
static std::string & from_any(const Any &value)
Definition: types.h:1172
gs::AnyConverter< uint64_t >::to_any
static Any to_any(const uint64_t &value)
Definition: types.h:1056
gs::impl::AdditionalTypeInfo
Definition: types.h:90
gs::impl::PropertyTypeImpl::kRecordView
@ kRecordView
gs::RecordView::RecordView
RecordView()=default
gs::impl::PropertyTypeImpl
PropertyTypeImpl
Definition: types.h:66
gs::PropertyType::StringMap
static PropertyType StringMap()
Definition: types.cc:332
gs::GlobalId::global_id
uint64_t global_id
Definition: types.h:173
gs::PropertyType::PropertyType
constexpr PropertyType()
Definition: types.h:100
gs::PropertyType::operator!=
bool operator!=(const PropertyType &other) const
Definition: types.cc:233
gs::ConvertAny< Record >::to
static void to(const Any &value, Record &out)
Definition: types.h:938
gs::__attribute__
struct __attribute__((packed)) ImmutableNbr< Date >
Definition: nbr.h:54
gs::DT_UNSIGNED_INT32
static constexpr const char * DT_UNSIGNED_INT32
Definition: types.h:47
gs::PropertyType::kRecordView
static const PropertyType kRecordView
Definition: types.h:149
gs::AnyConverter< std::string_view >::from_any_value
static const std::string_view & from_any_value(const AnyValue &value)
Definition: types.h:1157
gs::AnyConverter< Date >::from_any
static const Date & from_any(const Any &value)
Definition: types.h:1108
gs::AnyConverter< int64_t >::type
static PropertyType type()
Definition: types.h:1034
gs::Any::get_long
int64_t get_long() const
Definition: types.h:475
gs::DayValue
Definition: types.h:218
gs::Any::AsRecord
const Record & AsRecord() const
Definition: types.h:687
gs::AnyConverter< std::string >::to_any
static Any to_any(const std::string &value)
Definition: types.h:1166
gs::PropertyType::kDouble
static const PropertyType kDouble
Definition: types.h:142
gs::StringPtr::StringPtr
StringPtr()
Definition: types.h:331
gs::operator<<
std::ostream & operator<<(std::ostream &os, const LoadingStatus &status)
Definition: basic_fragment_loader.cc:22
gs::Any::AsFloat
float AsFloat() const
Definition: types.h:648
gs::LabelKey
Definition: types.h:279
gs::AnyConverter< double >::type
static PropertyType type()
Definition: types.h:1203
gs::StringPtr::operator*
std::string_view operator*() const
Definition: types.h:361
gs::Any::AsDay
const Day & AsDay() const
Definition: types.h:667
gs::ConvertAny< LabelKey >::to
static void to(const Any &value, LabelKey &out)
Definition: types.h:866
gs::Any::AsString
const std::string & AsString() const
Definition: types.h:613
gs::StorageStrategy::kNone
@ kNone
gs::Any::Any
Any(const std::vector< Any > &vec)
Definition: types.h:424
gs::RecordView::table
const Table * table
Definition: types.h:308
gs::AnyConverter< bool >::to_any
static Any to_any(const bool &value)
Definition: types.h:952
gs::DT_UNSIGNED_INT64
static constexpr const char * DT_UNSIGNED_INT64
Definition: types.h:49
std::operator<<
ostream & operator<<(ostream &os, const gs::BulkLoadMethod &method)
Definition: loading_config.h:234
gs::Day::Day
Day()=default
gs::ConvertAny< uint64_t >::to
static void to(const Any &value, uint64_t &out)
Definition: types.h:850
gs::impl::PropertyTypeImpl::kBool
@ kBool
gs::AnyConverter< float >::from_any_value
static const float & from_any_value(const AnyValue &value)
Definition: types.h:1237
gs::AnyConverter< Record >::type
static PropertyType type()
Definition: types.h:1283
gs::AnyConverter< uint32_t >::to_any
static Any to_any(const uint32_t &value)
Definition: types.h:1017
gs::Day::hour
int hour() const
Definition: types.cc:561
gs::LabelKey::LabelKey
LabelKey()=default
gs::DT_UNSIGNED_INT16
static constexpr const char * DT_UNSIGNED_INT16
Definition: types.h:45
gs::DayValue::hour
uint32_t hour
Definition: types.h:222
gs::impl::PropertyTypeImpl::kStringView
@ kStringView
gs::Any::set_u64
void set_u64(uint64_t v)
Definition: types.h:499
gs::AnyConverter< uint64_t >::from_any
static const uint64_t & from_any(const Any &value)
Definition: types.h:1062
gs::Day::month
int month() const
Definition: types.cc:557
gs::Day::value
union gs::Day::@4 value
gs::impl::PropertyTypeImpl::kInt32
@ kInt32
gs::StringPtr::~StringPtr
~StringPtr()
Definition: types.h:355
gs::PropertyType::PropertyType
constexpr PropertyType(impl::PropertyTypeImpl type)
Definition: types.h:102
gs::DT_SIGNED_INT32
static constexpr const char * DT_SIGNED_INT32
Definition: types.h:46
gs::AnyConverter< int64_t >::from_any_value
static const int64_t & from_any_value(const AnyValue &value)
Definition: types.h:1047
gs::Any::Any
Any(const T &val)
Definition: types.h:435
gs::Any::set_u16
void set_u16(uint16_t v)
Definition: types.h:554
gs::GlobalId::label_id_offset
static constexpr int32_t label_id_offset
Definition: types.h:167
gs::impl::PropertyTypeImpl::kVarChar
@ kVarChar
gs::AnyValue::ui
uint32_t ui
Definition: types.h:372
gs::GlobalId::get_label_id
static label_id_t get_label_id(gid_t gid)
Definition: types.cc:513
gs::PropertyType::kInt64
static const PropertyType kInt64
Definition: types.h:140
gs::Any::operator<
bool operator<(const Any &other) const
Definition: types.h:753
gs::Any::set_float
void set_float(float v)
Definition: types.h:539
gs::Any::Any
Any(Any &&other)
Definition: types.h:409
gs::DT_UNSIGNED_INT8
static constexpr const char * DT_UNSIGNED_INT8
Definition: types.h:44
gs::AnyConverter< uint64_t >::from_any_value
static const uint64_t & from_any_value(const AnyValue &value)
Definition: types.h:1067
gs::AnyConverter< uint16_t >::type
static PropertyType type()
Definition: types.h:981
gs::AnyConverter< Day >::from_any_value
static const Day & from_any_value(const AnyValue &value)
Definition: types.h:1138
gs::AnyConverter< RecordView >::type
static PropertyType type()
Definition: types.h:1263
gs::AnyValue::~AnyValue
~AnyValue()
Definition: types.h:368
gs::DT_BOOL
static constexpr const char * DT_BOOL
Definition: types.h:50
gs::PropertyType::Day
static PropertyType Day()
Definition: types.cc:323
gs::operator==
bool operator==(const GlobalId &lhs, const GlobalId &rhs)
Definition: types.h:185
std
Definition: loading_config.h:232
gs::Any::set_record
void set_record(Record v)
Definition: types.h:564
gs::GlobalId::label_id
label_id_t label_id() const
Definition: types.cc:529
gs::Day::from_timestamp
void from_timestamp(int64_t ts)
Definition: types.h:248
gs::AnyConverter< LabelKey >::type
static PropertyType type()
Definition: types.h:1242
gs::impl::PropertyTypeImpl::kVertexGlobalId
@ kVertexGlobalId
gs::AnyConverter< bool >::from_any_value
static const bool & from_any_value(const AnyValue &value)
Definition: types.h:962
gs::AnyValue::d
Date d
Definition: types.h:379
gs::AnyValue::s
std::string_view s
Definition: types.h:381
gs::AnyConverter< Day >::type
static PropertyType type()
Definition: types.h:1118
gs::AnyValue::u16
uint16_t u16
Definition: types.h:384
gs::AnyValue::AnyValue
AnyValue()
Definition: types.h:367
gs::PropertyType::Double
static PropertyType Double()
Definition: types.cc:317
gs::Any::set_string_view
void set_string_view(std::string_view v)
Definition: types.h:529
gs::PropertyType::kRecord
static const PropertyType kRecord
Definition: types.h:150
boost::hash_value
std::size_t hash_value(const grape::EmptyType &value)
Definition: types.h:1330
gs::StringPtr::StringPtr
StringPtr(const StringPtr &other)
Definition: types.h:333
gs::ConvertAny< GlobalId >::to
static void to(const Any &value, GlobalId &out)
Definition: types.h:858
gs::DT_DAY
static constexpr const char * DT_DAY
Definition: types.h:56
std::hash< gs::GlobalId >::operator()
size_t operator()(const gs::GlobalId &value) const
Definition: types.h:1400
gs::DT_SIGNED_INT64
static constexpr const char * DT_SIGNED_INT64
Definition: types.h:48
gs::impl::PropertyTypeImpl::kUInt64
@ kUInt64
gs::Day::to_string
std::string to_string() const
Definition: types.cc:545
gs::Record::operator=
Record & operator=(const Record &other)
Definition: types.cc:122
gs::PropertyType::kBool
static const PropertyType kBool
Definition: types.h:134
gs::Record::Record
Record()
Definition: types.h:313
gs::RecordView::size
size_t size() const
Definition: types.cc:87
gs::Any::set_record_view
void set_record_view(RecordView v)
Definition: types.h:559
grape::operator!=
bool operator!=(const EmptyType &a, const EmptyType &b)
Definition: types.h:1410
gs::ConvertAny
Definition: types.h:810
gs::AnyConverter
Definition: types.h:393
gs::AnyConverter< uint8_t >::from_any
static const uint8_t & from_any(const Any &value)
Definition: types.h:973
gs::AnyValue::u8
uint8_t u8
Definition: types.h:383
gs::PropertyType::Record
static PropertyType Record()
Definition: types.cc:351
gs::Any::set_day
void set_day(Day v)
Definition: types.h:524
gs::Any::type
PropertyType type
Definition: types.h:805
gs::DayValue::day
uint32_t day
Definition: types.h:221
gs::AnyValue::f
float f
Definition: types.h:373
gs::impl::PropertyTypeImpl::kString
@ kString
gs::StringPtr::operator=
StringPtr & operator=(const StringPtr &other)
Definition: types.h:341
gs::Any::set_date
void set_date(Date v)
Definition: types.h:519
gs::Day::integer
uint32_t integer
Definition: types.h:275
gs::AnyConverter< Day >::to_any
static Any to_any(int64_t value)
Definition: types.h:1126
gs::RecordView::operator==
bool operator==(const RecordView &other) const
Definition: types.h:298
gs::AnyConverter< Record >::from_any_value
static const Record & from_any_value(const AnyValue &value)
Definition: types.h:1296
gs::PropertyType::IsVarchar
bool IsVarchar() const
Definition: types.cc:237
gs::PropertyType::operator==
bool operator==(const PropertyType &other) const
Definition: types.cc:210
gs::AnyValue::ul
uint64_t ul
Definition: types.h:375
gs::Day::from_u32
void from_u32(uint32_t val)
Definition: types.cc:553
gs::GlobalId::GlobalId
GlobalId()
Definition: types.cc:521
gs::config_parsing::PrimitivePropertyTypeToString
std::string PrimitivePropertyTypeToString(PropertyType type)
Definition: types.cc:25
gs::PropertyType::UInt8
static PropertyType UInt8()
Definition: types.cc:296
gs::GlobalId::label_id_t
uint8_t label_id_t
Definition: types.h:164
gs::ConvertAny< std::string_view >::to
static void to(const Any &value, std::string_view &out)
Definition: types.h:905
gs::Any::~Any
~Any()
Definition: types.h:467
gs::impl::PropertyTypeImpl::kStringMap
@ kStringMap
gs::AnyConverter< RecordView >::from_any
static const RecordView & from_any(const Any &value)
Definition: types.h:1271
gs::PropertyType::additional_type_info
impl::AdditionalTypeInfo additional_type_info
Definition: types.h:98
gs::AnyConverter< uint8_t >::to_any
static Any to_any(const uint8_t &value)
Definition: types.h:968
gs::PropertyType::Int32
static PropertyType Int32()
Definition: types.cc:302
gs::PropertyType
Definition: types.h:95
gs::impl::PropertyTypeImpl::kUInt16
@ kUInt16
gs::RecordView
Definition: types.h:288
gs::RecordView::RecordView
RecordView(size_t offset, const Table *table)
Definition: types.h:290
gs::Any::operator=
Any & operator=(const Any &other)
Definition: types.h:448
gs::impl::AdditionalTypeInfo::max_length
uint16_t max_length
Definition: types.h:91
gs::StringPtr::ptr
std::string * ptr
Definition: types.h:364
gs::Day::year
int year() const
Definition: types.cc:555
gs::AnyValue::label_key
LabelKey label_key
Definition: types.h:377
gs::GlobalId::get_vid
static vid_t get_vid(gid_t gid)
Definition: types.cc:517
YAML::convert< gs::PropertyType >::encode
static Node encode(const gs::PropertyType &type)
Definition: types.h:1469
gs::AnyConverter< float >::to_any
static Any to_any(const float &value)
Definition: types.h:1226
gs::Any::to_string
std::string to_string() const
Definition: types.h:572
gs::PropertyType::kStringMap
static const PropertyType kStringMap
Definition: types.h:146
gs::PropertyType::RecordView
static PropertyType RecordView()
Definition: types.cc:347
gs::PropertyType::kVertexGlobalId
static const PropertyType kVertexGlobalId
Definition: types.h:147
gs::PropertyType::UInt16
static PropertyType UInt16()
Definition: types.cc:299
gs::AnyConverter< int64_t >::to_any
static Any to_any(const int64_t &value)
Definition: types.h:1036
gs::StringPtr::StringPtr
StringPtr(StringPtr &&other)
Definition: types.h:340
gs::PropertyType::Float
static PropertyType Float()
Definition: types.cc:308
gs::operator>>
std::istream & operator>>(std::istream &is, LoadingStatus &status)
Definition: basic_fragment_loader.cc:35
gs::AnyValue::day
Day day
Definition: types.h:380
YAML::convert< gs::PropertyType >::decode
static bool decode(const Node &config, gs::PropertyType &property_type)
Definition: types.h:1417
gs::AnyConverter< uint16_t >::from_any
static const uint16_t & from_any(const Any &value)
Definition: types.h:987
gs::AnyConverter< uint8_t >::type
static PropertyType type()
Definition: types.h:967
gs::PropertyType::kInt32
static const PropertyType kInt32
Definition: types.h:137
gs::StorageStrategy::kMem
@ kMem
gs::Any::AsStringView
std::string_view AsStringView() const
Definition: types.h:653
gs::AnyConverter< uint32_t >::type
static PropertyType type()
Definition: types.h:1015
gs::Day::~Day
~Day()=default
gs::AnyConverter< std::string_view >::type
static PropertyType type()
Definition: types.h:1143
gs::AnyValue::vertex_gid
GlobalId vertex_gid
Definition: types.h:376
gs::Any::AsRecordView
const RecordView & AsRecordView() const
Definition: types.h:682
gs::PropertyType::kUInt16
static const PropertyType kUInt16
Definition: types.h:136
gs::RecordView::get_field
T get_field(int col_id) const
Definition: types.h:1302
gs::LabelKey::LabelKey
LabelKey(label_data_type id)
Definition: types.h:283
gs::AnyConverter< uint32_t >::from_any_value
static const uint32_t & from_any_value(const AnyValue &value)
Definition: types.h:1028
gs::AnyConverter< GlobalId >::to_any
static Any to_any(const GlobalId &value)
Definition: types.h:1076
gs::Record::size
size_t size() const
Definition: types.h:321
gs::Any::AsDate
const Date & AsDate() const
Definition: types.h:662