Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions velox/experimental/cudf/expression/DecimalExpressionKernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "velox/experimental/cudf/expression/DecimalExpressionKernelsGpu.h"

#include "velox/common/base/Exceptions.h"
#include "velox/type/DecimalUtil.h"
#include "velox/type/Type.h"

#include <cudf/binaryop.hpp>
#include <cudf/column/column_factories.hpp>
Expand Down Expand Up @@ -118,6 +120,10 @@ std::unique_ptr<cudf::column> decimalDivide(
"Decimal divide requires matching input types");
VELOX_CHECK_GE(
aRescale, 0, "Decimal divide requires non-negative rescale factor");
// Rescale indexes DecimalUtil::kPowersOfTen; same bound as Presto divide
// init.
VELOX_USER_CHECK_LE(
aRescale, LongDecimalType::kMaxPrecision, "Decimal overflow");

const auto inType = lhs.type().id();
const auto outType = outputType.id();
Expand All @@ -143,8 +149,17 @@ std::unique_ptr<cudf::column> decimalDivide(
auto out = cudf::make_fixed_width_column(
outputType, lhs.size(), std::move(nullMask), nullCount, stream, mr);

detail::decimalDivideColumnColumn(
inType, outType, lhs, rhs, out->mutable_view(), aRescale, stream);
const __int128_t rescaleFactor = DecimalUtil::kPowersOfTen[aRescale];
VELOX_USER_CHECK(
detail::decimalDivideColumnColumn(
inType,
outType,
lhs,
rhs,
out->mutable_view(),
rescaleFactor,
stream),
"Decimal overflow");

// Scatter nulls where divisor is zero.
return scatterNullsAtZeroDivisor(std::move(out), rhs, stream, mr);
Expand All @@ -159,6 +174,10 @@ std::unique_ptr<cudf::column> decimalDivide(
rmm::device_async_resource_ref mr) {
VELOX_CHECK_GE(
aRescale, 0, "Decimal divide requires non-negative rescale factor");
// Rescale indexes DecimalUtil::kPowersOfTen; same bound as Presto divide
// init.
VELOX_USER_CHECK_LE(
aRescale, LongDecimalType::kMaxPrecision, "Decimal overflow");

if (!rhs.is_valid(stream)) {
return makeAllNullDecimalColumn(outputType, lhs.size(), stream, mr);
Expand Down Expand Up @@ -187,8 +206,16 @@ std::unique_ptr<cudf::column> decimalDivide(
"Unexpected output type for decimal divide");
}

detail::decimalDivideColumnScalar(
inType, outType, lhs, rhsValue, out->mutable_view(), aRescale, stream);
VELOX_USER_CHECK(
detail::decimalDivideColumnScalar(
inType,
outType,
lhs,
rhsValue,
out->mutable_view(),
DecimalUtil::kPowersOfTen[aRescale],
stream),
"Decimal overflow");

return out;
}
Expand All @@ -202,6 +229,10 @@ std::unique_ptr<cudf::column> decimalDivide(
rmm::device_async_resource_ref mr) {
VELOX_CHECK_GE(
aRescale, 0, "Decimal divide requires non-negative rescale factor");
// Rescale indexes DecimalUtil::kPowersOfTen; same bound as Presto divide
// init.
VELOX_USER_CHECK_LE(
aRescale, LongDecimalType::kMaxPrecision, "Decimal overflow");

if (!lhs.is_valid(stream)) {
return makeAllNullDecimalColumn(outputType, rhs.size(), stream, mr);
Expand Down Expand Up @@ -233,8 +264,17 @@ std::unique_ptr<cudf::column> decimalDivide(
"Unexpected output type for decimal divide");
}

detail::decimalDivideScalarColumn(
inType, outType, lhsValue, rhs, out->mutable_view(), aRescale, stream);
const __int128_t rescaleFactor = DecimalUtil::kPowersOfTen[aRescale];
VELOX_USER_CHECK(
detail::decimalDivideScalarColumn(
inType,
outType,
lhsValue,
rhs,
out->mutable_view(),
rescaleFactor,
stream),
"Decimal overflow");

// Scatter nulls where divisor is zero.
return scatterNullsAtZeroDivisor(std::move(out), rhs, stream, mr);
Expand Down
Loading
Loading