Skip to content

Commit

Permalink
Merge 208d4ad into 69d595a
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Feb 14, 2019
2 parents 69d595a + 208d4ad commit cdc74a5
Show file tree
Hide file tree
Showing 15 changed files with 662 additions and 384 deletions.
1 change: 1 addition & 0 deletions cpp/build-support/lint_exclusions.txt
@@ -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
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 < 0)) {
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
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
2 changes: 2 additions & 0 deletions cpp/src/arrow/compute/kernel.h
Expand Up @@ -188,6 +188,8 @@ 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;

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

/// \class BinaryKernel
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/arrow/compute/kernels/aggregate.cc
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
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
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

0 comments on commit cdc74a5

Please sign in to comment.