Skip to content

Commit c3c8bab

Browse files
committed
clean-up
1 parent 07cedbc commit c3c8bab

File tree

2 files changed

+8
-27
lines changed

2 files changed

+8
-27
lines changed

src/common_union.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@ impl JsonUnion {
9090
debug_assert!(self.index <= self.length);
9191
}
9292

93-
fn push_array(&mut self, fields: Vec<String>) {
94-
self.arrays[self.index] = Some(fields.join(","));
95-
self.index += 1;
96-
debug_assert!(self.index <= self.length);
97-
}
98-
9993
fn push_none(&mut self) {
10094
self.index += 1;
10195
debug_assert!(self.index <= self.length);
@@ -120,16 +114,16 @@ impl FromIterator<Option<JsonUnionField>> for JsonUnion {
120114
}
121115
}
122116

123-
/// Tries to collect a String array to a JsonUnion
124-
impl FromIterator<Option<Vec<String>>> for JsonUnion {
125-
fn from_iter<I: IntoIterator<Item = Option<Vec<String>>>>(iter: I) -> Self {
117+
/// Tries to collect an array represented as a string to a JsonUnion
118+
impl FromIterator<Option<String>> for JsonUnion {
119+
fn from_iter<I: IntoIterator<Item = Option<String>>>(iter: I) -> Self {
126120
let inner = iter.into_iter();
127121
let (lower, upper) = inner.size_hint();
128122
let mut union = Self::new(upper.unwrap_or(lower));
129123

130124
for row in inner {
131-
if let Some(arrays) = row {
132-
union.push_array(arrays);
125+
if let Some(array) = row {
126+
union.push(JsonUnionField::Array(array));
133127
} else {
134128
union.push_none();
135129
}

src/json_get_array.rs

+3-16
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ impl ScalarUDFImpl for JsonGetArray {
5656
let array: ListArray = c.try_into()?;
5757
Ok(Arc::new(array) as ArrayRef)
5858
};
59-
invoke::<JsonUnion, Vec<String>>(args, jiter_json_get_array, to_array, scalar_value)
59+
invoke::<JsonUnion, String>(args, jiter_json_get_array, to_array, ScalarValue::Utf8)
6060
}
6161

6262
fn aliases(&self) -> &[String] {
6363
&self.aliases
6464
}
6565
}
6666

67-
fn jiter_json_get_array(json_data: Option<&str>, path: &[JsonPath]) -> Result<Vec<String>, GetError> {
67+
fn jiter_json_get_array(json_data: Option<&str>, path: &[JsonPath]) -> Result<String, GetError> {
6868
if let Some((mut jiter, peek)) = jiter_json_find(json_data, path) {
6969
match peek {
7070
Peek::Array => {
@@ -82,24 +82,11 @@ fn jiter_json_get_array(json_data: Option<&str>, path: &[JsonPath]) -> Result<Ve
8282
peek_opt = jiter.array_step()?;
8383
}
8484

85-
Ok(array_values)
85+
Ok(array_values.join(","))
8686
}
8787
_ => get_err!(),
8888
}
8989
} else {
9090
get_err!()
9191
}
9292
}
93-
94-
pub fn scalar_value(f: Option<Vec<String>>) -> ScalarValue {
95-
if let Some(array) = f {
96-
let values = array
97-
.into_iter()
98-
.map(|e| ScalarValue::Utf8(Some(e)))
99-
.collect::<Vec<_>>();
100-
101-
ScalarValue::List(ScalarValue::new_list_nullable(&values, &DataType::Utf8))
102-
} else {
103-
ScalarValue::Null
104-
}
105-
}

0 commit comments

Comments
 (0)