@@ -180,6 +180,11 @@ void RowVector::copy(
180
180
const BaseVector* source,
181
181
const SelectivityVector& rows,
182
182
const vector_size_t * toSourceRow) {
183
+ if (source->typeKind () == TypeKind::UNKNOWN) {
184
+ rows.applyToSelected ([&](auto row) { setNull (row, true ); });
185
+ return ;
186
+ }
187
+
183
188
// Copy non-null values.
184
189
SelectivityVector nonNullRows = rows;
185
190
@@ -261,13 +266,47 @@ void RowVector::copy(
261
266
}
262
267
}
263
268
269
+ namespace {
270
+
271
+ // Runs quick checks to determine whether input vector has only null values.
272
+ // @return true if vector has only null values; false if vector may have
273
+ // non-null values.
274
+ bool isAllNullVector (const BaseVector& vector) {
275
+ if (vector.typeKind () == TypeKind::UNKNOWN) {
276
+ return true ;
277
+ }
278
+
279
+ if (vector.isConstantEncoding ()) {
280
+ return vector.isNullAt (0 );
281
+ }
282
+
283
+ auto leafVector = vector.wrappedVector ();
284
+ if (leafVector->isConstantEncoding ()) {
285
+ // A null constant does not have a value vector, so wrappedVector
286
+ // returns the constant.
287
+ VELOX_CHECK (leafVector->isNullAt (0 ));
288
+ return true ;
289
+ }
290
+ return false ;
291
+ }
292
+ } // namespace
293
+
264
294
void RowVector::copyRanges (
265
295
const BaseVector* source,
266
296
const folly::Range<const CopyRange*>& ranges) {
267
297
if (ranges.empty ()) {
268
298
return ;
269
299
}
270
300
301
+ if (isAllNullVector (*source)) {
302
+ for (const auto & range : ranges) {
303
+ for (auto i = 0 ; i < range.count ; ++i) {
304
+ setNull (range.targetIndex + i, true );
305
+ }
306
+ }
307
+ return ;
308
+ }
309
+
271
310
auto minTargetIndex = std::numeric_limits<vector_size_t >::max ();
272
311
auto maxTargetIndex = std::numeric_limits<vector_size_t >::min ();
273
312
for (auto & r : ranges) {
@@ -422,23 +461,29 @@ void ArrayVectorBase::copyRangesImpl(
422
461
const BaseVector* source,
423
462
const folly::Range<const BaseVector::CopyRange*>& ranges,
424
463
VectorPtr* targetValues,
425
- const BaseVector* sourceValues,
426
- VectorPtr* targetKeys,
427
- const BaseVector* sourceKeys) {
428
- auto sourceValue = source->wrappedVector ();
429
- if (sourceValue->isConstantEncoding ()) {
430
- // A null constant does not have a value vector, so wrappedVector
431
- // returns the constant.
432
- VELOX_CHECK (sourceValue->isNullAt (0 ));
433
- for (auto & r : ranges) {
434
- for (auto i = 0 ; i < r.count ; ++i) {
435
- setNull (r.targetIndex + i, true );
464
+ VectorPtr* targetKeys) {
465
+ if (isAllNullVector (*source)) {
466
+ for (const auto & range : ranges) {
467
+ for (auto i = 0 ; i < range.count ; ++i) {
468
+ setNull (range.targetIndex + i, true );
436
469
}
437
470
}
438
471
return ;
439
472
}
440
- VELOX_CHECK_EQ (sourceValue->encoding (), encoding ());
441
- auto sourceArray = sourceValue->asUnchecked <ArrayVectorBase>();
473
+
474
+ const BaseVector* sourceValues;
475
+ const BaseVector* sourceKeys = nullptr ;
476
+
477
+ auto leafSource = source->wrappedVector ();
478
+ VELOX_CHECK_EQ (leafSource->encoding (), encoding ());
479
+
480
+ if (typeKind_ == TypeKind::ARRAY) {
481
+ sourceValues = leafSource->as <ArrayVector>()->elements ().get ();
482
+ } else {
483
+ sourceValues = leafSource->as <MapVector>()->mapValues ().get ();
484
+ sourceKeys = leafSource->as <MapVector>()->mapKeys ().get ();
485
+ }
486
+
442
487
if (targetKeys) {
443
488
BaseVector::ensureWritable (
444
489
SelectivityVector::empty (),
@@ -452,6 +497,8 @@ void ArrayVectorBase::copyRangesImpl(
452
497
pool (),
453
498
*targetValues);
454
499
}
500
+
501
+ auto sourceArray = leafSource->asUnchecked <ArrayVectorBase>();
455
502
auto setNotNulls = mayHaveNulls () || source->mayHaveNulls ();
456
503
auto * mutableOffsets = offsets_->asMutable <vector_size_t >();
457
504
auto * mutableSizes = sizes_->asMutable <vector_size_t >();
@@ -869,6 +916,12 @@ void ArrayVector::validate(const VectorValidateOptions& options) const {
869
916
elements_->validate (options);
870
917
}
871
918
919
+ void ArrayVector::copyRanges (
920
+ const BaseVector* source,
921
+ const folly::Range<const CopyRange*>& ranges) {
922
+ copyRangesImpl (source, ranges, &elements_, nullptr );
923
+ }
924
+
872
925
bool MapVector::containsNullAt (vector_size_t idx) const {
873
926
if (BaseVector::isNullAt (idx)) {
874
927
return true ;
@@ -1158,5 +1211,11 @@ void MapVector::validate(const VectorValidateOptions& options) const {
1158
1211
values_->validate (options);
1159
1212
}
1160
1213
1214
+ void MapVector::copyRanges (
1215
+ const BaseVector* source,
1216
+ const folly::Range<const CopyRange*>& ranges) {
1217
+ copyRangesImpl (source, ranges, &values_, &keys_);
1218
+ }
1219
+
1161
1220
} // namespace velox
1162
1221
} // namespace facebook
0 commit comments