Skip to content

Commit

Permalink
Remove dead code from TryExpr::nullOutErrors (facebookincubator#9978)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebookincubator#9978

Errors vector is always flat, hence, 'if (errors->isConstantEncoding())' branch
is never taken.

Reviewed By: amitkdutta

Differential Revision: D57952179

fbshipit-source-id: a0349482c58cb599e28a6ce5a3a9be21d7d25c7e
  • Loading branch information
mbasmanova authored and facebook-github-bot committed May 30, 2024
1 parent 3f9d0c8 commit 0dc4633
Showing 1 changed file with 47 additions and 53 deletions.
100 changes: 47 additions & 53 deletions velox/expression/TryExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,62 +103,56 @@ void TryExpr::nullOutErrors(
const SelectivityVector& rows,
EvalCtx& context,
VectorPtr& result) const {
auto errors = context.errors();
if (errors) {
applyListenersOnError(rows, context);

if (result->encoding() == VectorEncoding::Simple::CONSTANT) {
// Since it's constant, if any row is NULL they're all NULL, so check row
// 0 arbitrarily.
if (result->isNullAt(0)) {
// The result is already a NULL constant, so this is a no-op.
return;
}
const auto* errors = context.errors();
if (!errors) {
return;
}

applyListenersOnError(rows, context);

if (errors->isConstantEncoding()) {
// Set the result to be a NULL constant.
result = BaseVector::createNullConstant(
result->type(), result->size(), context.pool());
} else {
auto size = result->size();
VELOX_DCHECK_GE(size, rows.end());

auto nulls = allocateNulls(size, context.pool());
auto rawNulls = nulls->asMutable<uint64_t>();
rows.applyToSelected([&](auto row) {
if (row < errors->size() && !errors->isNullAt(row)) {
bits::setNull(rawNulls, row, true);
}
});
// Wrap in dictionary indices all pointing to index 0.
auto indices = allocateIndices(size, context.pool());
result = BaseVector::wrapInDictionary(nulls, indices, size, result);
if (result->isConstantEncoding()) {
// Since it's constant, if any row is NULL they're all NULL, so check row
// 0 arbitrarily.
if (result->isNullAt(0)) {
// The result is already a NULL constant, so this is a no-op.
return;
}

auto size = result->size();
VELOX_DCHECK_GE(size, rows.end());

auto nulls = allocateNulls(size, context.pool());
auto rawNulls = nulls->asMutable<uint64_t>();
rows.applyToSelected([&](auto row) {
if (row < errors->size() && !errors->isNullAt(row)) {
bits::setNull(rawNulls, row, true);
}
} else {
if (result.unique() && result->isNullsWritable()) {
auto* rawNulls = result->mutableRawNulls();
rows.applyToSelected([&](auto row) {
if (row < errors->size() && !errors->isNullAt(row)) {
bits::setNull(rawNulls, row, true);
}
});
} else {
auto nulls = allocateNulls(rows.end(), context.pool());
auto* rawNulls = nulls->asMutable<uint64_t>();
auto indices = allocateIndices(rows.end(), context.pool());
auto* rawIndices = indices->asMutable<vector_size_t>();

rows.applyToSelected([&](auto row) {
rawIndices[row] = row;
if (row < errors->size() && !errors->isNullAt(row)) {
bits::setNull(rawNulls, row, true);
}
});

result =
BaseVector::wrapInDictionary(nulls, indices, rows.end(), result);
});

// Wrap in dictionary indices all pointing to index 0.
auto indices = allocateIndices(size, context.pool());
result = BaseVector::wrapInDictionary(nulls, indices, size, result);
} else if (result.unique() && result->isNullsWritable()) {
auto* rawNulls = result->mutableRawNulls();
rows.applyToSelected([&](auto row) {
if (row < errors->size() && !errors->isNullAt(row)) {
bits::setNull(rawNulls, row, true);
}
}
});
} else {
auto nulls = allocateNulls(rows.end(), context.pool());
auto* rawNulls = nulls->asMutable<uint64_t>();
auto indices = allocateIndices(rows.end(), context.pool());
auto* rawIndices = indices->asMutable<vector_size_t>();

rows.applyToSelected([&](auto row) {
rawIndices[row] = row;
if (row < errors->size() && !errors->isNullAt(row)) {
bits::setNull(rawNulls, row, true);
}
});

result = BaseVector::wrapInDictionary(nulls, indices, rows.end(), result);
}
}

Expand Down

0 comments on commit 0dc4633

Please sign in to comment.