Skip to content

Commit d485fb7

Browse files
committed
chore: hardcode field name
Signed-off-by: Alan Tang <jmtangcs@gmail.com>
1 parent 13a713e commit d485fb7

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

datafusion/spark/src/function/array/spark_array.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ use datafusion_expr::{
3333

3434
use crate::function::functions_nested_utils::make_scalar_function;
3535

36+
const ARRAY_FIELD_DEFAULT_NAME: &'static str = "element";
37+
3638
#[derive(Debug)]
3739
pub struct SparkArray {
3840
signature: Signature,
3941
aliases: Vec<String>,
40-
name: String,
4142
}
4243

4344
impl Default for SparkArray {
@@ -47,29 +48,15 @@ impl Default for SparkArray {
4748
}
4849

4950
impl SparkArray {
50-
pub const ARRAY_FIELD_DEFAULT_NAME: &'static str = "element";
51-
5251
pub fn new() -> Self {
5352
Self {
5453
signature: Signature::one_of(
5554
vec![TypeSignature::UserDefined, TypeSignature::Nullary],
5655
Volatility::Immutable,
5756
),
5857
aliases: vec![String::from("spark_make_array")],
59-
name: Self::ARRAY_FIELD_DEFAULT_NAME.to_string(),
60-
}
61-
}
62-
63-
pub fn with_list_field_name(name: impl Into<String>) -> Self {
64-
Self {
65-
name: name.into(),
66-
..Self::new()
6758
}
6859
}
69-
70-
pub fn name(&self) -> &String {
71-
&self.name
72-
}
7360
}
7461

7562
impl ScalarUDFImpl for SparkArray {
@@ -116,7 +103,11 @@ impl ScalarUDFImpl for SparkArray {
116103
.cloned()
117104
.collect::<Vec<_>>();
118105
let return_type = self.return_type(&data_types)?;
119-
Ok(Arc::new(Field::new(self.name(), return_type, false)))
106+
Ok(Arc::new(Field::new(
107+
ARRAY_FIELD_DEFAULT_NAME,
108+
return_type,
109+
false,
110+
)))
120111
}
121112

122113
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
@@ -154,7 +145,11 @@ impl ScalarUDFImpl for SparkArray {
154145

155146
// Empty array is a special case that is useful for many other array functions
156147
pub(super) fn empty_array_type() -> DataType {
157-
DataType::List(Arc::new(Field::new_list_field(DataType::Int32, true)))
148+
DataType::List(Arc::new(Field::new(
149+
ARRAY_FIELD_DEFAULT_NAME,
150+
DataType::Int32,
151+
true,
152+
)))
158153
}
159154

160155
/// `make_array_inner` is the implementation of the `make_array` function.
@@ -272,7 +267,7 @@ fn array_array<O: OffsetSizeTrait>(
272267
let data = mutable.freeze();
273268

274269
Ok(Arc::new(GenericListArray::<O>::try_new(
275-
Arc::new(Field::new_list_field(data_type, true)),
270+
Arc::new(Field::new(ARRAY_FIELD_DEFAULT_NAME, data_type, true)),
276271
OffsetBuffer::new(offsets.into()),
277272
make_array(data),
278273
None,

0 commit comments

Comments
 (0)