-
Notifications
You must be signed in to change notification settings - Fork 30
feature: add support for slicing above i32 where u64 can safely be coerced to f64 losslessly #861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
fedef7d
d921288
f9baa54
61fa689
05c2c0c
d4afa80
735e7a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,11 +7,13 @@ use crate::common::fetch::{ | |||||
| use crate::error::{Result, WasmResult}; | ||||||
| use crate::read_options::{JsReaderOptions, ReaderOptions}; | ||||||
| use crate::reader::cast_metadata_view_types; | ||||||
| use crate::utils; | ||||||
| use futures::channel::oneshot; | ||||||
| use futures::future::BoxFuture; | ||||||
| use object_store::coalesce_ranges; | ||||||
| use std::ops::Range; | ||||||
| use std::sync::Arc; | ||||||
| use std::io; | ||||||
| use wasm_bindgen::prelude::*; | ||||||
| use wasm_bindgen_futures::spawn_local; | ||||||
|
|
||||||
|
|
@@ -320,21 +322,20 @@ impl WrappedFile { | |||||
| Self { inner, size } | ||||||
| } | ||||||
|
|
||||||
| pub async fn get_bytes(&mut self, range: Range<u64>) -> Vec<u8> { | ||||||
| pub async fn get_bytes(&mut self, range: Range<u64>) -> io::Result<Vec<u8>> { | ||||||
| use js_sys::Uint8Array; | ||||||
| use wasm_bindgen_futures::JsFuture; | ||||||
| let (sender, receiver) = oneshot::channel(); | ||||||
| let file = self.inner.clone(); | ||||||
| spawn_local(async move { | ||||||
| let subset_blob = file | ||||||
| .slice_with_i32_and_i32( | ||||||
| range.start.try_into().unwrap(), | ||||||
| range.end.try_into().unwrap(), | ||||||
| ) | ||||||
| .unwrap(); | ||||||
| let buf = JsFuture::from(subset_blob.array_buffer()).await.unwrap(); | ||||||
| let out_vec = Uint8Array::new_with_byte_offset(&buf, 0).to_vec(); | ||||||
| sender.send(out_vec).unwrap(); | ||||||
| if range.start <= utils::MAX_EXACT_INTEGER && range.end <= utils::MAX_EXACT_INTEGER { | ||||||
| let subset_blob = file.slice_with_f64_and_f64(range.start as f64, range.end as f64).unwrap(); | ||||||
| let buf = JsFuture::from(subset_blob.array_buffer()).await.unwrap(); | ||||||
| let out_vec = Uint8Array::new_with_byte_offset(&buf, 0).to_vec(); | ||||||
| sender.send(Ok(out_vec)).unwrap(); | ||||||
| } else { | ||||||
| sender.send(Err(io::Error::new(io::ErrorKind::Unsupported, format!("{range:?} is too large to convert into a Blob slice")))).unwrap(); | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be a Lines 18 to 19 in d9e9e1f
since JS in the web doesn't support a slice larger than a |
||||||
| }; | ||||||
| }); | ||||||
|
|
||||||
| receiver.await.unwrap() | ||||||
|
|
@@ -347,10 +348,13 @@ async fn get_bytes_file( | |||||
| ) -> parquet::errors::Result<Bytes> { | ||||||
| let (sender, receiver) = oneshot::channel(); | ||||||
| spawn_local(async move { | ||||||
| let result: Bytes = file.get_bytes(range).await.into(); | ||||||
| let result = match file.get_bytes(range).await { | ||||||
| Ok(result) => Ok(Bytes::from(result)), | ||||||
| Err(e) => Err(e) | ||||||
| }; | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just use |
||||||
| sender.send(result).unwrap() | ||||||
| }); | ||||||
| let data = receiver.await.unwrap(); | ||||||
| let data = receiver.await.unwrap()?; | ||||||
| Ok(data) | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -375,11 +379,11 @@ impl AsyncFileReader for JsFileReader { | |||||
| let (sender, receiver) = oneshot::channel(); | ||||||
| let mut file = self.file.clone(); | ||||||
| spawn_local(async move { | ||||||
| let result: Bytes = file.get_bytes(range).await.into(); | ||||||
| let result = file.get_bytes(range).await.map(Bytes::from); | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like you did here |
||||||
| sender.send(result).unwrap() | ||||||
| }); | ||||||
| let data = receiver.await.unwrap(); | ||||||
| Ok(data) | ||||||
| Ok(data?) | ||||||
| } | ||||||
| .boxed() | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have a result type in this crate
parquet-wasm/src/error.rs
Lines 24 to 25 in d9e9e1f