Skip to content

Commit

Permalink
fix make_decimal in long decimal (facebookincubator#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchengchenghh authored and JkSelf committed Mar 24, 2023
1 parent 115a634 commit fb2f8f2
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions velox/functions/sparksql/Decimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class CheckOverflowFunction final : public exec::VectorFunction {
}
};

template <typename TInput>
class MakeDecimalFunction final : public exec::VectorFunction {
void apply(
const SelectivityVector& rows,
Expand Down Expand Up @@ -137,12 +136,12 @@ class MakeDecimalFunction final : public exec::VectorFunction {
LONG_DECIMAL(
static_cast<uint8_t>(precision), static_cast<uint8_t>(scale)),
resultRef);
auto result = resultRef->asUnchecked<FlatVector<UnscaledShortDecimal>>()
auto result = resultRef->asUnchecked<FlatVector<UnscaledLongDecimal>>()
->mutableRawValues();
rows.applyToSelected([&](int row) {
auto unscaled = unscaledVec->valueAt<int64_t>(row);
if (UnscaledLongDecimal::valueInRange(unscaled)) {
result[row] = unscaled;
result[row] = UnscaledLongDecimal(unscaled);
} else {
if (nullOnOverflow) {
resultRef->setNull(row, true);
Expand Down Expand Up @@ -293,20 +292,9 @@ std::shared_ptr<exec::VectorFunction> makeMakeDecimal(
const std::string& name,
const std::vector<exec::VectorFunctionArg>& inputArgs) {
VELOX_CHECK_EQ(inputArgs.size(), 3);
auto fromType = inputArgs[0].type;
switch (fromType->kind()) {
case TypeKind::SHORT_DECIMAL:
return std::make_shared<MakeDecimalFunction<UnscaledShortDecimal>>();
case TypeKind::LONG_DECIMAL:
return std::make_shared<MakeDecimalFunction<UnscaledLongDecimal>>();
case TypeKind::INTEGER:
return std::make_shared<MakeDecimalFunction<int32_t>>();
case TypeKind::BIGINT:
return std::make_shared<MakeDecimalFunction<int64_t>>();
default:
VELOX_FAIL(
"Not support this type {} in make_decimal", fromType->kindName())
}
static const auto kMakeDecimalFunction =
std::make_shared<MakeDecimalFunction>();
return kMakeDecimalFunction;
}

std::shared_ptr<exec::VectorFunction> makeRoundDecimal(
Expand Down

0 comments on commit fb2f8f2

Please sign in to comment.