You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "waynexia (via GitHub)" <gi...@apache.org> on 2024/02/10 16:04:06 UTC
[PR] feat: replace std Instant with wasm-compatible wrapper [arrow-datafusion]
waynexia opened a new pull request, #9189:
URL: https://github.com/apache/arrow-datafusion/pull/9189
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Relates to https://github.com/apache/arrow-datafusion/issues/7651 and #7652
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
`std::time::Instant` doesn't work on target `wasm32-unknown-unknown`. It would result in a runtime panic when using it. A detailed explanation can be found in the replacement wrapper crate `instant`'s [repository](https://github.com/sebcrozet/instant?tab=readme-ov-file#instant).
It doesn't have a difference when runs on other platforms.
## What changes are included in this PR?
Replace all the occurrences of `std::time::Instant` with `instant::Instant`.
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
## Are these changes tested?
Yes
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
There is no difference on platforms other than `wasm32-unknown-unknown`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: replace std Instant with wasm-compatible wrapper [arrow-datafusion]
Posted by "DDtKey (via GitHub)" <gi...@apache.org>.
DDtKey commented on code in PR #9189:
URL: https://github.com/apache/arrow-datafusion/pull/9189#discussion_r1504553431
##########
datafusion/common/src/wasm.rs:
##########
Review Comment:
Just one question:
it's wrapper for `Instant`, but module name is `wasm` while "wasm" it or not depends on target family
A 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#L28
Shouldn't it be `common::instant::Instant` instead? This way we fully encapsulate wrapper and can easily extend in the future if we wish
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: replace std Instant with wasm-compatible wrapper [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #9189:
URL: https://github.com/apache/arrow-datafusion/pull/9189#discussion_r1504511738
##########
datafusion/wasmtest/src/lib.rs:
##########
@@ -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 {
Review Comment:
💯 for the test
##########
datafusion/common/src/wasm.rs:
##########
@@ -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")]
Review Comment:
👍
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: replace std Instant with wasm-compatible wrapper [arrow-datafusion]
Posted by "DDtKey (via GitHub)" <gi...@apache.org>.
DDtKey commented on code in PR #9189:
URL: https://github.com/apache/arrow-datafusion/pull/9189#discussion_r1504553431
##########
datafusion/common/src/wasm.rs:
##########
Review Comment:
Just one question:
it's wrapper for `Instant`, but module name is `wasm` while "wasm" it or not depends on target family
A 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#L28
Shouldn't it be `datafusion_common::instant::Instant` instead? This way we fully encapsulate wrapper and can easily extend in the future if we wish
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: replace std Instant with wasm-compatible wrapper [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #9189:
URL: https://github.com/apache/arrow-datafusion/pull/9189
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: replace std Instant with wasm-compatible wrapper [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #9189:
URL: https://github.com/apache/arrow-datafusion/pull/9189#discussion_r1505878260
##########
clippy.toml:
##########
@@ -2,3 +2,7 @@ disallowed-methods = [
{ path = "tokio::task::spawn", reason = "To provide cancel-safety, use `SpawnedTask::spawn` instead (https://github.com/apache/arrow-datafusion/issues/6513)" },
{ path = "tokio::task::spawn_blocking", reason = "To provide cancel-safety, use `SpawnedTask::spawn` instead (https://github.com/apache/arrow-datafusion/issues/6513)" },
]
+
+disallowed-types = [
+ { path = "std::time::Instant", reason = "Use `datafusion_common::instant::Instant` instead for WASM compatibility" },
Review Comment:
👍
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: replace std Instant with wasm-compatible wrapper [arrow-datafusion]
Posted by "waynexia (via GitHub)" <gi...@apache.org>.
waynexia commented on code in PR #9189:
URL: https://github.com/apache/arrow-datafusion/pull/9189#discussion_r1493801417
##########
datafusion/wasmtest/src/lib.rs:
##########
@@ -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 {
+ 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();
Review Comment:
```suggestion
let statement = DFParser::parse_sql(sql).unwrap().pop_back().unwrap();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: replace std Instant with wasm-compatible wrapper [arrow-datafusion]
Posted by "waynexia (via GitHub)" <gi...@apache.org>.
waynexia commented on code in PR #9189:
URL: https://github.com/apache/arrow-datafusion/pull/9189#discussion_r1505322515
##########
datafusion/common/src/wasm.rs:
##########
Review Comment:
Makes sense 👍 please see [c823e38](https://github.com/apache/arrow-datafusion/pull/9189/commits/c823e3885b09a5df1e5508ab32813e3a7f17ca7a)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: replace std Instant with wasm-compatible wrapper [arrow-datafusion]
Posted by "DDtKey (via GitHub)" <gi...@apache.org>.
DDtKey commented on PR #9189:
URL: https://github.com/apache/arrow-datafusion/pull/9189#issuecomment-1968864318
> I find disallowed_type works for our case: https://github.com/apache/arrow-datafusion/commit/edb67fae06bbddb080fae7e6b57b97d5236f8c56, it seems work by matching the import types and won't follow type alias 😉
That's nice!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: replace std Instant with wasm-compatible wrapper [arrow-datafusion]
Posted by "DDtKey (via GitHub)" <gi...@apache.org>.
DDtKey commented on PR #9189:
URL: https://github.com/apache/arrow-datafusion/pull/9189#issuecomment-1968041152
>I wonder if you want to put an "exclude" type lint in to prevent people from accidentally using std::time::Instant
Unfortunately, I think it's not possible "as is" for this case, because it's actually just a type alias. However new-type pattern may work (wrap `Instant` into new type instead of type-alias)
Somebody already tried, btw: https://github.com/rust-lang/rust-clippy/issues/10406
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: replace std Instant with wasm-compatible wrapper [arrow-datafusion]
Posted by "waynexia (via GitHub)" <gi...@apache.org>.
waynexia commented on PR #9189:
URL: https://github.com/apache/arrow-datafusion/pull/9189#issuecomment-1968167780
> > I wonder if you want to put an "exclude" type lint in to prevent people from accidentally using std::time::Instant
>
> Unfortunately, I think it's not possible "as is" for this case, because it's actually just a type alias. However new-type pattern would work (wrap `Instant` into new type instead of type-alias)
>
> Somebody already tried, btw: [rust-lang/rust-clippy#10406](https://github.com/rust-lang/rust-clippy/issues/10406)
TIL, thanks for your information.
I find `disallowed_type` works for our case: https://github.com/apache/arrow-datafusion/pull/9189/commits/edb67fae06bbddb080fae7e6b57b97d5236f8c56, it seems work by matching the import types and won't follow type alias 😉
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: replace std Instant with wasm-compatible wrapper [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #9189:
URL: https://github.com/apache/arrow-datafusion/pull/9189#discussion_r1505205686
##########
datafusion/common/src/wasm.rs:
##########
Review Comment:
> Shouldn't it be `datafusion_common::instant::Instant` instead? This way we fully encapsulate wrapper and can easily extend in the future if we wish
I agree this would be a better home
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: replace std Instant with wasm-compatible wrapper [arrow-datafusion]
Posted by "DDtKey (via GitHub)" <gi...@apache.org>.
DDtKey commented on code in PR #9189:
URL: https://github.com/apache/arrow-datafusion/pull/9189#discussion_r1505866368
##########
datafusion/common/src/instant.rs:
##########
@@ -0,0 +1,28 @@
+// 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-compatible `Instant` warpper.
Review Comment:
Just a typo 🙂
```suggestion
//! WASM-compatible `Instant` wrapper.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: replace std Instant with wasm-compatible wrapper [arrow-datafusion]
Posted by "waynexia (via GitHub)" <gi...@apache.org>.
waynexia commented on PR #9189:
URL: https://github.com/apache/arrow-datafusion/pull/9189#issuecomment-1951333222
I've extracted all the references into `datafusion_common` and added a target family gateway. Now the implementation of `Instant` will switch automatically when compiling under `wasm32-unknown-unknown`.
I also extended `wasmtest` to include unit tests, which can be run by `wasm-pack test`. Refer to `datafusion/wasmtest/README.md` for detailed commands. Noticed that I haven't added CI for it, because the `--headless` mode has some unknown problem and would timeout in my environment. Once I fix it we can have a CI about wasm by following the link I added in `README.md`.
The lock file of `datafusion-cli` still contains `instant` crate. This seems to be a bug of cargo: https://github.com/rust-lang/cargo/issues/10801. I've tested that it won't be used in actual.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: replace std Instant with wasm-compatible wrapper [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #9189:
URL: https://github.com/apache/arrow-datafusion/pull/9189#issuecomment-1948240498
Marking as draft as I don't think this PR is waiting on review anymore and I am trying to clear the review queue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: replace std Instant with wasm-compatible wrapper [arrow-datafusion]
Posted by "DDtKey (via GitHub)" <gi...@apache.org>.
DDtKey commented on code in PR #9189:
URL: https://github.com/apache/arrow-datafusion/pull/9189#discussion_r1504553431
##########
datafusion/common/src/wasm.rs:
##########
Review Comment:
Just one question:
it's wrapper for `Instant`, but module name is `wasm` while "wasm" it or not depends on target family
A 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#L28)
Shouldn't it be `common::instant::Instant` instead? This way we fully encapsulate wrapper
##########
datafusion/common/src/wasm.rs:
##########
Review Comment:
Just one question:
it's wrapper for `Instant`, but module name is `wasm` while "wasm" it or not depends on target family
A 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#L28
Shouldn't it be `common::instant::Instant` instead? This way we fully encapsulate wrapper
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org