@@ -10,6 +10,7 @@ use datafusion::scalar::ScalarValue;
1010use jiter:: { Jiter , NumberAny , NumberInt , Peek } ;
1111
1212use crate :: common:: InvokeResult ;
13+ use crate :: common:: Sortedness ;
1314use crate :: common:: { get_err, invoke, jiter_json_find, return_type_check, GetError , JsonPath } ;
1415use crate :: common_macros:: make_udf_function;
1516use crate :: common_union:: { JsonUnion , JsonUnionField } ;
@@ -18,22 +19,39 @@ make_udf_function!(
1819 JsonGet ,
1920 json_get,
2021 json_data path,
21- r#"Get a value from a JSON string by its "path""#
22+ r#"Get a value from a JSON string by its "path""# ,
23+ Sortedness :: Unspecified
2224) ;
2325
24- // build_typed_get!(JsonGet, "json_get", Union, Float64Array, jiter_json_get_float);
26+ make_udf_function ! (
27+ JsonGet ,
28+ json_get_top_level_sorted,
29+ json_data path,
30+ r#"Get a value from a JSON string by its "path"; assumes the JSON string's top level object's keys are sorted."# ,
31+ Sortedness :: TopLevel
32+ ) ;
33+
34+ make_udf_function ! (
35+ JsonGet ,
36+ json_get_recursive_sorted,
37+ json_data path,
38+ r#"Get a value from a JSON string by its "path"; assumes all object's keys are sorted."# ,
39+ Sortedness :: Recursive
40+ ) ;
2541
2642#[ derive( Debug ) ]
2743pub ( super ) struct JsonGet {
2844 signature : Signature ,
2945 aliases : [ String ; 1 ] ,
46+ sorted : Sortedness ,
3047}
3148
32- impl Default for JsonGet {
33- fn default ( ) -> Self {
49+ impl JsonGet {
50+ pub fn new ( sorted : Sortedness ) -> Self {
3451 Self {
3552 signature : Signature :: variadic_any ( Volatility :: Immutable ) ,
36- aliases : [ "json_get" . to_string ( ) ] ,
53+ aliases : [ format ! ( "json_get{}" , sorted. function_name_suffix( ) ) ] ,
54+ sorted,
3755 }
3856 }
3957}
@@ -56,7 +74,7 @@ impl ScalarUDFImpl for JsonGet {
5674 }
5775
5876 fn invoke ( & self , args : & [ ColumnarValue ] ) -> DataFusionResult < ColumnarValue > {
59- invoke :: < JsonUnion > ( args, jiter_json_get_union)
77+ invoke :: < JsonUnion > ( args, |json , path| jiter_json_get_union ( json , path , self . sorted ) )
6078 }
6179
6280 fn aliases ( & self ) -> & [ String ] {
@@ -93,8 +111,12 @@ impl InvokeResult for JsonUnion {
93111 }
94112}
95113
96- fn jiter_json_get_union ( opt_json : Option < & str > , path : & [ JsonPath ] ) -> Result < JsonUnionField , GetError > {
97- if let Some ( ( mut jiter, peek) ) = jiter_json_find ( opt_json, path) {
114+ fn jiter_json_get_union (
115+ opt_json : Option < & str > ,
116+ path : & [ JsonPath ] ,
117+ sorted : Sortedness ,
118+ ) -> Result < JsonUnionField , GetError > {
119+ if let Some ( ( mut jiter, peek) ) = jiter_json_find ( opt_json, path, sorted) {
98120 build_union ( & mut jiter, peek)
99121 } else {
100122 get_err ! ( )
0 commit comments