Skip to content

Commit

Permalink
fix: add stub functions for wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi committed Dec 30, 2024
1 parent 14b234c commit 28df000
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 25 deletions.
35 changes: 24 additions & 11 deletions src/rust/src/expr/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
Ok(self
.inner
.clone()
.str()
.json_path_match(pat.inner.clone())
.into())
}

// fn str_json_decode(&self, dtype: &PlRExpr, infer_schema_len: &PlRExpr) -> Result<Self> {
// let dtype = robj_to!(Option, RPolarsDataType, dtype)?.map(|dty| dty.0);
// let infer_schema_len = robj_to!(Option, usize, infer_schema_len)?;
Expand Down Expand Up @@ -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 <https://github.com/yutannihilation/savvy/issues/333>
#[cfg(not(target_arch = "wasm32"))]
#[savvy]
impl PlRExpr {
fn str_json_path_match(&self, pat: &PlRExpr) -> Result<Self> {
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<Self> {
Err(RPolarsErr::Other(format!("`Not supported in WASM")).into())
}
}
25 changes: 19 additions & 6 deletions src/rust/src/expr/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
Ok(self.inner.clone().struct_().json_encode().into())
}

fn struct_with_fields(&self, fields: ListSexp) -> Result<Self> {
let fields = <Wrap<Vec<Expr>>>::from(fields).0;
let e = self
Expand All @@ -43,3 +37,22 @@ impl PlRExpr {
Ok(e.into())
}
}

// TODO: Refactor with adding `json` feature as like Python Polars
// FIXME: Work around for <https://github.com/yutannihilation/savvy/issues/333>
#[cfg(not(target_arch = "wasm32"))]
#[savvy]
impl PlRExpr {
fn struct_json_encode(&self) -> Result<Self> {
Ok(self.inner.clone().struct_().json_encode().into())
}
}

#[cfg(target_arch = "wasm32")]
#[savvy]
impl PlRExpr {
#[allow(unused_variables)]
fn struct_json_encode(&self) -> Result<Self> {
Err(RPolarsErr::Other(format!("`Not supported in WASM")).into())
}
}
66 changes: 58 additions & 8 deletions src/rust/src/lazyframe/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl PlRLazyFrame {
};

#[cfg(target_arch = "wasm32")]
let cloud_options = None;
let cloud_options: Option<Vec<(String, String)>> = None;

let mut args = ScanArgsIpc {
n_rows,
Expand Down Expand Up @@ -411,7 +411,7 @@ impl PlRLazyFrame {
};

#[cfg(target_arch = "wasm32")]
let cloud_options = None;
let cloud_options: Option<Vec<(String, String)>> = None;

let mut r = LazyCsvReader::new_paths(source.clone().into());
let first_path: Option<PathBuf> = source.first().unwrap().clone().into();
Expand Down Expand Up @@ -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 <https://github.com/yutannihilation/savvy/issues/333>
#[cfg(not(target_arch = "wasm32"))]
#[savvy]
impl PlRLazyFrame {
fn new_from_parquet(
source: StringSexp,
cache: bool,
Expand Down Expand Up @@ -551,7 +554,7 @@ impl PlRLazyFrame {
};

#[cfg(target_arch = "wasm32")]
let cloud_options = None;
let cloud_options: Option<Vec<(String, String)>> = None;

// TODO: Refactor with adding `cloud` feature as like Python Polars
#[cfg(not(target_arch = "wasm32"))]
Expand All @@ -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,
Expand Down Expand Up @@ -645,7 +646,7 @@ impl PlRLazyFrame {
};

#[cfg(target_arch = "wasm32")]
let cloud_options = None;
let cloud_options: Option<Vec<(String, String)>> = None;

// TODO: Refactor with adding `cloud` feature as like Python Polars
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -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<StringSexp>,
n_rows: Option<NumericScalar>,
row_index_name: Option<&str>,
hive_partitioning: Option<bool>,
schema: Option<ListSexp>,
hive_schema: Option<ListSexp>,
include_file_paths: Option<&str>,
) -> Result<Self> {
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<NumericScalar>,
schema: Option<ListSexp>,
schema_overrides: Option<ListSexp>,
batch_size: Option<NumericScalar>,
n_rows: Option<NumericScalar>,
include_file_paths: Option<&str>,
storage_options: Option<StringSexp>,
file_cache_ttl: Option<NumericScalar>,
) -> Result<Self> {
Err(RPolarsErr::Other(format!("`Not supported in WASM")).into())
}
}

0 comments on commit 28df000

Please sign in to comment.