@@ -6,8 +6,10 @@ use datafusion::arrow::array::UnionArray;
66use datafusion:: arrow:: datatypes:: DataType ;
77use datafusion:: common:: Result as DataFusionResult ;
88use datafusion:: logical_expr:: { ColumnarValue , ScalarUDFImpl , Signature , Volatility } ;
9+ use datafusion:: scalar:: ScalarValue ;
910use jiter:: { Jiter , NumberAny , NumberInt , Peek } ;
1011
12+ use crate :: common:: InvokeResult ;
1113use crate :: common:: { get_err, invoke, jiter_json_find, return_type_check, GetError , JsonPath } ;
1214use crate :: common_macros:: make_udf_function;
1315use crate :: common_union:: { JsonUnion , JsonUnionField } ;
@@ -54,18 +56,41 @@ impl ScalarUDFImpl for JsonGet {
5456 }
5557
5658 fn invoke ( & self , args : & [ ColumnarValue ] ) -> DataFusionResult < ColumnarValue > {
57- let to_array = |c : JsonUnion | {
58- let array: UnionArray = c. try_into ( ) ?;
59- Ok ( Arc :: new ( array) as ArrayRef )
60- } ;
61- invoke :: < JsonUnion , JsonUnionField > ( args, jiter_json_get_union, to_array, JsonUnionField :: scalar_value, true )
59+ invoke :: < JsonUnion > ( args, jiter_json_get_union, true )
6260 }
6361
6462 fn aliases ( & self ) -> & [ String ] {
6563 & self . aliases
6664 }
6765}
6866
67+ impl InvokeResult for JsonUnion {
68+ type Item = JsonUnionField ;
69+
70+ type Builder = JsonUnion ;
71+
72+ fn builder ( capacity : usize ) -> Self :: Builder {
73+ JsonUnion :: new ( capacity)
74+ }
75+
76+ fn append_value ( builder : & mut Self :: Builder , value : Option < Self :: Item > ) {
77+ if let Some ( value) = value {
78+ builder. push ( value)
79+ } else {
80+ builder. push_none ( )
81+ }
82+ }
83+
84+ fn finish ( builder : Self :: Builder ) -> DataFusionResult < ArrayRef > {
85+ let array: UnionArray = builder. try_into ( ) ?;
86+ Ok ( Arc :: new ( array) as ArrayRef )
87+ }
88+
89+ fn scalar ( value : Option < Self :: Item > ) -> ScalarValue {
90+ JsonUnionField :: scalar_value ( value)
91+ }
92+ }
93+
6994fn jiter_json_get_union ( opt_json : Option < & str > , path : & [ JsonPath ] ) -> Result < JsonUnionField , GetError > {
7095 if let Some ( ( mut jiter, peek) ) = jiter_json_find ( opt_json, path) {
7196 build_union ( & mut jiter, peek)
0 commit comments