Skip to content

Commit

Permalink
ARROW-212: Change contract of PrimitiveArray to reflect its abstractness
Browse files Browse the repository at this point in the history
Follow-up based on apache#80

Author: Micah Kornfield <emkornfield@gmail.com>

Closes apache#87 from emkornfield/emk_clarify_primitive and squashes the following commits:

14bd5b2 [Micah Kornfield] ARROW-212: Make the fact that PrimitiveArray is a abstract class more apparent fromt the contract
  • Loading branch information
emkornfield authored and wesm committed Jun 8, 2016
1 parent bc6c4c8 commit 8197f24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions cpp/src/arrow/types/primitive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ BooleanArray::BooleanArray(int32_t length, const std::shared_ptr<Buffer>& data,
: PrimitiveArray(
std::make_shared<BooleanType>(), length, data, null_count, null_bitmap) {}

BooleanArray::BooleanArray(const TypePtr& type, int32_t length,
const std::shared_ptr<Buffer>& data, int32_t null_count,
const std::shared_ptr<Buffer>& null_bitmap)
: PrimitiveArray(type, length, data, null_count, null_bitmap) {}

bool BooleanArray::EqualsExact(const BooleanArray& other) const {
if (this == &other) return true;
if (null_count_ != other.null_count_) { return false; }
Expand Down
15 changes: 9 additions & 6 deletions cpp/src/arrow/types/primitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ namespace arrow {

class MemoryPool;

// Base class for fixed-size logical types
// Base class for fixed-size logical types. See MakePrimitiveArray
// (types/construct.h) for constructing a specific subclass.
class PrimitiveArray : public Array {
public:
PrimitiveArray(const TypePtr& type, int32_t length, const std::shared_ptr<Buffer>& data,
int32_t null_count = 0, const std::shared_ptr<Buffer>& null_bitmap = nullptr);
virtual ~PrimitiveArray() {}

const std::shared_ptr<Buffer>& data() const { return data_; }
Expand All @@ -47,6 +46,8 @@ class PrimitiveArray : public Array {
bool Equals(const std::shared_ptr<Array>& arr) const override;

protected:
PrimitiveArray(const TypePtr& type, int32_t length, const std::shared_ptr<Buffer>& data,
int32_t null_count = 0, const std::shared_ptr<Buffer>& null_bitmap = nullptr);
std::shared_ptr<Buffer> data_;
const uint8_t* raw_data_;
};
Expand All @@ -55,12 +56,14 @@ class PrimitiveArray : public Array {
class NAME : public PrimitiveArray { \
public: \
using value_type = T; \
using PrimitiveArray::PrimitiveArray; \
\
NAME(int32_t length, const std::shared_ptr<Buffer>& data, int32_t null_count = 0, \
const std::shared_ptr<Buffer>& null_bitmap = nullptr) \
: PrimitiveArray( \
std::make_shared<TypeClass>(), length, data, null_count, null_bitmap) {} \
NAME(const TypePtr& type, int32_t length, const std::shared_ptr<Buffer>& data, \
int32_t null_count = 0, const std::shared_ptr<Buffer>& null_bitmap = nullptr) \
: PrimitiveArray(type, length, data, null_count, null_bitmap) {} \
\
bool EqualsExact(const NAME& other) const { \
return PrimitiveArray::EqualsExact(*static_cast<const PrimitiveArray*>(&other)); \
Expand Down Expand Up @@ -261,10 +264,10 @@ typedef NumericBuilder<DoubleType> DoubleBuilder;

class BooleanArray : public PrimitiveArray {
public:
using PrimitiveArray::PrimitiveArray;

BooleanArray(int32_t length, const std::shared_ptr<Buffer>& data,
int32_t null_count = 0, const std::shared_ptr<Buffer>& null_bitmap = nullptr);
BooleanArray(const TypePtr& type, int32_t length, const std::shared_ptr<Buffer>& data,
int32_t null_count = 0, const std::shared_ptr<Buffer>& null_bitmap = nullptr);

bool EqualsExact(const BooleanArray& other) const;
bool Equals(const ArrayPtr& arr) const override;
Expand Down

0 comments on commit 8197f24

Please sign in to comment.