Skip to content

Commit

Permalink
Refactor repeat Presto function for readability (#7277)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #7277

Reviewed By: xiaoxmeng

Differential Revision: D50737622

Pulled By: mbasmanova

fbshipit-source-id: ac9a4728d53a9a143ab793043c04b9129098350e
  • Loading branch information
mbasmanova authored and facebook-github-bot committed Oct 30, 2023
1 parent 68b4698 commit b9984b4
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions velox/functions/prestosql/Repeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@ class RepeatFunction : public exec::VectorFunction {
VectorPtr& result) const override {
VectorPtr localResult;
if (args[1]->isConstantEncoding()) {
try {
localResult = applyConstant(rows, args, outputType, context);
} catch (const VeloxRuntimeError&) {
throw;
} catch (const std::exception& e) {
context.setErrors(rows, std::current_exception());
localResult = applyConstant(rows, args, outputType, context);
if (localResult == nullptr) {
return;
}
} else {
Expand Down Expand Up @@ -71,14 +67,20 @@ class RepeatFunction : public exec::VectorFunction {
const auto numRows = rows.end();
auto pool = context.pool();

if (args[1]->as<ConstantVector<int32_t>>()->isNullAt(0)) {
auto* constantCount = args[1]->as<ConstantVector<int32_t>>();
if (constantCount->isNullAt(0)) {
// If count is a null constant, the result should be all nulls.
return BaseVector::createNullConstant(outputType, numRows, pool);
}

const auto count = args[1]->as<ConstantVector<int32_t>>()->valueAt(0);
// Exception will be processed on the upper level.
checkCount(count);
const auto count = constantCount->valueAt(0);
try {
checkCount(count);
} catch (const VeloxUserError&) {
context.setErrors(rows, std::current_exception());
return nullptr;
}

const auto totalCount = count * numRows;

// Allocate new vectors for indices, lengths and offsets.
Expand Down

0 comments on commit b9984b4

Please sign in to comment.