From 28df000fe6af3b15a2ad5a8875dfb8dd233e1a29 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Mon, 30 Dec 2024 03:11:49 +0000 Subject: [PATCH] fix: add stub functions for wasm --- src/rust/src/expr/string.rs | 35 ++++++++++------ src/rust/src/expr/struct.rs | 25 +++++++++--- src/rust/src/lazyframe/general.rs | 66 +++++++++++++++++++++++++++---- 3 files changed, 101 insertions(+), 25 deletions(-) diff --git a/src/rust/src/expr/string.rs b/src/rust/src/expr/string.rs index 6645f280..c5db23af 100644 --- a/src/rust/src/expr/string.rs +++ b/src/rust/src/expr/string.rs @@ -111,17 +111,6 @@ impl PlRExpr { .into()) } - // TODO: Refactor with adding `extract_jsonpath` feature as like Python Polars - #[cfg(not(target_arch = "wasm32"))] - fn str_json_path_match(&self, pat: &PlRExpr) -> Result { - Ok(self - .inner - .clone() - .str() - .json_path_match(pat.inner.clone()) - .into()) - } - // fn str_json_decode(&self, dtype: &PlRExpr, infer_schema_len: &PlRExpr) -> Result { // let dtype = robj_to!(Option, RPolarsDataType, dtype)?.map(|dty| dty.0); // let infer_schema_len = robj_to!(Option, usize, infer_schema_len)?; @@ -405,3 +394,27 @@ impl PlRExpr { Ok(self.inner.clone().str().tail(n.inner.clone()).into()) } } + +// TODO: Refactor with adding `extract_jsonpath` feature as like Python Polars +// FIXME: Work around for +#[cfg(not(target_arch = "wasm32"))] +#[savvy] +impl PlRExpr { + fn str_json_path_match(&self, pat: &PlRExpr) -> Result { + Ok(self + .inner + .clone() + .str() + .json_path_match(pat.inner.clone()) + .into()) + } +} + +#[cfg(target_arch = "wasm32")] +#[savvy] +impl PlRExpr { + #[allow(unused_variables)] + fn str_json_path_match(&self, pat: &PlRExpr) -> Result { + Err(RPolarsErr::Other(format!("`Not supported in WASM")).into()) + } +} \ No newline at end of file diff --git a/src/rust/src/expr/struct.rs b/src/rust/src/expr/struct.rs index e603ad45..eb67b3d5 100644 --- a/src/rust/src/expr/struct.rs +++ b/src/rust/src/expr/struct.rs @@ -26,12 +26,6 @@ impl PlRExpr { .into()) } - // TODO: Refactor with adding `json` feature as like Python Polars - #[cfg(not(target_arch = "wasm32"))] - fn struct_json_encode(&self) -> Result { - Ok(self.inner.clone().struct_().json_encode().into()) - } - fn struct_with_fields(&self, fields: ListSexp) -> Result { let fields = >>::from(fields).0; let e = self @@ -43,3 +37,22 @@ impl PlRExpr { Ok(e.into()) } } + +// TODO: Refactor with adding `json` feature as like Python Polars +// FIXME: Work around for +#[cfg(not(target_arch = "wasm32"))] +#[savvy] +impl PlRExpr { + fn struct_json_encode(&self) -> Result { + Ok(self.inner.clone().struct_().json_encode().into()) + } +} + +#[cfg(target_arch = "wasm32")] +#[savvy] +impl PlRExpr { + #[allow(unused_variables)] + fn struct_json_encode(&self) -> Result { + Err(RPolarsErr::Other(format!("`Not supported in WASM")).into()) + } +} diff --git a/src/rust/src/lazyframe/general.rs b/src/rust/src/lazyframe/general.rs index 1389d17f..998c1377 100644 --- a/src/rust/src/lazyframe/general.rs +++ b/src/rust/src/lazyframe/general.rs @@ -268,7 +268,7 @@ impl PlRLazyFrame { }; #[cfg(target_arch = "wasm32")] - let cloud_options = None; + let cloud_options: Option> = None; let mut args = ScanArgsIpc { n_rows, @@ -411,7 +411,7 @@ impl PlRLazyFrame { }; #[cfg(target_arch = "wasm32")] - let cloud_options = None; + let cloud_options: Option> = None; let mut r = LazyCsvReader::new_paths(source.clone().into()); let first_path: Option = source.first().unwrap().clone().into(); @@ -459,9 +459,12 @@ impl PlRLazyFrame { Ok(r.finish().map_err(RPolarsErr::from)?.into()) } +} - // TODO: Refactor with adding `parquet` feature as like Python Polars - #[cfg(not(target_arch = "wasm32"))] +// FIXME: Work around for +#[cfg(not(target_arch = "wasm32"))] +#[savvy] +impl PlRLazyFrame { fn new_from_parquet( source: StringSexp, cache: bool, @@ -551,7 +554,7 @@ impl PlRLazyFrame { }; #[cfg(target_arch = "wasm32")] - let cloud_options = None; + let cloud_options: Option> = None; // TODO: Refactor with adding `cloud` feature as like Python Polars #[cfg(not(target_arch = "wasm32"))] @@ -567,8 +570,6 @@ impl PlRLazyFrame { Ok(lf.into()) } - // TODO: Refactor with adding `json` feature as like Python Polars - #[cfg(not(target_arch = "wasm32"))] fn new_from_ndjson( source: StringSexp, low_memory: bool, @@ -645,7 +646,7 @@ impl PlRLazyFrame { }; #[cfg(target_arch = "wasm32")] - let cloud_options = None; + let cloud_options: Option> = None; // TODO: Refactor with adding `cloud` feature as like Python Polars #[cfg(not(target_arch = "wasm32"))] @@ -680,3 +681,52 @@ impl PlRLazyFrame { Ok(lf.into()) } } + +#[cfg(target_arch = "wasm32")] +#[savvy] +impl PlRLazyFrame { + #[allow(unused_variables)] + fn new_from_parquet( + source: StringSexp, + cache: bool, + parallel: &str, + rechunk: bool, + low_memory: bool, + use_statistics: bool, + try_parse_hive_dates: bool, + retries: NumericScalar, + glob: bool, + allow_missing_columns: bool, + row_index_offset: NumericScalar, + storage_options: Option, + n_rows: Option, + row_index_name: Option<&str>, + hive_partitioning: Option, + schema: Option, + hive_schema: Option, + include_file_paths: Option<&str>, + ) -> Result { + Err(RPolarsErr::Other(format!("`Not supported in WASM")).into()) + } + + #[allow(unused_variables)] + fn new_from_ndjson( + source: StringSexp, + low_memory: bool, + rechunk: bool, + ignore_errors: bool, + retries: NumericScalar, + row_index_offset: NumericScalar, + row_index_name: Option<&str>, + infer_schema_length: Option, + schema: Option, + schema_overrides: Option, + batch_size: Option, + n_rows: Option, + include_file_paths: Option<&str>, + storage_options: Option, + file_cache_ttl: Option, + ) -> Result { + Err(RPolarsErr::Other(format!("`Not supported in WASM")).into()) + } +}