-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add "end to end parquet reading test" for WASM #15362
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
Merged
alamb
merged 1 commit into
apache:main
from
jsai28:Add-end-to-end-parquet-reading-test-for-WASM
Mar 24, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,7 @@ pub fn basic_parse() { | |
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
use datafusion::execution::options::ParquetReadOptions; | ||
use datafusion::{ | ||
arrow::{ | ||
array::{ArrayRef, Int32Array, RecordBatch, StringArray}, | ||
|
@@ -90,12 +91,16 @@ mod test { | |
datasource::MemTable, | ||
execution::context::SessionContext, | ||
}; | ||
use datafusion_common::test_util::batches_to_string; | ||
use datafusion_execution::{ | ||
config::SessionConfig, disk_manager::DiskManagerConfig, | ||
runtime_env::RuntimeEnvBuilder, | ||
}; | ||
use datafusion_physical_plan::collect; | ||
use datafusion_sql::parser::DFParser; | ||
use insta::assert_snapshot; | ||
use object_store::{memory::InMemory, path::Path, ObjectStore}; | ||
use url::Url; | ||
use wasm_bindgen_test::wasm_bindgen_test; | ||
|
||
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); | ||
|
@@ -115,6 +120,22 @@ mod test { | |
let session_config = SessionConfig::new().with_target_partitions(1); | ||
Arc::new(SessionContext::new_with_config_rt(session_config, rt)) | ||
} | ||
|
||
fn create_test_data() -> (Arc<Schema>, RecordBatch) { | ||
let schema = Arc::new(Schema::new(vec![ | ||
Field::new("id", DataType::Int32, false), | ||
Field::new("value", DataType::Utf8, false), | ||
])); | ||
|
||
let data: Vec<ArrayRef> = vec![ | ||
Arc::new(Int32Array::from(vec![1, 2, 3])), | ||
Arc::new(StringArray::from(vec!["a", "b", "c"])), | ||
]; | ||
|
||
let batch = RecordBatch::try_new(schema.clone(), data).unwrap(); | ||
(schema, batch) | ||
} | ||
|
||
#[wasm_bindgen_test(unsupported = tokio::test)] | ||
async fn basic_execute() { | ||
let sql = "SELECT 2 + 2;"; | ||
|
@@ -185,26 +206,56 @@ mod test { | |
|
||
#[wasm_bindgen_test(unsupported = tokio::test)] | ||
async fn test_parquet_write() { | ||
let schema = Arc::new(Schema::new(vec![ | ||
Field::new("id", DataType::Int32, false), | ||
Field::new("value", DataType::Utf8, false), | ||
])); | ||
let (schema, batch) = create_test_data(); | ||
let mut buffer = Vec::new(); | ||
let mut writer = datafusion::parquet::arrow::ArrowWriter::try_new( | ||
&mut buffer, | ||
schema.clone(), | ||
None, | ||
) | ||
.unwrap(); | ||
|
||
let data: Vec<ArrayRef> = vec![ | ||
Arc::new(Int32Array::from(vec![1])), | ||
Arc::new(StringArray::from(vec!["a"])), | ||
]; | ||
writer.write(&batch).unwrap(); | ||
writer.close().unwrap(); | ||
} | ||
|
||
let batch = RecordBatch::try_new(schema.clone(), data).unwrap(); | ||
#[wasm_bindgen_test(unsupported = tokio::test)] | ||
async fn test_parquet_read_and_write() { | ||
let (schema, batch) = create_test_data(); | ||
let mut buffer = Vec::new(); | ||
let mut writer = datafusion::parquet::arrow::ArrowWriter::try_new( | ||
&mut buffer, | ||
schema.clone(), | ||
None, | ||
) | ||
.unwrap(); | ||
|
||
writer.write(&batch).unwrap(); | ||
writer.close().unwrap(); | ||
|
||
let session_ctx = SessionContext::new(); | ||
let store = InMemory::new(); | ||
|
||
let path = Path::from("a.parquet"); | ||
store.put(&path, buffer.into()).await.unwrap(); | ||
|
||
let url = Url::parse("memory://").unwrap(); | ||
session_ctx.register_object_store(&url, Arc::new(store)); | ||
|
||
let df = session_ctx | ||
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. love it |
||
.read_parquet("memory:///", ParquetReadOptions::new()) | ||
.await | ||
.unwrap(); | ||
|
||
let result = df.collect().await.unwrap(); | ||
|
||
assert_snapshot!(batches_to_string(&result), @r" | ||
+----+-------+ | ||
| id | value | | ||
+----+-------+ | ||
| 1 | a | | ||
| 2 | b | | ||
| 3 | c | | ||
+----+-------+ | ||
"); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It seems to me that this test is now redundant with "test_read_and_write" but looks good to me