MaxGekk commented on a change in pull request #27836: [SPARK-31009][SQL] 
Support json_object_keys function
URL: https://github.com/apache/spark/pull/27836#discussion_r399427492
 
 

 ##########
 File path: sql/core/src/test/resources/sql-tests/results/json-functions.sql.out
 ##########
 @@ -346,6 +346,96 @@ org.apache.spark.sql.AnalysisException
 cannot resolve 'schema_of_json(jsontable.`jsonField`)' due to data type 
mismatch: The input json should be a foldable string expression and not null; 
however, got jsontable.`jsonField`.; line 1 pos 7
 
 
+-- !query
+select json_object_keys('')
+-- !query schema
+struct<>
+-- !query output
+java.lang.IllegalArgumentException
+json_object_keys expect a JSON object but nothing is provided.
+
+
+-- !query
+select json_object_keys('{"key": 1}')
+-- !query schema
+struct<json_object_keys({"key": 1}):array<string>>
+-- !query output
+["key"]
+
+
+-- !query
+select json_object_keys('{}')
+-- !query schema
+struct<json_object_keys({}):array<string>>
+-- !query output
+[]
+
+
+-- !query
+select json_object_keys('{"key": "value", "key2": 2}')
+-- !query schema
+struct<json_object_keys({"key": "value", "key2": 2}):array<string>>
+-- !query output
+["key","key2"]
+
+
+-- !query
+select json_object_keys('{"arrayKey": [1, 2, 3]}')
+-- !query schema
+struct<json_object_keys({"arrayKey": [1, 2, 3]}):array<string>>
+-- !query output
+["arrayKey"]
+
+
+-- !query
+select json_object_keys('{"key":[1,2,3,{"key":"value"},[1,2,3]]}')
+-- !query schema
+struct<json_object_keys({"key":[1,2,3,{"key":"value"},[1,2,3]]}):array<string>>
+-- !query output
+["key"]
+
+
+-- !query
+select json_object_keys('{"f1":"abc","f2":{"f3":"a", "f4":"b"}}')
+-- !query schema
+struct<json_object_keys({"f1":"abc","f2":{"f3":"a", "f4":"b"}}):array<string>>
+-- !query output
+["f1","f2"]
+
+
+-- !query
+select json_object_keys('{"k1": [1, 2, {"key": 5}], "k2": {"key2": [1, 2]}}')
+-- !query schema
+struct<json_object_keys({"k1": [1, 2, {"key": 5}], "k2": {"key2": [1, 
2]}}):array<string>>
+-- !query output
+["k1","k2"]
+
+
+-- !query
+select json_object_keys('{[1,2]}')
+-- !query schema
+struct<json_object_keys({[1,2]}):array<string>>
+-- !query output
+NULL
+
+
+-- !query
+select json_object_keys('{"key": 45, "random_string"}')
+-- !query schema
+struct<json_object_keys({"key": 45, "random_string"}):array<string>>
+-- !query output
+NULL
+
+
+-- !query
+select json_object_keys('[1, 2, 3]')
+-- !query schema
+struct<>
+-- !query output
+java.lang.IllegalArgumentException
 
 Review comment:
   Why do you throw `IllegalArgumentException` for `'[1, 2, 3]'` but NULL for 
`'{"key": 45, "random_string"}'`? It looks slightly inconsistent though both 
input are invalid.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to