Skip to content

Commit

Permalink
use checked_cast
Browse files Browse the repository at this point in the history
  • Loading branch information
bkietz committed Jun 19, 2019
1 parent 223a860 commit d5c9c14
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions cpp/src/arrow/compute/kernels/mask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
namespace arrow {
namespace compute {

using internal::checked_cast;

Status Mask(FunctionContext* context, const Array& values, const Array& mask,
std::shared_ptr<Array>* out) {
Datum out_datum;
Expand Down Expand Up @@ -135,18 +137,18 @@ struct UnpackValues {
template <typename ValueType>
Status Visit(const ValueType&) {
using OutBuilder = typename TypeTraits<ValueType>::BuilderType;
auto&& mask = static_cast<const ArrayType<MaskType>&>(*params_.mask);
auto&& values = static_cast<const ArrayType<ValueType>&>(*params_.values);
const auto& mask = checked_cast<const ArrayType<MaskType>&>(*params_.mask);
const auto& values = checked_cast<const ArrayType<ValueType>&>(*params_.values);
std::unique_ptr<ArrayBuilder> builder;
RETURN_NOT_OK(MakeBuilder(params_.context->memory_pool(), values.type(), &builder));
RETURN_NOT_OK(builder->Reserve(OutputSize(mask)));
RETURN_NOT_OK(UnpackValuesNullCount(params_.context, values, mask,
static_cast<OutBuilder*>(builder.get())));
checked_cast<OutBuilder*>(builder.get())));
return builder->Finish(params_.out);
}

Status Visit(const NullType& t) {
auto&& mask = static_cast<const ArrayType<MaskType>&>(*params_.mask);
const auto& mask = checked_cast<const ArrayType<MaskType>&>(*params_.mask);
params_.out->reset(new NullArray(OutputSize(mask)));
return Status::OK();
}
Expand Down
10 changes: 6 additions & 4 deletions cpp/src/arrow/compute/kernels/take.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
namespace arrow {
namespace compute {

using internal::checked_cast;

Status Take(FunctionContext* context, const Array& values, const Array& indices,
std::shared_ptr<Array>* out) {
Datum out_datum;
Expand Down Expand Up @@ -117,20 +119,20 @@ struct UnpackValues {
Status Visit(const ValueType&) {
using ValueArrayRef = const typename TypeTraits<ValueType>::ArrayType&;
using OutBuilder = typename TypeTraits<ValueType>::BuilderType;
IndexArrayRef indices = static_cast<IndexArrayRef>(*params_.indices);
ValueArrayRef values = static_cast<ValueArrayRef>(*params_.values);
IndexArrayRef indices = checked_cast<IndexArrayRef>(*params_.indices);
ValueArrayRef values = checked_cast<ValueArrayRef>(*params_.values);
std::unique_ptr<ArrayBuilder> builder;
RETURN_NOT_OK(MakeBuilder(params_.context->memory_pool(), values.type(), &builder));
RETURN_NOT_OK(builder->Reserve(indices.length()));
RETURN_NOT_OK(UnpackValuesNullCount(params_.context, values, indices,
static_cast<OutBuilder*>(builder.get())));
checked_cast<OutBuilder*>(builder.get())));
return builder->Finish(params_.out);
}

Status Visit(const NullType& t) {
auto indices_length = params_.indices->length();
if (indices_length != 0) {
auto indices = static_cast<IndexArrayRef>(*params_.indices).raw_values();
auto indices = checked_cast<IndexArrayRef>(*params_.indices).raw_values();
auto minmax = std::minmax_element(indices, indices + indices_length);
auto min = static_cast<int64_t>(*minmax.first);
auto max = static_cast<int64_t>(*minmax.second);
Expand Down

0 comments on commit d5c9c14

Please sign in to comment.