@@ -50,9 +50,52 @@ use arrow::{
5050use arrow_array:: cast:: as_list_array;
5151use arrow_array:: { ArrowNativeTypeOp , Scalar } ;
5252
53- /// Represents a dynamically typed, nullable single value.
54- /// This is the single-valued counter-part to arrow's [`Array`].
53+ /// A dynamically typed, nullable single value, (the single-valued counter-part
54+ /// to arrow's [`Array`])
5555///
56+ /// # Performance
57+ ///
58+ /// In general, please use arrow [`Array`]s rather than [`ScalarValue`] whenever
59+ /// possible, as it is far more efficient for multiple values.
60+ ///
61+ /// # Example
62+ /// ```
63+ /// # use datafusion_common::ScalarValue;
64+ /// // Create single scalar value for an Int32 value
65+ /// let s1 = ScalarValue::Int32(Some(10));
66+ ///
67+ /// // You can also create values using the From impl:
68+ /// let s2 = ScalarValue::from(10i32);
69+ /// assert_eq!(s1, s2);
70+ /// ```
71+ ///
72+ /// # Null Handling
73+ ///
74+ /// `ScalarValue` represents null values in the same way as Arrow. Nulls are
75+ /// "typed" in the sense that a null value in an [`Int32Array`] is different
76+ /// than a null value in a [`Float64Array`], and is different than the values in
77+ /// a [`NullArray`].
78+ ///
79+ /// ```
80+ /// # fn main() -> datafusion_common::Result<()> {
81+ /// # use std::collections::hash_set::Difference;
82+ /// # use datafusion_common::ScalarValue;
83+ /// # use arrow::datatypes::DataType;
84+ /// // You can create a 'null' Int32 value directly:
85+ /// let s1 = ScalarValue::Int32(None);
86+ ///
87+ /// // You can also create a null value for a given datatype:
88+ /// let s2 = ScalarValue::try_from(&DataType::Int32)?;
89+ /// assert_eq!(s1, s2);
90+ ///
91+ /// // Note that this is DIFFERENT than a `ScalarValue::Null`
92+ /// let s3 = ScalarValue::Null;
93+ /// assert_ne!(s1, s3);
94+ /// # Ok(())
95+ /// # }
96+ /// ```
97+ ///
98+ /// # Further Reading
5699/// See [datatypes](https://arrow.apache.org/docs/python/api/datatypes.html) for
57100/// details on datatypes and the [format](https://github.com/apache/arrow/blob/master/format/Schema.fbs#L354-L375)
58101/// for the definitive reference.
0 commit comments