Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: execute "select count(*) from tbl" always getting zero #114

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/datafusion_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ async fn main() -> Result<()> {
.show()
.await?;

ctx.sql("select count(*) from table1").await?.show().await?;

ctx.read_orc(
"tests/basic/data/alltypes.snappy.orc",
OrcReadOptions::default(),
Expand Down
18 changes: 16 additions & 2 deletions src/array_decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use arrow::datatypes::{DataType as ArrowDataType, Field};
use arrow::datatypes::{
Date32Type, Float32Type, Float64Type, Int16Type, Int32Type, Int64Type, Int8Type, SchemaRef,
};
use arrow::record_batch::RecordBatch;
use arrow::record_batch::{RecordBatch, RecordBatchOptions};
use snafu::{ensure, ResultExt};

use crate::column::{get_present_vec, Column};
Expand Down Expand Up @@ -569,7 +569,21 @@ impl NaiveStripeDecoder {
let fields = self.inner_decode_next_batch(remaining)?;

if fields.is_empty() {
Ok(None)
if remaining == 0 {
Ok(None)
} else {
// In case of empty projection, we need to create a RecordBatch with `row_count` only
// to reflect the row number
Ok(Some(
RecordBatch::try_new_with_options(
Arc::clone(&self.schema_ref),
fields,
&RecordBatchOptions::new()
.with_row_count(Some(self.batch_size.min(remaining))),
)
.context(error::ConvertRecordBatchSnafu)?,
))
}
} else {
//TODO(weny): any better way?
let fields = self
Expand Down
Loading