Skip to content

Commit fc2f879

Browse files
committed
Skip computation of expression return dtype unless there are no chunks
to return Signed-off-by: Robert Kruszewski <github@robertk.io>
1 parent 06cf4a3 commit fc2f879

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

vortex-layout/src/layouts/chunked/reader.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use vortex_array::dtype::FieldMask;
2121
use vortex_array::expr::Expression;
2222
use vortex_error::VortexExpect;
2323
use vortex_error::VortexResult;
24+
use vortex_error::vortex_ensure;
2425
use vortex_error::vortex_panic;
2526
use vortex_mask::Mask;
2627
use vortex_session::VortexSession;
@@ -290,9 +291,11 @@ impl LayoutReader for ChunkedReader {
290291
expr: &Expression,
291292
mask: MaskFuture,
292293
) -> VortexResult<BoxFuture<'static, VortexResult<ArrayRef>>> {
293-
let dtype = expr.return_dtype(self.dtype())?;
294294
if row_range.is_empty() {
295-
return Ok(future::ready(Ok(Canonical::empty(&dtype).into_array())).boxed());
295+
return Ok(future::ready(Ok(
296+
Canonical::empty(&expr.return_dtype(self.dtype())?).into_array()
297+
))
298+
.boxed());
296299
}
297300

298301
let mut chunk_evals = vec![];
@@ -311,13 +314,16 @@ impl LayoutReader for ChunkedReader {
311314
// Split the mask over each chunk.
312315
let chunks: Vec<_> = FuturesOrdered::from_iter(chunk_evals).try_collect().await?;
313316

317+
vortex_ensure!(!chunks.is_empty(), "Empty chunks were checked earlier");
318+
314319
// If there is only one chunk, we can return it directly.
315320
if chunks.len() == 1 {
316321
return Ok(chunks.into_iter().next().vortex_expect("one chunk"));
317322
}
318323

324+
let return_dtype = chunks[0].dtype().clone();
319325
// Combine the arrays.
320-
Ok(ChunkedArray::try_new(chunks, dtype)?.into_array())
326+
Ok(ChunkedArray::try_new(chunks, return_dtype)?.into_array())
321327
}
322328
.boxed())
323329
}

0 commit comments

Comments
 (0)