Skip to content

Commit a042672

Browse files
authored
perf: Skip validation step for attributes of S7 objects on the R side (#1634)
1 parent 073ec73 commit a042672

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

R/functions-lazy.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ pl__collect_all <- function(
157157
# TODO: add support for argument `optimizations`
158158
optflags <- QueryOptFlags()
159159
check_is_S7(optflags, QueryOptFlags)
160-
validate(optflags)
161160

162161
lfs <- lapply(lazy_frames, \(x) x$`_ldf`)
163162

src/rust/src/conversion/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use categorical::PlRCategories;
66
use polars::series::ops::NullBehavior;
77
use savvy::{
88
ListSexp, NotAvailableValue, NumericScalar, NumericSexp, NumericTypedSexp, Sexp, StringSexp,
9-
TypedSexp,
9+
TypedSexp, savvy_err,
1010
};
1111
use search_sorted::SearchSortedSide;
1212
use std::{num::NonZeroUsize, str::FromStr};
@@ -40,6 +40,12 @@ impl<T> From<T> for Wrap<T> {
4040
}
4141
}
4242

43+
// TODO: Move this to upstream?
44+
pub(crate) fn try_extract_attribute(obj: &Sexp, attr_name: &str) -> savvy::Result<Sexp> {
45+
obj.get_attrib(attr_name)?
46+
.ok_or(savvy_err!("Attribute '{attr_name}' does not exist."))
47+
}
48+
4349
impl TryFrom<&str> for PlRDataType {
4450
type Error = String;
4551

src/rust/src/conversion/s7.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
use super::try_extract_attribute;
12
use crate::lazyframe::PlROptFlags;
2-
use savvy::{Sexp, TypedSexp};
3+
use savvy::Sexp;
34

45
impl TryFrom<Sexp> for PlROptFlags {
56
type Error = savvy::Error;
@@ -23,13 +24,10 @@ impl TryFrom<Sexp> for PlROptFlags {
2324
"streaming",
2425
];
2526

26-
ATTR_NAMES.iter().for_each(|attr_name| {
27-
// Safety: validated on the R side
28-
let attr_value = match obj.get_attrib(attr_name).unwrap().unwrap().into_typed() {
29-
TypedSexp::Logical(l) => l.iter().next().unwrap(),
30-
_ => unreachable!(),
31-
};
32-
match *attr_name {
27+
for &attr_name in ATTR_NAMES {
28+
let attr_value: bool = try_extract_attribute(&obj, attr_name)?.try_into()?;
29+
30+
match attr_name {
3331
"type_coercion" => opts.set_type_coercion(attr_value),
3432
"type_check" => opts.set_type_check(attr_value),
3533
"predicate_pushdown" => opts.set_predicate_pushdown(attr_value),
@@ -45,7 +43,7 @@ impl TryFrom<Sexp> for PlROptFlags {
4543
"streaming" => opts.set_streaming(attr_value),
4644
_ => unreachable!(),
4745
}
48-
});
46+
}
4947
Ok(opts)
5048
}
5149
}

0 commit comments

Comments
 (0)