Kùzu C++ API
Loading...
Searching...
No Matches
value.h
Go to the documentation of this file.
1#pragma once
2
3#include <utility>
4
5#include "api.h"
6#include "date_t.h"
7#include "int128_t.h"
8#include "interval_t.h"
9#include "ku_list.h"
10#include "timestamp_t.h"
11#include "uuid.h"
12
13namespace kuzu {
14namespace common {
15
16class NodeVal;
17class RelVal;
18struct FileInfo;
19class NestedVal;
20class RecursiveRelVal;
21class ArrowRowBatch;
22class ValueVector;
23class Serializer;
24class Deserializer;
25
26class Value {
27 friend class NodeVal;
28 friend class RelVal;
29 friend class NestedVal;
30 friend class RecursiveRelVal;
31 friend class ArrowRowBatch;
32 friend class ValueVector;
33
34public:
43 KUZU_API static Value createNullValue(const LogicalType& dataType);
52 KUZU_API explicit Value(bool val_);
56 KUZU_API explicit Value(int8_t val_);
60 KUZU_API explicit Value(int16_t val_);
64 KUZU_API explicit Value(int32_t val_);
68 KUZU_API explicit Value(int64_t val_);
72 KUZU_API explicit Value(uint8_t val_);
76 KUZU_API explicit Value(uint16_t val_);
80 KUZU_API explicit Value(uint32_t val_);
84 KUZU_API explicit Value(uint64_t val_);
88 KUZU_API explicit Value(int128_t val_);
92 KUZU_API explicit Value(ku_uuid_t val_);
96 KUZU_API explicit Value(double val_);
100 KUZU_API explicit Value(float val_);
104 KUZU_API explicit Value(date_t val_);
124 KUZU_API explicit Value(timestamp_t val_);
128 KUZU_API explicit Value(interval_t val_);
136 KUZU_API explicit Value(const char* val_);
140 KUZU_API explicit Value(const std::string& val_);
144 KUZU_API explicit Value(uint8_t* val_);
149 KUZU_API explicit Value(LogicalType type, std::string val_);
154 KUZU_API explicit Value(LogicalType dataType, std::vector<std::unique_ptr<Value>> children);
158 KUZU_API Value(const Value& other);
159
163 KUZU_API Value(Value&& other) = default;
164 KUZU_API Value& operator=(Value&& other) = default;
165 KUZU_API bool operator==(const Value& rhs) const;
166
171 KUZU_API void setDataType(const LogicalType& dataType_);
180 KUZU_API void setNull(bool flag);
188 KUZU_API bool isNull() const;
193 KUZU_API void copyFromRowLayout(const uint8_t* value);
198 KUZU_API void copyFromColLayout(const uint8_t* value, ValueVector* vec = nullptr);
203 KUZU_API void copyValueFrom(const Value& other);
207 template<class T>
208 T getValue() const {
209 throw std::runtime_error("Unimplemented template for Value::getValue()");
210 }
214 template<class T>
216 throw std::runtime_error("Unimplemented template for Value::getValueReference()");
217 }
221 template<class T>
222 static Value createValue(T /*value*/) {
223 throw std::runtime_error("Unimplemented template for Value::createValue()");
224 }
225
229 KUZU_API std::unique_ptr<Value> copy() const;
233 KUZU_API std::string toString() const;
234
235 KUZU_API void serialize(Serializer& serializer) const;
236
237 KUZU_API static std::unique_ptr<Value> deserialize(Deserializer& deserializer);
238
240
242 bool allowTypeChange() const;
243
244 uint64_t computeHash() const;
245
246 KUZU_API uint32_t getChildrenSize() const { return childrenSize; }
247
248private:
249 Value();
250 explicit Value(const LogicalType& dataType);
251
252 void resizeChildrenVector(uint64_t size, const LogicalType& childType);
253 void copyFromRowLayoutList(const ku_list_t& list, const LogicalType& childType);
254 void copyFromColLayoutList(const list_entry_t& list, ValueVector* vec);
255 void copyFromRowLayoutStruct(const uint8_t* kuStruct);
256 void copyFromColLayoutStruct(const struct_entry_t& structEntry, ValueVector* vec);
257 void copyFromUnion(const uint8_t* kuUnion);
258
259 std::string mapToString() const;
260 std::string listToString() const;
261 std::string structToString() const;
262 std::string nodeToString() const;
263 std::string relToString() const;
264 std::string decimalToString() const;
265
266public:
267 union Val {
268 constexpr Val() : booleanVal{false} {}
271 int64_t int64Val;
272 int32_t int32Val;
273 int16_t int16Val;
274 int8_t int8Val;
275 uint64_t uint64Val;
276 uint32_t uint32Val;
277 uint16_t uint16Val;
278 uint8_t uint8Val;
279 double doubleVal;
280 float floatVal;
281 // TODO(Ziyi): Should we remove the val suffix from all values in Val? Looks redundant.
282 uint8_t* pointer;
286 std::string strVal;
287
288private:
289 LogicalType dataType;
290 bool isNull_;
291
292 // Note: ALWAYS use childrenSize over children.size(). We do NOT resize children when
293 // iterating with nested value. So children.size() reflects the capacity() rather the actual
294 // size.
295 std::vector<std::unique_ptr<Value>> children;
296 uint32_t childrenSize;
297};
298
302template<>
303KUZU_API inline bool Value::getValue() const {
305 return val.booleanVal;
306}
307
311template<>
312KUZU_API inline int8_t Value::getValue() const {
314 return val.int8Val;
315}
316
320template<>
321KUZU_API inline int16_t Value::getValue() const {
323 return val.int16Val;
324}
325
329template<>
330KUZU_API inline int32_t Value::getValue() const {
332 return val.int32Val;
333}
334
338template<>
339KUZU_API inline int64_t Value::getValue() const {
341 return val.int64Val;
342}
343
347template<>
348KUZU_API inline uint64_t Value::getValue() const {
350 return val.uint64Val;
351}
352
356template<>
357KUZU_API inline uint32_t Value::getValue() const {
359 return val.uint32Val;
360}
361
365template<>
366KUZU_API inline uint16_t Value::getValue() const {
368 return val.uint16Val;
369}
370
374template<>
375KUZU_API inline uint8_t Value::getValue() const {
377 return val.uint8Val;
378}
379
383template<>
386 return val.int128Val;
387}
388
392template<>
393KUZU_API inline float Value::getValue() const {
395 return val.floatVal;
396}
397
401template<>
402KUZU_API inline double Value::getValue() const {
404 return val.doubleVal;
405}
406
410template<>
413 return date_t{val.int32Val};
414}
415
419template<>
424
428template<>
433
437template<>
442
446template<>
451
455template<>
460
464template<>
469
473template<>
478
482template<>
483KUZU_API inline std::string Value::getValue() const {
487 return strVal;
488}
489
493template<>
494KUZU_API inline uint8_t* Value::getValue() const {
496 return val.pointer;
497}
498
502template<>
507
511template<>
514 return val.int8Val;
515}
516
520template<>
523 return val.int16Val;
524}
525
529template<>
532 return val.int32Val;
533}
534
538template<>
541 return val.int64Val;
542}
543
547template<>
550 return val.uint8Val;
551}
552
556template<>
559 return val.uint16Val;
560}
561
565template<>
568 return val.uint32Val;
569}
570
574template<>
577 return val.uint64Val;
578}
579
583template<>
588
592template<>
595 return val.floatVal;
596}
597
601template<>
604 return val.doubleVal;
605}
606
610template<>
613 return *reinterpret_cast<date_t*>(&val.int32Val);
614}
615
619template<>
622 return *reinterpret_cast<timestamp_t*>(&val.int64Val);
623}
624
628template<>
633
637template<>
642
646template<>
651
655template<>
660
664template<>
669
673template<>
678
682template<>
683KUZU_API inline std::string& Value::getValueReference() {
685 return strVal;
686}
687
691template<>
694 return val.pointer;
695}
696
701template<>
703 return Value(val);
704}
705
706template<>
708 return Value(val);
709}
710
715template<>
716KUZU_API inline Value Value::createValue(int16_t val) {
717 return Value(val);
718}
719
724template<>
725KUZU_API inline Value Value::createValue(int32_t val) {
726 return Value(val);
727}
728
733template<>
734KUZU_API inline Value Value::createValue(int64_t val) {
735 return Value(val);
736}
737
742template<>
743KUZU_API inline Value Value::createValue(uint8_t val) {
744 return Value(val);
745}
746
751template<>
752KUZU_API inline Value Value::createValue(uint16_t val) {
753 return Value(val);
754}
755
760template<>
761KUZU_API inline Value Value::createValue(uint32_t val) {
762 return Value(val);
763}
764
769template<>
770KUZU_API inline Value Value::createValue(uint64_t val) {
771 return Value(val);
772}
773
778template<>
780 return Value(val);
781}
782
787template<>
789 return Value(val);
790}
791
796template<>
798 return Value(val);
799}
800
805template<>
807 return Value(val);
808}
809
814template<>
816 return Value(val);
817}
818
823template<>
825 return Value(val);
826}
827
832template<>
833KUZU_API inline Value Value::createValue(std::string val) {
834 return Value(LogicalType::STRING(), std::move(val));
835}
836
841template<>
842KUZU_API inline Value Value::createValue(const char* value) {
843 return Value(LogicalType::STRING(), std::string(value));
844}
845
850template<>
851KUZU_API inline Value Value::createValue(uint8_t* val) {
852 return Value(val);
853}
854
855} // namespace common
856} // namespace kuzu
#define KUZU_API
Definition api.h:25
#define KU_ASSERT(condition)
Definition assert.h:19
Definition types.h:249
KUZU_API LogicalTypeID getLogicalTypeID() const
Definition types.h:272
static LogicalType STRING()
Definition types.h:327
KUZU_API PhysicalTypeID getPhysicalType() const
Definition types.h:276
Definition nested.h:12
NodeVal represents a node in the graph and stores the nodeID, label and properties of that node.
Definition node.h:20
RecursiveRelVal represents a path in the graph and stores the corresponding rels and nodes of that pa...
Definition recursive_rel.h:14
RelVal represents a rel in the graph and stores the relID, src/dst nodes and properties of that rel.
Definition rel.h:20
Definition value.h:26
KUZU_API Value(const char *val_)
KUZU_API Value(date_t val_)
KUZU_API Value(float val_)
KUZU_API void serialize(Serializer &serializer) const
KUZU_API Value(timestamp_t val_)
static KUZU_API Value createNullValue()
KUZU_API Value(uint16_t val_)
KUZU_API Value(int8_t val_)
friend class ArrowRowBatch
Definition value.h:31
KUZU_API Value(Value &&other)=default
KUZU_API Value(timestamp_sec_t val_)
KUZU_API Value(uint8_t val_)
KUZU_API Value(internalID_t val_)
KUZU_API Value(timestamp_ms_t val_)
KUZU_API void setNull(bool flag)
Sets the null flag of the Value.
KUZU_API Value(uint8_t *val_)
bool hasNoneNullChildren() const
static KUZU_API Value createDefaultValue(const LogicalType &dataType)
std::string strVal
Definition value.h:286
KUZU_API const LogicalType & getDataType() const
union kuzu::common::Value::Val val
KUZU_API Value & operator=(Value &&other)=default
KUZU_API Value(LogicalType type, std::string val_)
KUZU_API Value(timestamp_tz_t val_)
KUZU_API Value(int16_t val_)
KUZU_API std::string toString() const
KUZU_API void copyFromColLayout(const uint8_t *value, ValueVector *vec=nullptr)
Copies from the col layout value.
KUZU_API Value(int64_t val_)
T getValue() const
Definition value.h:208
KUZU_API void setDataType(const LogicalType &dataType_)
Sets the data type of the Value.
KUZU_API void copyValueFrom(const Value &other)
Copies from the other.
KUZU_API std::unique_ptr< Value > copy() const
KUZU_API Value(LogicalType dataType, std::vector< std::unique_ptr< Value > > children)
KUZU_API Value(uint64_t val_)
KUZU_API void setNull()
Sets the null flag of the Value to true.
uint64_t computeHash() const
KUZU_API bool isNull() const
KUZU_API Value(ku_uuid_t val_)
KUZU_API bool operator==(const Value &rhs) const
bool allowTypeChange() const
KUZU_API uint32_t getChildrenSize() const
Definition value.h:246
KUZU_API Value(bool val_)
KUZU_API Value(const Value &other)
KUZU_API Value(int32_t val_)
KUZU_API Value(const std::string &val_)
static KUZU_API std::unique_ptr< Value > deserialize(Deserializer &deserializer)
T & getValueReference()
Definition value.h:215
KUZU_API Value(int128_t val_)
static KUZU_API Value createNullValue(const LogicalType &dataType)
static Value createValue(T)
Definition value.h:222
KUZU_API Value(interval_t val_)
KUZU_API Value(uint32_t val_)
KUZU_API void copyFromRowLayout(const uint8_t *value)
Copies from the row layout value.
KUZU_API Value(double val_)
KUZU_API Value(timestamp_ns_t val_)
KUZU_API void validateType(common::LogicalTypeID targetTypeID) const
Definition value_vector.h:21
LogicalTypeID
Definition types.h:170
Definition array_utils.h:7
Definition date_t.h:16
Definition int128_t.h:20
Definition types.h:87
Definition interval_t.h:35
Definition ku_list.h:8
Definition uuid.h:16
Definition types.h:111
Definition types.h:119
Definition timestamp_t.h:49
Definition timestamp_t.h:46
Definition timestamp_t.h:52
Definition timestamp_t.h:10
Definition timestamp_t.h:43
Definition value.h:267
int32_t int32Val
Definition value.h:272
int8_t int8Val
Definition value.h:274
uint8_t uint8Val
Definition value.h:278
uint8_t * pointer
Definition value.h:282
uint32_t uint32Val
Definition value.h:276
bool booleanVal
Definition value.h:269
uint16_t uint16Val
Definition value.h:277
int16_t int16Val
Definition value.h:273
internalID_t internalIDVal
Definition value.h:284
int64_t int64Val
Definition value.h:271
interval_t intervalVal
Definition value.h:283
double doubleVal
Definition value.h:279
int128_t int128Val
Definition value.h:270
float floatVal
Definition value.h:280
constexpr Val()
Definition value.h:268
uint64_t uint64Val
Definition value.h:275