File tree 1 file changed +29
-2
lines changed
1 file changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -1321,7 +1321,34 @@ impl ScalarValue {
1321
1321
self . to_array_of_size ( 1 )
1322
1322
}
1323
1323
1324
- /// Converts a scalar into an arrow [`Scalar`]
1324
+ /// Converts a scalar into an arrow [`Scalar`] (which implements
1325
+ /// the [`Datum`] interface).
1326
+ ///
1327
+ /// This can be used to call arrow compute kernels such as `lt`
1328
+ ///
1329
+ /// # Example
1330
+ /// ```
1331
+ /// use datafusion_common::ScalarValue;
1332
+ /// use arrow::array::{BooleanArray, Int32Array};
1333
+ ///
1334
+ /// let arr = Int32Array::from(vec![Some(1), None, Some(10)]);
1335
+ /// let five = ScalarValue::Int32(Some(5));
1336
+ ///
1337
+ /// let result = arrow::compute::kernels::cmp::lt(
1338
+ /// &arr,
1339
+ /// &five.to_scalar(),
1340
+ /// ).unwrap();
1341
+ ///
1342
+ /// let expected = BooleanArray::from(vec![
1343
+ /// Some(true),
1344
+ /// None,
1345
+ /// Some(false)
1346
+ /// ]
1347
+ /// );
1348
+ ///
1349
+ /// assert_eq!(&result, &expected);
1350
+ /// ```
1351
+ /// [`Datum`]: arrow_array::Datum
1325
1352
pub fn to_scalar ( & self ) -> Scalar < ArrayRef > {
1326
1353
Scalar :: new ( self . to_array_of_size ( 1 ) )
1327
1354
}
@@ -1332,7 +1359,7 @@ impl ScalarValue {
1332
1359
/// Returns an error if the iterator is empty or if the
1333
1360
/// [`ScalarValue`]s are not all the same type
1334
1361
///
1335
- /// Example
1362
+ /// # Example
1336
1363
/// ```
1337
1364
/// use datafusion_common::ScalarValue;
1338
1365
/// use arrow::array::{ArrayRef, BooleanArray};
You can’t perform that action at this time.
0 commit comments