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 "internal_id_t.h"
9#include "interval_t.h"
10#include "ku_list.h"
11#include "timestamp_t.h"
12#include "uuid.h"
13
14namespace kuzu {
15namespace common {
16
17class NodeVal;
18class RelVal;
19struct FileInfo;
20class NestedVal;
21class RecursiveRelVal;
22class ArrowRowBatch;
23class ValueVector;
24class Serializer;
25class Deserializer;
26
27class Value {
28 friend class NodeVal;
29 friend class RelVal;
30 friend class NestedVal;
31 friend class RecursiveRelVal;
32 friend class ArrowRowBatch;
33 friend class ValueVector;
34
35public:
44 KUZU_API static Value createNullValue(const LogicalType& dataType);
53 KUZU_API explicit Value(bool val_);
57 KUZU_API explicit Value(int8_t val_);
61 KUZU_API explicit Value(int16_t val_);
65 KUZU_API explicit Value(int32_t val_);
69 KUZU_API explicit Value(int64_t val_);
73 KUZU_API explicit Value(uint8_t val_);
77 KUZU_API explicit Value(uint16_t val_);
81 KUZU_API explicit Value(uint32_t val_);
85 KUZU_API explicit Value(uint64_t val_);
89 KUZU_API explicit Value(int128_t val_);
93 KUZU_API explicit Value(ku_uuid_t val_);
97 KUZU_API explicit Value(double val_);
101 KUZU_API explicit Value(float val_);
105 KUZU_API explicit Value(date_t val_);
125 KUZU_API explicit Value(timestamp_t val_);
129 KUZU_API explicit Value(interval_t val_);
137 KUZU_API explicit Value(const char* val_);
141 KUZU_API explicit Value(const std::string& val_);
145 KUZU_API explicit Value(uint8_t* val_);
150 KUZU_API explicit Value(LogicalType type, std::string val_);
155 KUZU_API explicit Value(LogicalType dataType, std::vector<std::unique_ptr<Value>> children);
159 KUZU_API Value(const Value& other);
160
164 KUZU_API Value(Value&& other) = default;
165 KUZU_API Value& operator=(Value&& other) = default;
166 KUZU_API bool operator==(const Value& rhs) const;
167
172 KUZU_API void setDataType(const LogicalType& dataType_);
181 KUZU_API void setNull(bool flag);
189 KUZU_API bool isNull() const;
194 KUZU_API void copyFromRowLayout(const uint8_t* value);
199 KUZU_API void copyFromColLayout(const uint8_t* value, ValueVector* vec = nullptr);
204 KUZU_API void copyValueFrom(const Value& other);
208 template<class T>
209 T getValue() const {
210 throw std::runtime_error("Unimplemented template for Value::getValue()");
211 }
215 template<class T>
217 throw std::runtime_error("Unimplemented template for Value::getValueReference()");
218 }
222 template<class T>
223 static Value createValue(T /*value*/) {
224 throw std::runtime_error("Unimplemented template for Value::createValue()");
225 }
226
230 KUZU_API std::unique_ptr<Value> copy() const;
234 KUZU_API std::string toString() const;
235
236 KUZU_API void serialize(Serializer& serializer) const;
237
238 KUZU_API static std::unique_ptr<Value> deserialize(Deserializer& deserializer);
239
240 void validateType(common::LogicalTypeID targetTypeID) const;
241
243 bool allowTypeChange() const;
244
245 uint64_t computeHash() const;
246
247 KUZU_API uint32_t getChildrenSize() const { return childrenSize; }
248
249private:
250 Value();
251 explicit Value(const LogicalType& dataType);
252
253 void resizeChildrenVector(uint64_t size, const LogicalType& childType);
254 void copyFromRowLayoutList(const ku_list_t& list, const LogicalType& childType);
255 void copyFromColLayoutList(const list_entry_t& list, ValueVector* vec);
256 void copyFromRowLayoutStruct(const uint8_t* kuStruct);
257 void copyFromColLayoutStruct(const struct_entry_t& structEntry, ValueVector* vec);
258 void copyFromUnion(const uint8_t* kuUnion);
259
260 std::string rdfVariantToString() const;
261 std::string mapToString() const;
262 std::string listToString() const;
263 std::string structToString() const;
264 std::string nodeToString() const;
265 std::string relToString() const;
266 std::string decimalToString() const;
267
268public:
269 union Val {
270 constexpr Val() : booleanVal{false} {}
273 int64_t int64Val;
274 int32_t int32Val;
275 int16_t int16Val;
276 int8_t int8Val;
277 uint64_t uint64Val;
278 uint32_t uint32Val;
279 uint16_t uint16Val;
280 uint8_t uint8Val;
281 double doubleVal;
282 float floatVal;
283 // TODO(Ziyi): Should we remove the val suffix from all values in Val? Looks redundant.
284 uint8_t* pointer;
288 std::string strVal;
289
290private:
291 LogicalType dataType;
292 bool isNull_;
293
294 // Note: ALWAYS use childrenSize over children.size(). We do NOT resize children when
295 // iterating with nested value. So children.size() reflects the capacity() rather the actual
296 // size.
297 std::vector<std::unique_ptr<Value>> children;
298 uint32_t childrenSize;
299};
300
304template<>
305KUZU_API inline bool Value::getValue() const {
307 return val.booleanVal;
308}
309
313template<>
314KUZU_API inline int8_t Value::getValue() const {
316 return val.int8Val;
317}
318
322template<>
323KUZU_API inline int16_t Value::getValue() const {
325 return val.int16Val;
326}
327
331template<>
332KUZU_API inline int32_t Value::getValue() const {
334 return val.int32Val;
335}
336
340template<>
341KUZU_API inline int64_t Value::getValue() const {
343 return val.int64Val;
344}
345
349template<>
350KUZU_API inline uint64_t Value::getValue() const {
352 return val.uint64Val;
353}
354
358template<>
359KUZU_API inline uint32_t Value::getValue() const {
361 return val.uint32Val;
362}
363
367template<>
368KUZU_API inline uint16_t Value::getValue() const {
370 return val.uint16Val;
371}
372
376template<>
377KUZU_API inline uint8_t Value::getValue() const {
379 return val.uint8Val;
380}
381
385template<>
388 return val.int128Val;
389}
390
394template<>
395KUZU_API inline float Value::getValue() const {
397 return val.floatVal;
398}
399
403template<>
404KUZU_API inline double Value::getValue() const {
406 return val.doubleVal;
407}
408
412template<>
415 return date_t{val.int32Val};
416}
417
421template<>
426
430template<>
435
439template<>
444
448template<>
453
457template<>
462
466template<>
471
475template<>
480
484template<>
485KUZU_API inline std::string Value::getValue() const {
489 return strVal;
490}
491
495template<>
496KUZU_API inline uint8_t* Value::getValue() const {
498 return val.pointer;
499}
500
504template<>
509
513template<>
516 return val.int8Val;
517}
518
522template<>
525 return val.int16Val;
526}
527
531template<>
534 return val.int32Val;
535}
536
540template<>
543 return val.int64Val;
544}
545
549template<>
552 return val.uint8Val;
553}
554
558template<>
561 return val.uint16Val;
562}
563
567template<>
570 return val.uint32Val;
571}
572
576template<>
579 return val.uint64Val;
580}
581
585template<>
590
594template<>
597 return val.floatVal;
598}
599
603template<>
606 return val.doubleVal;
607}
608
612template<>
615 return *reinterpret_cast<date_t*>(&val.int32Val);
616}
617
621template<>
624 return *reinterpret_cast<timestamp_t*>(&val.int64Val);
625}
626
630template<>
635
639template<>
644
648template<>
653
657template<>
662
666template<>
671
675template<>
680
684template<>
685KUZU_API inline std::string& Value::getValueReference() {
687 return strVal;
688}
689
693template<>
696 return val.pointer;
697}
698
703template<>
705 return Value(val);
706}
707
708template<>
710 return Value(val);
711}
712
717template<>
718KUZU_API inline Value Value::createValue(int16_t val) {
719 return Value(val);
720}
721
726template<>
727KUZU_API inline Value Value::createValue(int32_t val) {
728 return Value(val);
729}
730
735template<>
736KUZU_API inline Value Value::createValue(int64_t val) {
737 return Value(val);
738}
739
744template<>
745KUZU_API inline Value Value::createValue(uint8_t val) {
746 return Value(val);
747}
748
753template<>
754KUZU_API inline Value Value::createValue(uint16_t val) {
755 return Value(val);
756}
757
762template<>
763KUZU_API inline Value Value::createValue(uint32_t val) {
764 return Value(val);
765}
766
771template<>
772KUZU_API inline Value Value::createValue(uint64_t val) {
773 return Value(val);
774}
775
780template<>
782 return Value(val);
783}
784
789template<>
791 return Value(val);
792}
793
798template<>
800 return Value(val);
801}
802
807template<>
809 return Value(val);
810}
811
816template<>
818 return Value(val);
819}
820
825template<>
827 return Value(val);
828}
829
834template<>
835KUZU_API inline Value Value::createValue(std::string val) {
836 return Value(LogicalType::STRING(), std::move(val));
837}
838
843template<>
844KUZU_API inline Value Value::createValue(const char* value) {
845 return Value(LogicalType::STRING(), std::string(value));
846}
847
852template<>
853KUZU_API inline Value Value::createValue(uint8_t* val) {
854 return Value(val);
855}
856
857} // namespace common
858} // namespace kuzu
#define KUZU_API
Definition api.h:25
#define KU_ASSERT(condition)
Definition assert.h:19
Definition deserializer.h:15
Definition types.h:201
KUZU_API LogicalTypeID getLogicalTypeID() const
Definition types.h:224
static LogicalType STRING()
Definition types.h:266
KUZU_API PhysicalTypeID getPhysicalType() const
Definition types.h:227
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 serializer.h:15
Definition value.h:27
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:32
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:288
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:209
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:247
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:216
KUZU_API Value(int128_t val_)
static KUZU_API Value createNullValue(const LogicalType &dataType)
static Value createValue(T)
Definition value.h:223
KUZU_API Value(interval_t val_)
void validateType(common::LogicalTypeID targetTypeID) const
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_)
Definition value_vector.h:20
LogicalTypeID
Definition types.h:126
Definition alter_type.h:5
Definition date_t.h:11
Definition int128_t.h:20
Definition internal_id_t.h:31
Definition interval_t.h:30
Definition ku_list.h:8
Definition uuid.h:11
Definition types.h:70
Definition types.h:78
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:269
int32_t int32Val
Definition value.h:274
int8_t int8Val
Definition value.h:276
uint8_t uint8Val
Definition value.h:280
uint8_t * pointer
Definition value.h:284
uint32_t uint32Val
Definition value.h:278
bool booleanVal
Definition value.h:271
uint16_t uint16Val
Definition value.h:279
int16_t int16Val
Definition value.h:275
internalID_t internalIDVal
Definition value.h:286
int64_t int64Val
Definition value.h:273
interval_t intervalVal
Definition value.h:285
double doubleVal
Definition value.h:281
int128_t int128Val
Definition value.h:272
float floatVal
Definition value.h:282
constexpr Val()
Definition value.h:270
uint64_t uint64Val
Definition value.h:277