-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Docs: Improve the documentation on ScalarValue
#8378
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
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
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 |
---|---|---|
|
@@ -50,9 +50,52 @@ use arrow::{ | |
use arrow_array::cast::as_list_array; | ||
use arrow_array::{ArrowNativeTypeOp, Scalar}; | ||
|
||
/// Represents a dynamically typed, nullable single value. | ||
/// This is the single-valued counter-part to arrow's [`Array`]. | ||
/// A dynamically typed, nullable single value, (the single-valued counter-part | ||
/// to arrow's [`Array`]) | ||
/// | ||
/// # Performance | ||
/// | ||
/// In general, please use arrow [`Array`]s rather than [`ScalarValue`] whenever | ||
/// possible, as it is far more efficient for multiple values. | ||
/// | ||
/// # Example | ||
/// ``` | ||
/// # use datafusion_common::ScalarValue; | ||
/// // Create single scalar value for an Int32 value | ||
/// let s1 = ScalarValue::Int32(Some(10)); | ||
/// | ||
/// // You can also create values using the From impl: | ||
/// let s2 = ScalarValue::from(10i32); | ||
/// assert_eq!(s1, s2); | ||
/// ``` | ||
/// | ||
/// # Null Handling | ||
/// | ||
/// `ScalarValue` represents null values in the same way as Arrow. Nulls are | ||
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. FYI @jayzhan211 -- perhaps this can help explain some of how we can avoid using NullArray / ScalarValue::Null in the various list array functions |
||
/// "typed" in the sense that a null value in an [`Int32Array`] is different | ||
/// than a null value in a [`Float64Array`], and is different than the values in | ||
/// a [`NullArray`]. | ||
/// | ||
/// ``` | ||
/// # fn main() -> datafusion_common::Result<()> { | ||
/// # use std::collections::hash_set::Difference; | ||
/// # use datafusion_common::ScalarValue; | ||
/// # use arrow::datatypes::DataType; | ||
/// // You can create a 'null' Int32 value directly: | ||
/// let s1 = ScalarValue::Int32(None); | ||
/// | ||
/// // You can also create a null value for a given datatype: | ||
/// let s2 = ScalarValue::try_from(&DataType::Int32)?; | ||
/// assert_eq!(s1, s2); | ||
/// | ||
/// // Note that this is DIFFERENT than a `ScalarValue::Null` | ||
/// let s3 = ScalarValue::Null; | ||
/// assert_ne!(s1, s3); | ||
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
/// | ||
/// # Further Reading | ||
/// See [datatypes](https://arrow.apache.org/docs/python/api/datatypes.html) for | ||
/// details on datatypes and the [format](https://github.com/apache/arrow/blob/master/format/Schema.fbs#L354-L375) | ||
/// for the definitive reference. | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.