marin-ma commented on code in PR #7998:
URL: https://github.com/apache/incubator-gluten/pull/7998#discussion_r1849558185
##########
cpp/core/jni/JniCommon.cc:
##########
@@ -109,17 +109,30 @@ std::shared_ptr<gluten::ColumnarBatch>
gluten::JniColumnarBatchIterator::next()
return nullptr; // stream ended
}
- checkException(env);
- jlong handle = env->CallLongMethod(jColumnarBatchItr_,
serializedColumnarBatchIteratorNext_);
- checkException(env);
- auto batch = ObjectStore::retrieve<ColumnarBatch>(handle);
if (writer_ != nullptr) {
- // save snapshot of the batch to file
- std::shared_ptr<ArrowSchema> schema = batch->exportArrowSchema();
- std::shared_ptr<ArrowArray> array = batch->exportArrowArray();
- auto rb = gluten::arrowGetOrThrow(arrow::ImportRecordBatch(array.get(),
schema.get()));
- GLUTEN_THROW_NOT_OK(writer_->initWriter(*(rb->schema().get())));
- GLUTEN_THROW_NOT_OK(writer_->writeInBatches(rb));
+ if (!writer_->closed()) {
+ // Dump all inputs.
+ do {
+ checkException(env);
+ jlong handle = env->CallLongMethod(jColumnarBatchItr_,
serializedColumnarBatchIteratorNext_);
+ checkException(env);
+ auto batch = ObjectStore::retrieve<ColumnarBatch>(handle);
+
+ // Save the snapshot of the batch to file.
+ std::shared_ptr<ArrowSchema> schema = batch->exportArrowSchema();
+ std::shared_ptr<ArrowArray> array = batch->exportArrowArray();
+ auto rb =
gluten::arrowGetOrThrow(arrow::ImportRecordBatch(array.get(), schema.get()));
+ GLUTEN_THROW_NOT_OK(writer_->initWriter(*(rb->schema().get())));
+ GLUTEN_THROW_NOT_OK(writer_->writeInBatches(rb));
+ } while (env->CallBooleanMethod(jColumnarBatchItr_,
serializedColumnarBatchIteratorHasNext_));
Review Comment:
@jinchengchenghh In what cases would the batch iterator be reused? Could you
elaborate more on this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]