Skip to content

Apache DataFusion SQL Query Engine

Minor: deprecate ScalarValue::get_datatype() (#7507)

Alex Huang0cd30886cd41
diff --git a/datafusion/common/src/scalar.rs b/datafusion/common/src/scalar.rs
index 88e0f3a301..6189a293b4 100644
--- a/datafusion/common/src/scalar.rs
+++ b/datafusion/common/src/scalar.rs
@@ -983,7 +983,7 @@ impl ScalarValue {
}
ScalarValue::Struct(_, fields) => DataType::Struct(fields.clone()),
ScalarValue::Dictionary(k, v) => {
- DataType::Dictionary(k.clone(), Box::new(v.get_datatype()))
+ DataType::Dictionary(k.clone(), Box::new(v.data_type()))
}
ScalarValue::Null => DataType::Null,
}
@@ -992,6 +992,7 @@ impl ScalarValue {
/// Getter for the `DataType` of the value.
///
/// Suggest using [`Self::data_type`] as a more standard API
+ #[deprecated(since = "31.0.0", note = "use data_type instead")]
pub fn get_datatype(&self) -> DataType {
self.data_type()
}
@@ -1243,7 +1244,7 @@ impl ScalarValue {
"Empty iterator passed to ScalarValue::iter_to_array"
);
}
- Some(sv) => sv.get_datatype(),
+ Some(sv) => sv.data_type(),
};
/// Creates an array of $ARRAY_TY by unpacking values of
@@ -2013,7 +2014,7 @@ impl ScalarValue {
Arc::new(StructArray::from(field_values))
}
None => {
- let dt = self.get_datatype();
+ let dt = self.data_type();
new_null_array(&dt, size)
}
},
@@ -2618,9 +2619,7 @@ impl From<Vec<(&str, ScalarValue)>> for ScalarValue {
fn from(value: Vec<(&str, ScalarValue)>) -> Self {
let (fields, scalars): (SchemaBuilder, Vec<_>) = value
.into_iter()
- .map(|(name, scalar)| {
- (Field::new(name, scalar.get_datatype(), false), scalar)
- })
+ .map(|(name, scalar)| (Field::new(name, scalar.data_type(), false), scalar))
.unzip();
Self::Struct(Some(scalars), fields.finish().fields)
@@ -3221,7 +3220,7 @@ mod tests {
#[test]
fn scalar_decimal_test() -> Result<()> {
let decimal_value = ScalarValue::Decimal128(Some(123), 10, 1);
- assert_eq!(DataType::Decimal128(10, 1), decimal_value.get_datatype());
+ assert_eq!(DataType::Decimal128(10, 1), decimal_value.data_type());
let try_into_value: i128 = decimal_value.clone().try_into().unwrap();
assert_eq!(123_i128, try_into_value);
assert!(!decimal_value.is_null());
@@ -4192,11 +4191,11 @@ mod tests {
// Define list-of-structs scalars
let nl0 =
- ScalarValue::new_list(Some(vec![s0.clone(), s1.clone()]), s0.get_datatype());
+ ScalarValue::new_list(Some(vec![s0.clone(), s1.clone()]), s0.data_type());
- let nl1 = ScalarValue::new_list(Some(vec![s2]), s0.get_datatype());
+ let nl1 = ScalarValue::new_list(Some(vec![s2]), s0.data_type());
- let nl2 = ScalarValue::new_list(Some(vec![s1]), s0.get_datatype());
+ let nl2 = ScalarValue::new_list(Some(vec![s1]), s0.data_type());
// iter_to_array for list-of-struct
let array = ScalarValue::iter_to_array(vec![nl0, nl1, nl2]).unwrap();
let array = as_list_array(&array).unwrap();
@@ -4405,7 +4404,7 @@ mod tests {
);
assert_eq!(
- scalar.get_datatype(),
+ scalar.data_type(),
DataType::Timestamp(TimeUnit::Nanosecond, Some("UTC".into()))
);
@@ -4418,7 +4417,7 @@ mod tests {
let newscalar = ScalarValue::try_from_array(&array, 0).unwrap();
assert_eq!(
- newscalar.get_datatype(),
+ newscalar.data_type(),
DataType::Timestamp(TimeUnit::Nanosecond, Some("UTC".into()))
);
}
@@ -4452,7 +4451,7 @@ mod tests {
// turn it back to a scalar
let cast_scalar = ScalarValue::try_from_array(&cast_array, 0).unwrap();
- assert_eq!(cast_scalar.get_datatype(), desired_type);
+ assert_eq!(cast_scalar.data_type(), desired_type);
// Some time later the "cast" scalar is turned back into an array:
let array = cast_scalar.to_array_of_size(10);
diff --git a/datafusion/core/src/datasource/physical_plan/file_scan_config.rs b/datafusion/core/src/datasource/physical_plan/file_scan_config.rs
index 7d4902b7bc..d946fbabae 100644
--- a/datafusion/core/src/datasource/physical_plan/file_scan_config.rs
+++ b/datafusion/core/src/datasource/physical_plan/file_scan_config.rs
@@ -347,7 +347,7 @@ impl PartitionColumnProjector {
// check if user forgot to dict-encode the partition value
let field = self.projected_schema.field(sidx);
let expected_data_type = field.data_type();
- let actual_data_type = partition_value.get_datatype();
+ let actual_data_type = partition_value.data_type();
if let DataType::Dictionary(key_type, _) = expected_data_type {
if !matches!(actual_data_type, DataType::Dictionary(_, _)) {
warn!("Partition value for column {} was not dictionary-encoded, applied auto-fix.", field.name());
@@ -448,7 +448,7 @@ fn create_output_array(
&mut key_buffer_cache.gen_i8,
dict_val,
len,
- val.get_datatype(),
+ val.data_type(),
);
}
DataType::Int16 => {
@@ -456,7 +456,7 @@ fn create_output_array(
&mut key_buffer_cache.gen_i16,
dict_val,
len,
- val.get_datatype(),
+ val.data_type(),
);
}
DataType::Int32 => {
@@ -464,7 +464,7 @@ fn create_output_array(
&mut key_buffer_cache.gen_i32,
dict_val,
len,
- val.get_datatype(),
+ val.data_type(),
);
}
DataType::Int64 => {
@@ -472,7 +472,7 @@ fn create_output_array(
&mut key_buffer_cache.gen_i64,
dict_val,
len,
- val.get_datatype(),
+ val.data_type(),
);
}
DataType::UInt8 => {
@@ -480,7 +480,7 @@ fn create_output_array(
&mut key_buffer_cache.gen_u8,
dict_val,
len,
- val.get_datatype(),
+ val.data_type(),
);
}
DataType::UInt16 => {
@@ -488,7 +488,7 @@ fn create_output_array(
&mut key_buffer_cache.gen_u16,
dict_val,
len,
- val.get_datatype(),
+ val.data_type(),
);
}
DataType::UInt32 => {
@@ -496,7 +496,7 @@ fn create_output_array(
&mut key_buffer_cache.gen_u32,
dict_val,
len,
- val.get_datatype(),
+ val.data_type(),
);
}
DataType::UInt64 => {
@@ -504,7 +504,7 @@ fn create_output_array(
&mut key_buffer_cache.gen_u64,
dict_val,
len,
- val.get_datatype(),
+ val.data_type(),
);
}
_ => {}
diff --git a/datafusion/core/src/physical_plan/filter.rs b/datafusion/core/src/physical_plan/filter.rs
index 5c8cb1abc4..0b878814e3 100644
--- a/datafusion/core/src/physical_plan/filter.rs
+++ b/datafusion/core/src/physical_plan/filter.rs
@@ -775,13 +775,7 @@ mod tests {
.into_iter()
.zip(statistics.column_statistics.unwrap())
.map(|(expected, actual)| {
- if actual
- .min_value
- .clone()
- .unwrap()
- .get_datatype()
- .is_floating()
- {
+ if actual.min_value.clone().unwrap().data_type().is_floating() {
// Windows rounds arithmetic operation results differently for floating point numbers.
// Therefore, we check if the actual values are in an epsilon range.
let actual_min = actual.min_value.unwrap();
diff --git a/datafusion/core/src/physical_plan/joins/hash_join_utils.rs b/datafusion/core/src/physical_plan/joins/hash_join_utils.rs
index b80413b53d..ac0b183818 100644
--- a/datafusion/core/src/physical_plan/joins/hash_join_utils.rs
+++ b/datafusion/core/src/physical_plan/joins/hash_join_utils.rs
@@ -704,7 +704,7 @@ pub fn update_filter_expr_interval(
// Convert the array to a ScalarValue:
let value = ScalarValue::try_from_array(&array, 0)?;
// Create a ScalarValue representing positive or negative infinity for the same data type:
- let unbounded = IntervalBound::make_unbounded(value.get_datatype())?;
+ let unbounded = IntervalBound::make_unbounded(value.data_type())?;
// Update the interval with lower and upper bounds based on the sort option:
let interval = if sorted_expr.origin_sorted_expr().options.descending {
Interval::new(unbounded, IntervalBound::new(value, false))
diff --git a/datafusion/core/tests/path_partition.rs b/datafusion/core/tests/path_partition.rs
index 372817359b..1c08733e3d 100644
--- a/datafusion/core/tests/path_partition.rs
+++ b/datafusion/core/tests/path_partition.rs
@@ -125,7 +125,7 @@ async fn parquet_distinct_partition_col() -> Result<()> {
let mut max_limit = match ScalarValue::try_from_array(results[0].column(0), 0)? {
ScalarValue::Int64(Some(count)) => count,
- s => panic!("Expected count as Int64 found {}", s.get_datatype()),
+ s => panic!("Expected count as Int64 found {}", s.data_type()),
};
max_limit += 1;
@@ -136,7 +136,7 @@ async fn parquet_distinct_partition_col() -> Result<()> {
let mut min_limit =
match ScalarValue::try_from_array(last_batch.column(0), last_row_idx)? {
ScalarValue::Int64(Some(count)) => count,
- s => panic!("Expected count as Int64 found {}", s.get_datatype()),
+ s => panic!("Expected count as Int64 found {}", s.data_type()),
};
min_limit -= 1;
diff --git a/datafusion/expr/src/columnar_value.rs b/datafusion/expr/src/columnar_value.rs
index 9a18bdceab..c72aae69c8 100644
--- a/datafusion/expr/src/columnar_value.rs
+++ b/datafusion/expr/src/columnar_value.rs
@@ -41,7 +41,7 @@ impl ColumnarValue {
pub fn data_type(&self) -> DataType {
match self {
ColumnarValue::Array(array_value) => array_value.data_type().clone(),
- ColumnarValue::Scalar(scalar_value) => scalar_value.get_datatype(),
+ ColumnarValue::Scalar(scalar_value) => scalar_value.data_type(),
}
}
diff --git a/datafusion/expr/src/expr_schema.rs b/datafusion/expr/src/expr_schema.rs
index 82f1bf8ed7..9651b377c5 100644
--- a/datafusion/expr/src/expr_schema.rs
+++ b/datafusion/expr/src/expr_schema.rs
@@ -77,7 +77,7 @@ impl ExprSchemable for Expr {
Expr::Column(c) => Ok(schema.data_type(c)?.clone()),
Expr::OuterReferenceColumn(ty, _) => Ok(ty.clone()),
Expr::ScalarVariable(ty, _) => Ok(ty.clone()),
- Expr::Literal(l) => Ok(l.get_datatype()),
+ Expr::Literal(l) => Ok(l.data_type()),
Expr::Case(case) => case.when_then_expr[0].1.get_type(schema),
Expr::Cast(Cast { data_type, .. })
| Expr::TryCast(TryCast { data_type, .. }) => Ok(data_type.clone()),
diff --git a/datafusion/physical-expr/src/aggregate/array_agg_ordered.rs b/datafusion/physical-expr/src/aggregate/array_agg_ordered.rs
index e65a2116d3..bf5dbfb4fd 100644
--- a/datafusion/physical-expr/src/aggregate/array_agg_ordered.rs
+++ b/datafusion/physical-expr/src/aggregate/array_agg_ordered.rs
@@ -291,14 +291,14 @@ impl OrderSensitiveArrayAggAccumulator {
} else {
exec_err!(
"Expects to receive ScalarValue::Struct(Some(..), _) but got:{:?}",
- struct_vals.get_datatype()
+ struct_vals.data_type()
)
}
}).collect::<Result<Vec<_>>>()
} else {
exec_err!(
"Expects to receive ScalarValue::List(Some(..), _) but got:{:?}",
- in_data.get_datatype()
+ in_data.data_type()
)
}
}
diff --git a/datafusion/physical-expr/src/datetime_expressions.rs b/datafusion/physical-expr/src/datetime_expressions.rs
index 2db0818082..bf90a7da9c 100644
--- a/datafusion/physical-expr/src/datetime_expressions.rs
+++ b/datafusion/physical-expr/src/datetime_expressions.rs
@@ -554,7 +554,7 @@ fn date_bin_impl(
ColumnarValue::Scalar(v) => {
return exec_err!(
"DATE_BIN expects stride argument to be an INTERVAL but got {}",
- v.get_datatype()
+ v.data_type()
)
}
ColumnarValue::Array(_) => {
@@ -569,7 +569,7 @@ fn date_bin_impl(
ColumnarValue::Scalar(v) => {
return exec_err!(
"DATE_BIN expects origin argument to be a TIMESTAMP with nanosececond precision but got {}",
- v.get_datatype()
+ v.data_type()
)
}
ColumnarValue::Array(_) => return not_impl_err!(
diff --git a/datafusion/physical-expr/src/expressions/literal.rs b/datafusion/physical-expr/src/expressions/literal.rs
index 517a0fe411..91cb23d586 100644
--- a/datafusion/physical-expr/src/expressions/literal.rs
+++ b/datafusion/physical-expr/src/expressions/literal.rs
@@ -63,7 +63,7 @@ impl PhysicalExpr for Literal {
}
fn data_type(&self, _input_schema: &Schema) -> Result<DataType> {
- Ok(self.value.get_datatype())
+ Ok(self.value.data_type())
}
fn nullable(&self, _input_schema: &Schema) -> Result<bool> {
diff --git a/datafusion/physical-expr/src/expressions/mod.rs b/datafusion/physical-expr/src/expressions/mod.rs
index fbc609611e..cfc8ec2f07 100644
--- a/datafusion/physical-expr/src/expressions/mod.rs
+++ b/datafusion/physical-expr/src/expressions/mod.rs
@@ -116,7 +116,7 @@ pub(crate) mod tests {
#[macro_export]
macro_rules! generic_test_op {
($ARRAY:expr, $DATATYPE:expr, $OP:ident, $EXPECTED:expr) => {
- generic_test_op!($ARRAY, $DATATYPE, $OP, $EXPECTED, $EXPECTED.get_datatype())
+ generic_test_op!($ARRAY, $DATATYPE, $OP, $EXPECTED, $EXPECTED.data_type())
};
($ARRAY:expr, $DATATYPE:expr, $OP:ident, $EXPECTED:expr, $EXPECTED_DATATYPE:expr) => {{
let schema = Schema::new(vec![Field::new("a", $DATATYPE, true)]);
@@ -212,7 +212,7 @@ pub(crate) mod tests {
$DATATYPE2,
$OP,
$EXPECTED,
- $EXPECTED.get_datatype()
+ $EXPECTED.data_type()
)
};
($ARRAY1:expr, $ARRAY2:expr, $DATATYPE1:expr, $DATATYPE2:expr, $OP:ident, $EXPECTED:expr, $EXPECTED_DATATYPE:expr) => {{
diff --git a/datafusion/physical-expr/src/expressions/not.rs b/datafusion/physical-expr/src/expressions/not.rs
index 2535c2f199..c154fad100 100644
--- a/datafusion/physical-expr/src/expressions/not.rs
+++ b/datafusion/physical-expr/src/expressions/not.rs
@@ -83,7 +83,7 @@ impl PhysicalExpr for NotExpr {
if scalar.is_null() {
return Ok(ColumnarValue::Scalar(ScalarValue::Boolean(None)));
}
- let value_type = scalar.get_datatype();
+ let value_type = scalar.data_type();
if value_type != DataType::Boolean {
return internal_err!(
"NOT '{:?}' can't be evaluated because the expression's type is {:?}, not boolean or NULL",
diff --git a/datafusion/physical-expr/src/expressions/nullif.rs b/datafusion/physical-expr/src/expressions/nullif.rs
index 04a9756665..7bbe9d73d4 100644
--- a/datafusion/physical-expr/src/expressions/nullif.rs
+++ b/datafusion/physical-expr/src/expressions/nullif.rs
@@ -53,7 +53,7 @@ pub fn nullif_func(args: &[ColumnarValue]) -> Result<ColumnarValue> {
}
(ColumnarValue::Scalar(lhs), ColumnarValue::Scalar(rhs)) => {
let val: ScalarValue = match lhs.eq(rhs) {
- true => lhs.get_datatype().try_into()?,
+ true => lhs.data_type().try_into()?,
false => lhs.clone(),
};
diff --git a/datafusion/physical-expr/src/intervals/interval_aritmetic.rs b/datafusion/physical-expr/src/intervals/interval_aritmetic.rs
index 5e4710116c..37b0ad433b 100644
--- a/datafusion/physical-expr/src/intervals/interval_aritmetic.rs
+++ b/datafusion/physical-expr/src/intervals/interval_aritmetic.rs
@@ -55,7 +55,7 @@ impl IntervalBound {
/// This convenience function returns the data type associated with this
/// `IntervalBound`.
pub fn get_datatype(&self) -> DataType {
- self.value.get_datatype()
+ self.value.data_type()
}
/// This convenience function checks whether the `IntervalBound` represents
@@ -475,7 +475,7 @@ impl Interval {
// If the minimum value is a negative number, we need to
// switch sides to ensure an unsigned result.
let (min, max) = if self.lower.value
- < ScalarValue::new_zero(&self.lower.value.get_datatype())?
+ < ScalarValue::new_zero(&self.lower.value.data_type())?
{
(self.upper.value.clone(), self.lower.value.clone())
} else {
diff --git a/datafusion/proto/src/logical_plan/from_proto.rs b/datafusion/proto/src/logical_plan/from_proto.rs
index 7fbf2ff52c..0352f703c7 100644
--- a/datafusion/proto/src/logical_plan/from_proto.rs
+++ b/datafusion/proto/src/logical_plan/from_proto.rs
@@ -902,7 +902,7 @@ pub fn parse_i32_to_aggregate_function(value: &i32) -> Result<AggregateFunction,
fn validate_list_values(field: &Field, values: &[ScalarValue]) -> Result<(), Error> {
for value in values {
let field_type = field.data_type();
- let value_type = value.get_datatype();
+ let value_type = value.data_type();
if field_type != &value_type {
return Err(proto_error(format!(
diff --git a/datafusion/proto/src/logical_plan/to_proto.rs b/datafusion/proto/src/logical_plan/to_proto.rs
index f1b327170d..1a9ee64fcf 100644
--- a/datafusion/proto/src/logical_plan/to_proto.rs
+++ b/datafusion/proto/src/logical_plan/to_proto.rs
@@ -1083,7 +1083,7 @@ impl TryFrom<&ScalarValue> for protobuf::ScalarValue {
fn try_from(val: &ScalarValue) -> Result<Self, Self::Error> {
use protobuf::scalar_value::Value;
- let data_type = val.get_datatype();
+ let data_type = val.data_type();
match val {
ScalarValue::Boolean(val) => {
create_proto_scalar(val.as_ref(), &data_type, |s| Value::BoolValue(*s))