@@ -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,43 @@ 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)
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+ const ACCEPT_DICT_RETURN : bool = true ;
73+
74+ fn builder ( capacity : usize ) -> Self :: Builder {
75+ JsonUnion :: new ( capacity)
76+ }
77+
78+ fn append_value ( builder : & mut Self :: Builder , value : Option < Self :: Item > ) {
79+ if let Some ( value) = value {
80+ builder. push ( value) ;
81+ } else {
82+ builder. push_none ( ) ;
83+ }
84+ }
85+
86+ fn finish ( builder : Self :: Builder ) -> DataFusionResult < ArrayRef > {
87+ let array: UnionArray = builder. try_into ( ) ?;
88+ Ok ( Arc :: new ( array) as ArrayRef )
89+ }
90+
91+ fn scalar ( value : Option < Self :: Item > ) -> ScalarValue {
92+ JsonUnionField :: scalar_value ( value)
93+ }
94+ }
95+
6996fn jiter_json_get_union ( opt_json : Option < & str > , path : & [ JsonPath ] ) -> Result < JsonUnionField , GetError > {
7097 if let Some ( ( mut jiter, peek) ) = jiter_json_find ( opt_json, path) {
7198 build_union ( & mut jiter, peek)
0 commit comments