You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/01/26 10:02:15 UTC
[GitHub] [arrow-rs] HaoYang670 opened a new pull request #1241: Add Rust Docs examples for UnionArray
HaoYang670 opened a new pull request #1241:
URL: https://github.com/apache/arrow-rs/pull/1241
Signed-off-by: remzi <13...@gmail.com>
# 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.
-->
Closes #751
# 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.
-->
Add 2 docs examples of building `UnionArray` using the function `UnionArray::try_new`,
so that users can easily understand the data structure of `UnionArray`.
# What changes are included in this PR?
<!---
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 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 `breaking change` label.
-->
--
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
[GitHub] [arrow-rs] alamb merged pull request #1241: Add Rust Docs examples for UnionArray
Posted by GitBox <gi...@apache.org>.
alamb merged pull request #1241:
URL: https://github.com/apache/arrow-rs/pull/1241
--
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
[GitHub] [arrow-rs] codecov-commenter commented on pull request #1241: Add Rust Docs examples for UnionArray
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #1241:
URL: https://github.com/apache/arrow-rs/pull/1241#issuecomment-1022060537
# [Codecov](https://codecov.io/gh/apache/arrow-rs/pull/1241?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#1241](https://codecov.io/gh/apache/arrow-rs/pull/1241?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (ff23910) into [master](https://codecov.io/gh/apache/arrow-rs/commit/794929835dd32f2c2e6897d7f606606e3e5aab29?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (7949298) will **decrease** coverage by `0.00%`.
> The diff coverage is `n/a`.
[![Impacted file tree graph](https://codecov.io/gh/apache/arrow-rs/pull/1241/graphs/tree.svg?width=650&height=150&src=pr&token=pq9V9qWZ1N&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/arrow-rs/pull/1241?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
```diff
@@ Coverage Diff @@
## master #1241 +/- ##
==========================================
- Coverage 82.94% 82.94% -0.01%
==========================================
Files 178 178
Lines 51420 51420
==========================================
- Hits 42651 42650 -1
- Misses 8769 8770 +1
```
| [Impacted Files](https://codecov.io/gh/apache/arrow-rs/pull/1241?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [arrow/src/array/array\_union.rs](https://codecov.io/gh/apache/arrow-rs/pull/1241/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-YXJyb3cvc3JjL2FycmF5L2FycmF5X3VuaW9uLnJz) | `90.76% <ø> (ø)` | |
| [arrow/src/datatypes/datatype.rs](https://codecov.io/gh/apache/arrow-rs/pull/1241/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-YXJyb3cvc3JjL2RhdGF0eXBlcy9kYXRhdHlwZS5ycw==) | `66.38% <0.00%> (-0.43%)` | :arrow_down: |
| [arrow/src/array/transform/mod.rs](https://codecov.io/gh/apache/arrow-rs/pull/1241/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-YXJyb3cvc3JjL2FycmF5L3RyYW5zZm9ybS9tb2QucnM=) | `84.51% <0.00%> (-0.13%)` | :arrow_down: |
| [parquet\_derive/src/parquet\_field.rs](https://codecov.io/gh/apache/arrow-rs/pull/1241/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGFycXVldF9kZXJpdmUvc3JjL3BhcnF1ZXRfZmllbGQucnM=) | `66.21% <0.00%> (+0.22%)` | :arrow_up: |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/arrow-rs/pull/1241?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/arrow-rs/pull/1241?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [7949298...ff23910](https://codecov.io/gh/apache/arrow-rs/pull/1241?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
--
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
[GitHub] [arrow-rs] matthewmturner commented on pull request #1241: Add Rust Docs examples for UnionArray
Posted by GitBox <gi...@apache.org>.
matthewmturner commented on pull request #1241:
URL: https://github.com/apache/arrow-rs/pull/1241#issuecomment-1023634762
thank you @HaoYang670
--
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
[GitHub] [arrow-rs] alamb commented on a change in pull request #1241: Add Rust Docs examples for UnionArray
Posted by GitBox <gi...@apache.org>.
alamb commented on a change in pull request #1241:
URL: https://github.com/apache/arrow-rs/pull/1241#discussion_r792584783
##########
File path: arrow/src/array/array_union.rs
##########
@@ -35,6 +35,73 @@ use std::any::Any;
/// [`UnionBuilder`]can be used to create `UnionArray`'s of primitive types. `UnionArray`'s of nested
/// types are also supported but not via `UnionBuilder`, see the tests for examples.
///
+/// # Examples
+/// ## Create a dense UnionArray `[1, 3.2, 34]`
+/// ```
+/// use arrow::buffer::Buffer;
+/// use arrow::datatypes::*;
+/// use std::sync::Arc;
+/// use arrow::array::{Array, Int32Array, Float64Array, UnionArray};
+///
+/// let int_array = Int32Array::from(vec![1, 34]);
+/// let float_array = Float64Array::from(vec![3.2]);
+/// let type_id_buffer = Buffer::from_slice_ref(&[0_i8, 1, 0]);
+/// let value_offsets_buffer = Buffer::from_slice_ref(&[0_i32, 0, 1]);
+///
+/// let children: Vec<(Field, Arc<dyn Array>)> = vec![
+/// (Field::new("A", DataType::Int32, false), Arc::new(int_array)),
+/// (Field::new("B", DataType::Float64, false), Arc::new(float_array)),
+/// ];
+///
+/// let array = UnionArray::try_new(
+/// type_id_buffer,
+/// Some(value_offsets_buffer),
+/// children,
+/// None,
+/// ).unwrap();
+///
+/// let value = array.value(0).as_any().downcast_ref::<Int32Array>().unwrap().value(0);
+/// assert_eq!(1, value);
+///
+/// let value = array.value(1).as_any().downcast_ref::<Float64Array>().unwrap().value(0);
+/// assert!(3.2 - value < f64::EPSILON);
+///
+/// let value = array.value(2).as_any().downcast_ref::<Int32Array>().unwrap().value(0);
+/// assert_eq!(34, value);
+/// ```
+///
+/// ## Create a sparse UnionArray `[1, 3.2, 34]`
+/// ```
+/// use arrow::buffer::Buffer;
+/// use arrow::datatypes::*;
+/// use std::sync::Arc;
+/// use arrow::array::{Array, Int32Array, Float64Array, UnionArray};
+///
+/// let int_array = Int32Array::from(vec![Some(1), None, Some(34)]);
+/// let float_array = Float64Array::from(vec![None, Some(3.2), None]);
+/// let type_id_buffer = Buffer::from_slice_ref(&[0_i8, 1, 0]);
+///
+/// let children: Vec<(Field, Arc<dyn Array>)> = vec![
+/// (Field::new("A", DataType::Int32, false), Arc::new(int_array)),
+/// (Field::new("B", DataType::Float64, false), Arc::new(float_array)),
+/// ];
+///
+/// let array = UnionArray::try_new(
+/// type_id_buffer,
+/// None,
+/// children,
+/// None,
+/// ).unwrap();
+///
+/// let value = array.value(0).as_any().downcast_ref::<Int32Array>().unwrap().value(0);
Review comment:
It isn't the nicest API in the world, is it ?
However, documenting what we have is 👍
Thank you @HaoYang670
--
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