@@ -103,32 +103,29 @@ impl<'s> JsonPath<'s> {
103103 }
104104}
105105
106- /// Very similar to `FromIterator` but we define it here so we can implement it as we wish,
106+ /// Same as `FromIterator` but we defined within the crate so we can custom as we wish,
107107/// e.g. for `ListArray` with `Vec<String>`.
108- ///
109- /// Make the usage slightly more concise by taking `IntoIterator<Item = Option<I>>`
110- /// instead of just `IntoIterator<Item = I>`.
111- pub trait FromOptionIter < I > : Sized {
112- fn from_option_iter < T : IntoIterator < Item = Option < I > > > ( iter : T ) -> Self ;
108+ pub trait JiterFromIterator < I > : Sized {
109+ fn jiter_from_iter < T : IntoIterator < Item = I > > ( iter : T ) -> Self ;
113110}
114111
115- macro_rules! impl_from_option_iter {
112+ macro_rules! impl_jiter_from_iterator {
116113 ( $collect: ty, $item: ty) => {
117- impl FromOptionIter <$item> for $collect {
118- fn from_option_iter <T : IntoIterator <Item = Option < $item> >>( iter: T ) -> Self {
114+ impl JiterFromIterator <$item> for $collect {
115+ fn jiter_from_iter <T : IntoIterator <Item = $item>>( iter: T ) -> Self {
119116 <$collect>:: from_iter( iter)
120117 }
121118 }
122119 } ;
123120}
124- impl_from_option_iter ! ( Int64Array , i64 ) ;
125- impl_from_option_iter ! ( UInt64Array , u64 ) ;
126- impl_from_option_iter ! ( Float64Array , f64 ) ;
127- impl_from_option_iter ! ( StringArray , String ) ;
128- impl_from_option_iter ! ( BooleanArray , bool ) ;
129- impl_from_option_iter ! ( JsonUnion , JsonUnionField ) ;
130-
131- pub fn invoke < C : FromOptionIter < I > + ' static , I > (
121+ impl_jiter_from_iterator ! ( Int64Array , Option < i64 > ) ;
122+ impl_jiter_from_iterator ! ( UInt64Array , Option < u64 > ) ;
123+ impl_jiter_from_iterator ! ( Float64Array , Option < f64 > ) ;
124+ impl_jiter_from_iterator ! ( StringArray , Option < String > ) ;
125+ impl_jiter_from_iterator ! ( BooleanArray , Option < bool > ) ;
126+ impl_jiter_from_iterator ! ( JsonUnion , Option < JsonUnionField > ) ;
127+
128+ pub fn invoke < C : JiterFromIterator < Option < I > > + ' static , I > (
132129 args : & [ ColumnarValue ] ,
133130 jiter_find : impl Fn ( Option < & str > , & [ JsonPath ] ) -> Result < I , GetError > ,
134131 to_array : impl Fn ( C ) -> DataFusionResult < ArrayRef > ,
@@ -165,7 +162,7 @@ pub fn invoke<C: FromOptionIter<I> + 'static, I>(
165162 }
166163}
167164
168- fn invoke_array < C : FromOptionIter < I > + ' static , I > (
165+ fn invoke_array < C : JiterFromIterator < Option < I > > + ' static , I > (
169166 json_array : & ArrayRef ,
170167 needle_array : & ArrayRef ,
171168 to_array : impl Fn ( C ) -> DataFusionResult < ArrayRef > ,
@@ -195,7 +192,7 @@ fn invoke_array<C: FromOptionIter<I> + 'static, I>(
195192 }
196193}
197194
198- fn zip_apply < ' a , P : Iterator < Item = Option < JsonPath < ' a > > > , C : FromOptionIter < I > + ' static , I > (
195+ fn zip_apply < ' a , P : Iterator < Item = Option < JsonPath < ' a > > > , C : JiterFromIterator < Option < I > > + ' static , I > (
199196 json_array : & ArrayRef ,
200197 path_array : P ,
201198 to_array : impl Fn ( C ) -> DataFusionResult < ArrayRef > ,
@@ -224,12 +221,12 @@ fn zip_apply<'a, P: Iterator<Item = Option<JsonPath<'a>>>, C: FromOptionIter<I>
224221 to_array ( c)
225222}
226223
227- fn zip_apply_iter < ' a , ' j , P : Iterator < Item = Option < JsonPath < ' a > > > , C : FromOptionIter < I > + ' static , I > (
224+ fn zip_apply_iter < ' a , ' j , P : Iterator < Item = Option < JsonPath < ' a > > > , C : JiterFromIterator < Option < I > > + ' static , I > (
228225 json_iter : impl Iterator < Item = Option < & ' j str > > ,
229226 path_array : P ,
230227 jiter_find : impl Fn ( Option < & str > , & [ JsonPath ] ) -> Result < I , GetError > ,
231228) -> C {
232- C :: from_option_iter ( json_iter. zip ( path_array) . map ( |( opt_json, opt_path) | {
229+ C :: jiter_from_iter ( json_iter. zip ( path_array) . map ( |( opt_json, opt_path) | {
233230 if let Some ( path) = opt_path {
234231 jiter_find ( opt_json, & [ path] ) . ok ( )
235232 } else {
@@ -262,7 +259,7 @@ fn invoke_scalar<I>(
262259 }
263260}
264261
265- fn scalar_apply < C : FromOptionIter < I > , I > (
262+ fn scalar_apply < C : JiterFromIterator < Option < I > > , I > (
266263 json_array : & ArrayRef ,
267264 path : & [ JsonPath ] ,
268265 to_array : impl Fn ( C ) -> DataFusionResult < ArrayRef > ,
@@ -320,12 +317,12 @@ fn is_object_lookup(path: &[JsonPath]) -> bool {
320317 }
321318}
322319
323- fn scalar_apply_iter < ' j , C : FromOptionIter < I > , I > (
320+ fn scalar_apply_iter < ' j , C : JiterFromIterator < Option < I > > , I > (
324321 json_iter : impl Iterator < Item = Option < & ' j str > > ,
325322 path : & [ JsonPath ] ,
326323 jiter_find : impl Fn ( Option < & str > , & [ JsonPath ] ) -> Result < I , GetError > ,
327324) -> C {
328- C :: from_option_iter ( json_iter. map ( |opt_json| jiter_find ( opt_json, path) . ok ( ) ) )
325+ C :: jiter_from_iter ( json_iter. map ( |opt_json| jiter_find ( opt_json, path) . ok ( ) ) )
329326}
330327
331328pub fn jiter_json_find < ' j > ( opt_json : Option < & ' j str > , path : & [ JsonPath ] ) -> Option < ( Jiter < ' j > , Peek ) > {
0 commit comments