@@ -83,14 +83,77 @@ async fn test_json_get_union() {
8383}
8484
8585#[ tokio:: test]
86- async fn test_json_get_array ( ) {
86+ async fn test_json_get_array_elem ( ) {
8787 let sql = "select json_get('[1, 2, 3]', 2)" ;
8888 let batches = run_query ( sql) . await . unwrap ( ) ;
8989 let ( value_type, value_repr) = display_val ( batches) . await ;
9090 assert ! ( matches!( value_type, DataType :: Union ( _, _) ) ) ;
9191 assert_eq ! ( value_repr, "{int=3}" ) ;
9292}
9393
94+ #[ tokio:: test]
95+ async fn test_json_get_array_basic_numbers ( ) {
96+ let sql = "select json_get_array('[1, 2, 3]')" ;
97+ let batches = run_query ( sql) . await . unwrap ( ) ;
98+ let ( value_type, value_repr) = display_val ( batches) . await ;
99+ assert ! ( matches!( value_type, DataType :: List ( _) ) ) ;
100+ assert_eq ! ( value_repr, "[1, 2, 3]" ) ;
101+ }
102+
103+ #[ tokio:: test]
104+ async fn test_json_get_array_mixed_types ( ) {
105+ let sql = r#"select json_get_array('["hello", 42, true, null, 3.14]')"# ;
106+ let batches = run_query ( sql) . await . unwrap ( ) ;
107+ let ( value_type, value_repr) = display_val ( batches) . await ;
108+ assert ! ( matches!( value_type, DataType :: List ( _) ) ) ;
109+ assert_eq ! ( value_repr, r#"["hello", 42, true, null, 3.14]"# ) ;
110+ }
111+
112+ #[ tokio:: test]
113+ async fn test_json_get_array_nested_objects ( ) {
114+ let sql = r#"select json_get_array('[{"name": "John"}, {"age": 30}]')"# ;
115+ let batches = run_query ( sql) . await . unwrap ( ) ;
116+ let ( value_type, value_repr) = display_val ( batches) . await ;
117+ assert ! ( matches!( value_type, DataType :: List ( _) ) ) ;
118+ assert_eq ! ( value_repr, r#"[{"name": "John"}, {"age": 30}]"# ) ;
119+ }
120+
121+ #[ tokio:: test]
122+ async fn test_json_get_array_nested_arrays ( ) {
123+ let sql = r#"select json_get_array('[[1, 2], [3, 4]]')"# ;
124+ let batches = run_query ( sql) . await . unwrap ( ) ;
125+ let ( value_type, value_repr) = display_val ( batches) . await ;
126+ assert ! ( matches!( value_type, DataType :: List ( _) ) ) ;
127+ assert_eq ! ( value_repr, "[[1, 2], [3, 4]]" ) ;
128+ }
129+
130+ #[ tokio:: test]
131+ async fn test_json_get_array_empty ( ) {
132+ let sql = "select json_get_array('[]')" ;
133+ let batches = run_query ( sql) . await . unwrap ( ) ;
134+ let ( value_type, value_repr) = display_val ( batches) . await ;
135+ assert ! ( matches!( value_type, DataType :: List ( _) ) ) ;
136+ assert_eq ! ( value_repr, "[]" ) ;
137+ }
138+
139+ #[ tokio:: test]
140+ async fn test_json_get_array_invalid_json ( ) {
141+ let sql = "select json_get_array('')" ;
142+ let batches = run_query ( sql) . await . unwrap ( ) ;
143+ let ( value_type, value_repr) = display_val ( batches) . await ;
144+ assert ! ( matches!( value_type, DataType :: List ( _) ) ) ;
145+ assert_eq ! ( value_repr, "" ) ;
146+ }
147+
148+ #[ tokio:: test]
149+ async fn test_json_get_array_with_path ( ) {
150+ let sql = r#"select json_get_array('{"items": [1, 2, 3]}', 'items')"# ;
151+ let batches = run_query ( sql) . await . unwrap ( ) ;
152+ let ( value_type, value_repr) = display_val ( batches) . await ;
153+ assert ! ( matches!( value_type, DataType :: List ( _) ) ) ;
154+ assert_eq ! ( value_repr, "[1, 2, 3]" ) ;
155+ }
156+
94157#[ tokio:: test]
95158async fn test_json_get_equals ( ) {
96159 let e = run_query ( r"select name, json_get(json_data, 'foo')='abc' from test" )
0 commit comments