Skip to content
Closed
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
1 change: 1 addition & 0 deletions cpp/build-support/lint_exclusions.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*codegen*
*_generated*
*windows_compatibility.h
*pyarrow_api.h
Expand Down
23 changes: 12 additions & 11 deletions cpp/src/arrow/array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,23 @@ std::shared_ptr<ArrayData> ArrayData::Make(const std::shared_ptr<DataType>& type
return std::make_shared<ArrayData>(type, length, null_count, offset);
}

// ----------------------------------------------------------------------
// Base array class

int64_t Array::null_count() const {
if (ARROW_PREDICT_FALSE(data_->null_count < 0)) {
if (data_->buffers[0]) {
data_->null_count =
data_->length - CountSetBits(null_bitmap_data_, data_->offset, data_->length);

int64_t ArrayData::GetNullCount() const {
if (ARROW_PREDICT_FALSE(this->null_count == kUnknownNullCount)) {
if (this->buffers[0]) {
this->null_count = this->length - CountSetBits(this->buffers[0]->data(),
this->offset, this->length);
} else {
data_->null_count = 0;
this->null_count = 0;
}
}
return data_->null_count;
return this->null_count;
}

// ----------------------------------------------------------------------
// Base array class

int64_t Array::null_count() const { return data_->GetNullCount(); }

bool Array::Equals(const Array& arr) const { return ArrayEquals(*this, arr); }

bool Array::Equals(const std::shared_ptr<Array>& arr) const {
Expand Down
5 changes: 4 additions & 1 deletion cpp/src/arrow/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,12 @@ struct ARROW_EXPORT ArrayData {
return GetMutableValues<T>(i, offset);
}

/// \brief Return null count, or compute and set it if it's not known
int64_t GetNullCount() const;

std::shared_ptr<DataType> type;
int64_t length;
int64_t null_count;
mutable int64_t null_count;
// The logical start point into the physical buffers (in values, not bytes).
// Note that, for child data, this must be *added* to the child data's own offset.
int64_t offset;
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/arrow/compute/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ class ARROW_EXPORT UnaryKernel : public OpKernel {
/// there will be a more generic mechansim for understanding the necessary
/// contracts.
virtual Status Call(FunctionContext* ctx, const Datum& input, Datum* out) = 0;

/// \brief EXPERIMENTAL The output data type of the kernel
/// \return the output type
virtual std::shared_ptr<DataType> out_type() const = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

documentation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

};

/// \class BinaryKernel
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/arrow/compute/kernels/aggregate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,9 @@ Status AggregateUnaryKernel::Call(FunctionContext* ctx, const Datum& input, Datu
return Status::OK();
}

std::shared_ptr<DataType> AggregateUnaryKernel::out_type() const {
return aggregate_function_->out_type();
}

} // namespace compute
} // namespace arrow
4 changes: 4 additions & 0 deletions cpp/src/arrow/compute/kernels/aggregate.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class AggregateFunction {

virtual ~AggregateFunction() {}

virtual std::shared_ptr<DataType> out_type() const = 0;

/// State management methods.
virtual int64_t Size() const = 0;
virtual void New(void* ptr) const = 0;
Expand Down Expand Up @@ -103,6 +105,8 @@ class ARROW_EXPORT AggregateUnaryKernel : public UnaryKernel {

Status Call(FunctionContext* ctx, const Datum& input, Datum* out) override;

std::shared_ptr<DataType> out_type() const override;

private:
std::shared_ptr<AggregateFunction> aggregate_function_;
};
Expand Down
21 changes: 7 additions & 14 deletions cpp/src/arrow/compute/kernels/boolean.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ namespace arrow {
using internal::BitmapAnd;
using internal::BitmapOr;
using internal::BitmapXor;
using internal::CopyBitmap;
using internal::CountSetBits;
using internal::InvertBitmap;

namespace compute {

class InvertKernel : public UnaryKernel {
class BooleanUnaryKernel : public UnaryKernel {
public:
std::shared_ptr<DataType> out_type() const override { return boolean(); }
};

class InvertKernel : public BooleanUnaryKernel {
Status Call(FunctionContext* ctx, const Datum& input, Datum* out) override {
DCHECK_EQ(Datum::ARRAY, input.kind());
constexpr int64_t kZeroDestOffset = 0;
Expand All @@ -49,17 +53,6 @@ class InvertKernel : public UnaryKernel {
std::shared_ptr<ArrayData> result = out->array();
result->type = boolean();

// Handle validity bitmap
result->null_count = in_data.null_count;
const std::shared_ptr<Buffer>& validity_bitmap = in_data.buffers[0];
if (in_data.offset != 0 && in_data.null_count > 0) {
DCHECK_LE(BitUtil::BytesForBits(in_data.length), validity_bitmap->size());
CopyBitmap(validity_bitmap->data(), in_data.offset, in_data.length,
result->buffers[0]->mutable_data(), kZeroDestOffset);
} else {
result->buffers[0] = validity_bitmap;
}

// Handle output data buffer
if (in_data.length > 0) {
const Buffer& data_buffer = *in_data.buffers[1];
Expand All @@ -73,7 +66,7 @@ class InvertKernel : public UnaryKernel {

Status Invert(FunctionContext* ctx, const Datum& value, Datum* out) {
detail::PrimitiveAllocatingUnaryKernel kernel(
std::unique_ptr<UnaryKernel>(new InvertKernel()));
std::unique_ptr<UnaryKernel>(new InvertKernel()), boolean());

std::vector<Datum> result;
RETURN_NOT_OK(detail::InvokeUnaryArrayKernel(ctx, &kernel, value, &result));
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/compute/kernels/cast-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ TEST_F(TestCast, PreallocatedMemory) {
shared_ptr<Buffer> out_values;
ASSERT_OK(this->ctx_.Allocate(length * sizeof(int64_t), &out_values));

out_data->buffers.push_back(nullptr);
out_data->buffers.push_back(arr->data()->buffers[0]);
out_data->buffers.push_back(out_values);

Datum out(out_data);
Expand Down
Loading