-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the same implementation for all types, so we can move to a generic `length` evaluator when we move to `sparrow-expressions` package.
- Loading branch information
1 parent
6db60f0
commit 8e2b748
Showing
6 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
crates/sparrow-instructions/src/evaluators/list/list_len.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use arrow::array::ArrayRef; | ||
|
||
use arrow_schema::DataType; | ||
use sparrow_plan::ValueRef; | ||
use std::sync::Arc; | ||
|
||
use crate::{Evaluator, EvaluatorFactory, StaticInfo}; | ||
|
||
/// Evaluator for `len` on lists. | ||
/// | ||
/// Produces the length of the list. | ||
#[derive(Debug)] | ||
pub(in crate::evaluators) struct ListLenEvaluator { | ||
list: ValueRef, | ||
} | ||
|
||
impl EvaluatorFactory for ListLenEvaluator { | ||
fn try_new(info: StaticInfo<'_>) -> anyhow::Result<Box<dyn Evaluator>> { | ||
let input_type = info.args[0].data_type.clone(); | ||
match input_type { | ||
DataType::List(_) => (), | ||
other => anyhow::bail!("expected list type, saw {:?}", other), | ||
}; | ||
|
||
let list = info.unpack_argument()?; | ||
Ok(Box::new(Self { list })) | ||
} | ||
} | ||
|
||
impl Evaluator for ListLenEvaluator { | ||
fn evaluate(&mut self, info: &dyn crate::RuntimeInfo) -> anyhow::Result<ArrayRef> { | ||
let input = info.value(&self.list)?.array_ref()?; | ||
let result = arrow::compute::kernels::length::length(input.as_ref())?; | ||
Ok(Arc::new(result)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters