diff --git a/be/src/runtime/buffered-tuple-stream.cc b/be/src/runtime/buffered-tuple-stream.cc index 3427daf6c..3f39c735c 100644 --- a/be/src/runtime/buffered-tuple-stream.cc +++ b/be/src/runtime/buffered-tuple-stream.cc @@ -73,6 +73,7 @@ string BufferedTupleStream::DebugString() const { stringstream ss; ss << "BufferedTupleStream num_rows=" << num_rows_ << " rows_returned=" << rows_returned_ << " pinned=" << (pinned_ ? "true" : "false") + << " delete_on_read=" << (delete_on_read_ ? "true" : "false") << " num_pinned=" << num_pinned_ << " write_block=" << write_block_ << " read_block_="; if (read_block_ == blocks_.end()) { @@ -176,11 +177,13 @@ Status BufferedTupleStream::NewBlockForWrite(int min_size, bool* got_block) { Status BufferedTupleStream::NextBlockForRead() { DCHECK(!closed_); DCHECK(read_block_ != blocks_.end()); + DCHECK_EQ(num_pinned_, NumPinned(blocks_)) << pinned_; // If non-NULL, this will be the current block if we are going to free it while // grabbing the next block. This will stay NULL if we don't want to free the // current block. - BufferedBlockMgr::Block* block_to_free = pinned_ ? NULL : *read_block_; + BufferedBlockMgr::Block* block_to_free = + (!pinned_ || delete_on_read_) ? *read_block_ : NULL; if (delete_on_read_) { blocks_.pop_front(); read_block_ = blocks_.begin(); @@ -214,13 +217,13 @@ Status BufferedTupleStream::NextBlockForRead() { DCHECK(block_to_free == NULL) << "Should have been able to pin." << endl << block_mgr_->DebugString(block_mgr_client_);; } - if (block_to_free == NULL) ++num_pinned_; + if (block_to_free == NULL && pinned) ++num_pinned_; } if (read_block_ != blocks_.end() && (*read_block_)->is_pinned()) { read_ptr_ = (*read_block_)->buffer(); } - DCHECK_EQ(num_pinned_, NumPinned(blocks_)); + DCHECK_EQ(num_pinned_, NumPinned(blocks_)) << DebugString(); return Status::OK; } diff --git a/testdata/workloads/functional-query/queries/QueryTest/analytic-fns.test b/testdata/workloads/functional-query/queries/QueryTest/analytic-fns.test index 51da8b121..29926b208 100644 --- a/testdata/workloads/functional-query/queries/QueryTest/analytic-fns.test +++ b/testdata/workloads/functional-query/queries/QueryTest/analytic-fns.test @@ -895,8 +895,8 @@ TINYINT, INT, BIGINT ==== ---- QUERY # IMPALA-1280: Crash running analytic with LEFT SEMI JOIN -select sum(t1.int_col) over (partition by t1.id order by t1.int_col, t1.month) -from alltypestiny t1 +select sum(t1.int_col) over (partition by t1.id order by t1.int_col, t1.month) +from alltypestiny t1 where exists (select tt1.month from alltypes tt1 where t1.int_col = tt1.smallint_col) ---- RESULTS: VERIFY_IS_EQUAL_SORTED 0 @@ -908,3 +908,25 @@ where exists (select tt1.month from alltypes tt1 where t1.int_col = tt1.smallint 1 1 ==== +---- QUERY +# IMPALA-1312 +SELECT + SUM(t1.int_col * t1.id) OVER ( + ORDER BY t1.int_col * t1.id ASC, t3.year + t3.tinyint_col ASC ROWS + BETWEEN 66 PRECEDING AND 21 FOLLOWING) AS int_col_1 +FROM alltypes t1 +INNER JOIN alltypes t2 ON t2.month = t1.smallint_col +INNER JOIN alltypes t3 ON t3.bigint_col = t2.bigint_col +WHERE +t2.id <= t3.smallint_col + t2.tinyint_col +order by 1 +limit 5 +---- TYPES +BIGINT +---- RESULTS +22 +23 +24 +25 +26 +====