-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat: replace std Instant with wasm-compatible wrapper #9189
Merged
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
36dba53
feat: replace std Instant with wasm-compatible wrapper
waynexia 4394ad8
update cli's lock file
waynexia a556ae6
wrap instant in datafusion_common
waynexia 63872b2
write unit test
waynexia 56c7d0e
Merge branch 'main' into warp-std-instant
waynexia 7e3bf08
update lock file
waynexia cb16252
format toml
waynexia d19c1ef
Update datafusion/wasmtest/src/lib.rs
waynexia 857a2e3
Merge branch 'main' into warp-std-instant
waynexia 0bf8728
Merge branch 'main' into warp-std-instant
waynexia edb67fa
add clippy lint to prevent from using std Instant
waynexia c823e38
rename mod name from wasm to instant
waynexia d620e32
fix existing std instant reference
waynexia ad0686a
Update datafusion/common/src/instant.rs
waynexia 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
//! WASM-related utilities | ||
|
||
#[cfg(target_family = "wasm")] | ||
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. 👍 |
||
/// DataFusion wrapper around [`std::time::Instant`]. Uses [`instant::Instant`] | ||
/// under `wasm` feature gate. It provides the same API as [`std::time::Instant`]. | ||
pub type Instant = instant::Instant; | ||
|
||
#[cfg(not(target_family = "wasm"))] | ||
/// DataFusion wrapper around [`std::time::Instant`]. This is only a type alias. | ||
pub type Instant = std::time::Instant; |
This file contains 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 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 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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -17,4 +17,5 @@ | |
|
||
import * as wasm from "datafusion-wasmtest"; | ||
|
||
wasm.try_datafusion(); | ||
wasm.basic_exprs(); | ||
wasm.basic_parse(); |
This file contains 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 |
---|---|---|
|
@@ -44,7 +44,7 @@ extern "C" { | |
} | ||
|
||
#[wasm_bindgen] | ||
pub fn try_datafusion() { | ||
pub fn basic_exprs() { | ||
set_panic_hook(); | ||
// Create a scalar value (from datafusion-common) | ||
let scalar = ScalarValue::from("Hello, World!"); | ||
|
@@ -61,10 +61,67 @@ pub fn try_datafusion() { | |
ExprSimplifier::new(SimplifyContext::new(&execution_props).with_schema(schema)); | ||
let simplified_expr = simplifier.simplify(expr).unwrap(); | ||
log(&format!("Simplified Expr: {simplified_expr:?}")); | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn basic_parse() { | ||
// Parse SQL (using datafusion-sql) | ||
let sql = "SELECT 2 + 37"; | ||
let dialect = GenericDialect {}; // or AnsiDialect, or your own dialect ... | ||
let ast = Parser::parse_sql(&dialect, sql).unwrap(); | ||
log(&format!("Parsed SQL: {ast:?}")); | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
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. 💯 for the test |
||
use super::*; | ||
use datafusion::execution::context::SessionContext; | ||
use datafusion_execution::{ | ||
config::SessionConfig, | ||
disk_manager::DiskManagerConfig, | ||
runtime_env::{RuntimeConfig, RuntimeEnv}, | ||
}; | ||
use datafusion_physical_plan::collect; | ||
use datafusion_sql::parser::DFParser; | ||
use wasm_bindgen_test::wasm_bindgen_test; | ||
|
||
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); | ||
|
||
#[wasm_bindgen_test] | ||
fn datafusion_test() { | ||
basic_exprs(); | ||
basic_parse(); | ||
} | ||
|
||
#[wasm_bindgen_test] | ||
async fn basic_execute() { | ||
let sql = "SELECT 2 + 2;"; | ||
|
||
// Execute SQL (using datafusion) | ||
let rt = Arc::new( | ||
RuntimeEnv::new( | ||
RuntimeConfig::new().with_disk_manager(DiskManagerConfig::Disabled), | ||
) | ||
.unwrap(), | ||
); | ||
let session_config = SessionConfig::new().with_target_partitions(1); | ||
let session_context = | ||
Arc::new(SessionContext::new_with_config_rt(session_config, rt)); | ||
|
||
let statement = DFParser::parse_sql(&sql).unwrap().pop_back().unwrap(); | ||
waynexia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let logical_plan = session_context | ||
.state() | ||
.statement_to_plan(statement) | ||
.await | ||
.unwrap(); | ||
let data_frame = session_context | ||
.execute_logical_plan(logical_plan) | ||
.await | ||
.unwrap(); | ||
let physical_plan = data_frame.create_physical_plan().await.unwrap(); | ||
|
||
let task_ctx = session_context.task_ctx(); | ||
let _ = collect(physical_plan, task_ctx).await.unwrap(); | ||
} | ||
} |
Oops, something went wrong.
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.
Just one question:
it's wrapper for
Instant
, but module name iswasm
while "wasm" it or not depends on target familyA bit confusing to use
wasm::Instant
in code, like it's something specific, e.g https://github.com/apache/arrow-datafusion/blob/857a2e34299b7ec5be97b40a5019b15d0fc23bd0/datafusion/core/benches/parquet_query_sql.rs#L28Shouldn't it be
datafusion_common::instant::Instant
instead? This way we fully encapsulate wrapper and can easily extend in the future if we wishThere 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.
I agree this would be a better home
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.
Makes sense 👍 please see c823e38