Skip to content

Commit 501add5

Browse files
committed
revise some scalarValue fn implementation
1 parent 69d9051 commit 501add5

2 files changed

Lines changed: 8 additions & 12 deletions

File tree

datafusion/common/src/scalar.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use std::{convert::TryFrom, fmt, iter::repeat, sync::Arc};
3939
/// This is the single-valued counter-part of arrow’s `Array`.
4040
#[derive(Clone)]
4141
pub enum ScalarValue {
42-
/// represents null
42+
/// represents `DataType::Null` (castable to/from any other type)
4343
Null,
4444
/// true or false value
4545
Boolean(Option<bool>),
@@ -172,6 +172,7 @@ impl PartialEq for ScalarValue {
172172
(IntervalMonthDayNano(_), _) => false,
173173
(Struct(v1, t1), Struct(v2, t2)) => v1.eq(v2) && t1.eq(t2),
174174
(Struct(_, _), _) => false,
175+
(Null, Null) => true,
175176
(Null, _) => false,
176177
}
177178
}
@@ -273,6 +274,7 @@ impl PartialOrd for ScalarValue {
273274
}
274275
}
275276
(Struct(_, _), _) => None,
277+
(Null, Null) => Some(Ordering::Equal),
276278
(Null, _) => None,
277279
}
278280
}
@@ -844,10 +846,7 @@ impl ScalarValue {
844846
ScalarValue::iter_to_decimal_array(scalars, precision, scale)?;
845847
Arc::new(decimal_array)
846848
}
847-
DataType::Null => {
848-
let null_array = ScalarValue::iter_to_null_array(scalars)?;
849-
Arc::new(null_array)
850-
}
849+
DataType::Null => ScalarValue::iter_to_null_array(scalars),
851850
DataType::Boolean => build_array_primitive!(BooleanArray, Boolean),
852851
DataType::Float32 => build_array_primitive!(Float32Array, Float32),
853852
DataType::Float64 => build_array_primitive!(Float64Array, Float64),
@@ -980,18 +979,15 @@ impl ScalarValue {
980979
Ok(array)
981980
}
982981

983-
fn iter_to_null_array(
984-
scalars: impl IntoIterator<Item = ScalarValue>,
985-
) -> Result<NullArray> {
982+
fn iter_to_null_array(scalars: impl IntoIterator<Item = ScalarValue>) -> ArrayRef {
986983
let length =
987984
scalars
988985
.into_iter()
989986
.fold(0usize, |r, element: ScalarValue| match element {
990987
ScalarValue::Null => r + 1,
991988
_ => unreachable!(),
992989
});
993-
let array = NullArray::new(length);
994-
Ok(array)
990+
new_null_array(&DataType::Null, length)
995991
}
996992

997993
fn iter_to_decimal_array(
@@ -1550,7 +1546,7 @@ impl ScalarValue {
15501546
eq_array_primitive!(array, index, IntervalMonthDayNanoArray, val)
15511547
}
15521548
ScalarValue::Struct(_, _) => unimplemented!(),
1553-
ScalarValue::Null => false,
1549+
ScalarValue::Null => array.data().is_null(index),
15541550
}
15551551
}
15561552

datafusion/physical-expr/src/expressions/binary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ impl BinaryExpr {
12781278
Operator::NotEq => neq_dyn(&left, &right),
12791279
Operator::IsDistinctFrom => {
12801280
match (left_data_type, right_data_type) {
1281-
// exchange lhs and rhs to when lhs is Null since `binary_array_op` is
1281+
// exchange lhs and rhs when lhs is Null, since `binary_array_op` is
12821282
// always try to down cast array according to $LEFT expression.
12831283
(DataType::Null, _) => {
12841284
binary_array_op!(right, left, is_distinct_from)

0 commit comments

Comments
 (0)