| 752 | } |
| 753 | |
| 754 | void 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 | |
| 783 | void Value::serialize(Serializer& serializer) const { |
| 784 | dataType.serialize(serializer); |