Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
discard proxy pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
zhztheplayer committed Jul 28, 2021
1 parent b671deb commit 10878c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 42 deletions.
51 changes: 10 additions & 41 deletions native-sql-engine/cpp/src/codegen/common/relation_column.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ class TypedRelationColumn<DataType, enable_if_number_or_decimal<DataType>>
}
return arrow::Status::OK();
}
virtual T GetValue(int array_id, int id) {
T GetValue(int array_id, int id) {
return array_vector_[array_id]->GetView(id);
}
bool HasNull() { return has_null_; }
virtual bool HasNull() { return has_null_; }

private:
using ArrayType = typename TypeTraits<DataType>::ArrayType;
Expand Down Expand Up @@ -188,10 +188,10 @@ class TypedRelationColumn<DataType, enable_if_string_like<DataType>>
}
return arrow::Status::OK();
}
virtual std::string GetValue(int array_id, int id) {
std::string GetValue(int array_id, int id) {
return array_vector_[array_id]->GetString(id);
}
bool HasNull() { return has_null_; }
virtual bool HasNull() { return has_null_; }

private:
std::vector<std::shared_ptr<StringArray>> array_vector_;
Expand All @@ -211,14 +211,6 @@ class TypedLazyLoadRelationColumn<DataType, enable_if_number_or_decimal<DataType
using T = typename TypeTraits<DataType>::CType;
TypedLazyLoadRelationColumn() = default;

bool IsNull(int array_id, int id) override {
return delegated.IsNull(array_id, id);
}

bool IsEqualTo(int x_array_id, int x_id, int y_array_id, int y_id) override {
return delegated.IsEqualTo(x_array_id, x_id, y_array_id, y_id);
}

arrow::Status FromLazyBatchIterator(std::shared_ptr<LazyBatchIterator> in,
int field_id) override {
in_ = in;
Expand All @@ -233,7 +225,7 @@ class TypedLazyLoadRelationColumn<DataType, enable_if_number_or_decimal<DataType
for (int i = current_array_id_; i <= array_id; i++) {
std::shared_ptr<arrow::RecordBatch> batch = in_->GetBatch(i);
std::shared_ptr<arrow::Array> array = batch->column(field_id_);
delegated.AppendColumn(array);
TypedRelationColumn<DataType>::AppendColumn(array);
in_->RetainBatch(i);
array_released.push_back(false);
}
Expand All @@ -250,7 +242,7 @@ class TypedLazyLoadRelationColumn<DataType, enable_if_number_or_decimal<DataType
return i;
}
std::shared_ptr<arrow::Array> array = batch->column(field_id_);
delegated.AppendColumn(array);
TypedRelationColumn<DataType>::AppendColumn(array);
in_->RetainBatch(target_batch);
array_released.push_back(false);
current_array_id_++;
Expand All @@ -265,24 +257,16 @@ class TypedLazyLoadRelationColumn<DataType, enable_if_number_or_decimal<DataType
if (array_released[array_id]) {
return arrow::Status::OK();
}
RETURN_NOT_OK(delegated.ReleaseArray(array_id));
RETURN_NOT_OK(TypedRelationColumn<DataType>::ReleaseArray(array_id));
in_->ReleaseBatch(array_id);
array_released[array_id] = true;
return arrow::Status::OK();
}

arrow::Status GetArrayVector(std::vector<std::shared_ptr<arrow::Array>>* out) override {
return delegated.GetArrayVector(out);
}

T GetValue(int array_id, int id) override {
return delegated.GetValue(array_id, id);
}
bool HasNull() override { return has_null_; }

private:
std::shared_ptr<LazyBatchIterator> in_;
TypedRelationColumn<DataType> delegated;
int current_array_id_ = 0;
int field_id_ = -1;
std::vector<bool> array_released;
Expand All @@ -294,12 +278,6 @@ class TypedLazyLoadRelationColumn<DataType, enable_if_string_like<DataType>>
: public TypedRelationColumn<DataType> {
public:
TypedLazyLoadRelationColumn() = default;
bool IsNull(int array_id, int id) override {
return delegated.IsNull(array_id, id);
}
bool IsEqualTo(int x_array_id, int x_id, int y_array_id, int y_id) override {
return delegated.IsEqualTo(x_array_id, x_id, y_array_id, y_id);
}

arrow::Status FromLazyBatchIterator(std::shared_ptr<LazyBatchIterator> in,
int field_id) override {
Expand All @@ -315,7 +293,7 @@ class TypedLazyLoadRelationColumn<DataType, enable_if_string_like<DataType>>
for (int i = current_array_id_; i <= array_id; i++) {
std::shared_ptr<arrow::RecordBatch> batch = in_->GetBatch(i);
std::shared_ptr<arrow::Array> array = batch->column(field_id_);
delegated.AppendColumn(array);
TypedRelationColumn<DataType>::AppendColumn(array);
in_->RetainBatch(i);
array_released.push_back(false);
}
Expand All @@ -332,7 +310,7 @@ class TypedLazyLoadRelationColumn<DataType, enable_if_string_like<DataType>>
return i;
}
std::shared_ptr<arrow::Array> array = batch->column(field_id_);
delegated.AppendColumn(array);
TypedRelationColumn<DataType>::AppendColumn(array);
in_->RetainBatch(target_batch);
array_released.push_back(false);
current_array_id_++;
Expand All @@ -347,25 +325,16 @@ class TypedLazyLoadRelationColumn<DataType, enable_if_string_like<DataType>>
if (array_released[array_id]) {
return arrow::Status::OK();
}
RETURN_NOT_OK(delegated.ReleaseArray(array_id));
RETURN_NOT_OK(TypedRelationColumn<DataType>::ReleaseArray(array_id));
in_->ReleaseBatch(array_id);
array_released[array_id] = true;
return arrow::Status::OK();
}

arrow::Status GetArrayVector(std::vector<std::shared_ptr<arrow::Array>>* out) override {
return delegated.GetArrayVector(out);
}

std::string GetValue(int array_id, int id) override {
return delegated.GetValue(array_id, id);
}

bool HasNull() override { return has_null_; }

private:
std::shared_ptr<LazyBatchIterator> in_;
TypedRelationColumn<DataType> delegated;
int32_t current_array_id_ = 0;
int32_t field_id_ = -1;
std::vector<bool> array_released;
Expand Down
2 changes: 1 addition & 1 deletion native-sql-engine/cpp/src/tests/arrow_compute_test_wscg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4151,7 +4151,7 @@ TEST(TestArrowComputeWSCG, WSCGTestContinuousMergeJoinSemiExistenceWithCondition
ASSERT_NOT_OK(expr->finish(&build_result_iterator));
auto rb_iter = std::dynamic_pointer_cast<ResultIterator<arrow::RecordBatch>>(
build_result_iterator);
if (false) {
if (true) {
// lazy read
arrow::RecordBatchIterator itr = arrow::MakeFunctionIterator(
[rb_iter]() -> arrow::Result<std::shared_ptr<arrow::RecordBatch>> {
Expand Down

0 comments on commit 10878c0

Please sign in to comment.