@@ -172,13 +172,12 @@ Value Value::createDefaultValue(const LogicalType& dataType) {
172
172
return Value (dataType.copy (), std::move (children));
173
173
}
174
174
case LogicalTypeID::MAP:
175
- case LogicalTypeID::LIST: {
176
- return Value (dataType.copy (), std::vector<std::unique_ptr<Value>>{});
177
- }
175
+ case LogicalTypeID::LIST:
178
176
case LogicalTypeID::UNION: {
179
- std::vector<std::unique_ptr<Value>> children;
180
- children.push_back (std::make_unique<Value>(createNullValue ()));
181
- return Value (dataType.copy (), std::move (children));
177
+ // We can't create a default value for the union since the
178
+ // selected variant is runtime information. Default value
179
+ // is initialized when copying (see Value::copyFromUnion).
180
+ return Value (dataType.copy (), std::vector<std::unique_ptr<Value>>{});
182
181
}
183
182
case LogicalTypeID::NODE:
184
183
case LogicalTypeID::REL:
@@ -732,19 +731,25 @@ void Value::copyFromUnion(const uint8_t* kuUnion) {
732
731
// For union dataType, only one member can be active at a time. So we don't need to copy all
733
732
// union fields into value.
734
733
auto activeFieldIdx = UnionType::getInternalFieldIdx (*(union_field_idx_t *)unionValues);
735
- auto childValue = children[ 0 ]. get ();
736
- childValue-> dataType = childrenTypes[activeFieldIdx]-> copy ( );
734
+ // Create default value now that we know the active field
735
+ auto childValue = Value::createDefaultValue (* childrenTypes[activeFieldIdx]);
737
736
auto curMemberIdx = 0u ;
738
737
// Seek to the current active member value.
739
738
while (curMemberIdx < activeFieldIdx) {
740
739
unionValues += storage::StorageUtils::getDataTypeSize (*childrenTypes[curMemberIdx]);
741
740
curMemberIdx++;
742
741
}
743
742
if (NullBuffer::isNull (unionNullValues, activeFieldIdx)) {
744
- childValue->setNull (true );
743
+ childValue.setNull (true );
744
+ } else {
745
+ childValue.setNull (false );
746
+ childValue.copyFromRowLayout (unionValues);
747
+ }
748
+ if (children.empty ()) {
749
+ children.push_back (std::make_unique<Value>(std::move (childValue)));
750
+ childrenSize = 1 ;
745
751
} else {
746
- childValue->setNull (false );
747
- childValue->copyFromRowLayout (unionValues);
752
+ children[0 ] = std::make_unique<Value>(std::move (childValue));
748
753
}
749
754
}
750
755
0 commit comments