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