MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / copyFromUnion

Method copyFromUnion

src/common/types/value/value.cpp:754–781  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

752}
753
754void Value::copyFromUnion(const uint8_t* unionValue) {
755 auto childrenTypes = StructType::getFieldTypes(dataType);
756 auto unionNullValues = unionValue;
757 auto unionValues = unionNullValues + NullBuffer::getNumBytesForNullValues(childrenTypes.size());
758 // For union dataType, only one member can be active at a time. So we don't need to copy all
759 // union fields into value.
760 auto activeFieldIdx = UnionType::getInternalFieldIdx(*(union_field_idx_t*)unionValues);
761 // Create default value now that we know the active field
762 auto childValue = Value::createDefaultValue(*childrenTypes[activeFieldIdx]);
763 auto curMemberIdx = 0u;
764 // Seek to the current active member value.
765 while (curMemberIdx < activeFieldIdx) {
766 unionValues += storage::StorageUtils::getDataTypeSize(*childrenTypes[curMemberIdx]);
767 curMemberIdx++;
768 }
769 if (NullBuffer::isNull(unionNullValues, activeFieldIdx)) {
770 childValue.setNull(true);
771 } else {
772 childValue.setNull(false);
773 childValue.copyFromRowLayout(unionValues);
774 }
775 if (children.empty()) {
776 children.push_back(std::make_unique<Value>(std::move(childValue)));
777 childrenSize = 1;
778 } else {
779 children[0] = std::make_unique<Value>(std::move(childValue));
780 }
781}
782
783void Value::serialize(Serializer& serializer) const {
784 dataType.serialize(serializer);

Callers

nothing calls this directly

Calls 6

copyFromRowLayoutMethod · 0.80
isNullFunction · 0.50
sizeMethod · 0.45
setNullMethod · 0.45
emptyMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected