|
| 1 | +#![cfg(target_arch = "wasm32")] |
| 2 | +#![allow(clippy::suspicious_map)] |
| 3 | + |
| 4 | +use std::path::PathBuf; |
| 5 | +use wasm_bindgen::prelude::*; |
| 6 | +use wasm_bindgen_test::{wasm_bindgen_test, wasm_bindgen_test_configure}; |
| 7 | + |
| 8 | +use amadeus::prelude::*; |
| 9 | + |
| 10 | +wasm_bindgen_test_configure!(run_in_browser); |
| 11 | + |
| 12 | +#[wasm_bindgen] |
| 13 | +extern "C" { |
| 14 | + #[wasm_bindgen(js_namespace = console)] |
| 15 | + fn log(s: &str); |
| 16 | +} |
| 17 | +macro_rules! print { |
| 18 | + ($($t:tt)*) => (log(&format_args!($($t)*).to_string())); |
| 19 | +} |
| 20 | +macro_rules! println { |
| 21 | + ($fmt:expr) => (print!(concat!($fmt, "\n"))); |
| 22 | + ($fmt:expr, $($t:tt)*) => (print!(concat!($fmt, "\n"), $($t)*)); |
| 23 | +} |
| 24 | + |
| 25 | +#[no_mangle] |
| 26 | +pub extern "C" fn malloc(_size: usize) -> *mut std::ffi::c_void { |
| 27 | + panic!() |
| 28 | +} |
| 29 | +#[no_mangle] |
| 30 | +pub extern "C" fn free(_ptr: *mut std::ffi::c_void) { |
| 31 | + panic!() |
| 32 | +} |
| 33 | +#[no_mangle] |
| 34 | +pub extern "C" fn calloc(_nmemb: usize, _size: usize) -> *mut std::ffi::c_void { |
| 35 | + panic!() |
| 36 | +} |
| 37 | +#[no_mangle] |
| 38 | +pub extern "C" fn realloc(_ptr: *mut std::ffi::c_void, _size: usize) -> *mut std::ffi::c_void { |
| 39 | + panic!() |
| 40 | +} |
| 41 | + |
| 42 | +#[wasm_bindgen_test] |
| 43 | +async fn parquet() { |
| 44 | + let timer = web_sys::window().unwrap().performance().unwrap(); |
| 45 | + let start = timer.now(); |
| 46 | + |
| 47 | + let pool = &ThreadPool::new(None).unwrap(); |
| 48 | + |
| 49 | + let rows = Parquet::<_, Value>::new(vec![ |
| 50 | + PathBuf::from("amadeus-testing/parquet/cf-accesslogs/year=2018/month=11/day=02/part-00176-17868f39-cd99-4b60-bb48-8daf9072122e.c000.snappy.parquet"), |
| 51 | + PathBuf::from("amadeus-testing/parquet/cf-accesslogs/year=2018/month=11/day=02/part-00176-ed461019-4a12-46fa-a3f3-246d58f0ee06.c000.snappy.parquet"), |
| 52 | + PathBuf::from("amadeus-testing/parquet/cf-accesslogs/year=2018/month=11/day=03/part-00137-17868f39-cd99-4b60-bb48-8daf9072122e.c000.snappy.parquet"), |
| 53 | + PathBuf::from("amadeus-testing/parquet/cf-accesslogs/year=2018/month=11/day=04/part-00173-17868f39-cd99-4b60-bb48-8daf9072122e.c000.snappy.parquet"), |
| 54 | + PathBuf::from("amadeus-testing/parquet/cf-accesslogs/year=2018/month=11/day=05/part-00025-17868f39-cd99-4b60-bb48-8daf9072122e.c000.snappy.parquet"), |
| 55 | + PathBuf::from("amadeus-testing/parquet/cf-accesslogs/year=2018/month=11/day=05/part-00025-96c249f4-3a10-4509-b6b8-693a5d90dbf3.c000.snappy.parquet"), |
| 56 | + PathBuf::from("amadeus-testing/parquet/cf-accesslogs/year=2018/month=11/day=06/part-00185-96c249f4-3a10-4509-b6b8-693a5d90dbf3.c000.snappy.parquet"), |
| 57 | + PathBuf::from("amadeus-testing/parquet/cf-accesslogs/year=2018/month=11/day=07/part-00151-96c249f4-3a10-4509-b6b8-693a5d90dbf3.c000.snappy.parquet"), |
| 58 | + ]).await.unwrap(); |
| 59 | + assert_eq!( |
| 60 | + rows.par_stream() |
| 61 | + .map(|row: Result<_, _>| row.unwrap()) |
| 62 | + .count(pool) |
| 63 | + .await, |
| 64 | + 207_535 |
| 65 | + ); |
| 66 | + |
| 67 | + let elapsed = timer.now() - start; |
| 68 | + println!("in {}s", elapsed / 1000.0); |
| 69 | +} |
0 commit comments