dongjoon-hyun 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_r400636724
########## File path: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/JsonExpressionsSuite.scala ########## @@ -791,4 +791,42 @@ class JsonExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper with checkDecimalInfer(_, """struct<d:decimal(7,3)>""") } } + + test("json_object_keys") { + val null_object = """""" + val empty_json_object = """{}""" + val simple_json_object = """{"key": 1}""" + val another_simple_json_object = """{"key": "value", "key2": 2}""" + val json_object_with_array = """{"arrayKey": [1, 2, 3]}""" + val another_json_object_with_array = """{"key":[1,2,3,{"key":"value"},[1,2,3]]}""" + val complex_json_object = """{"f1":"abc","f2":{"f3":"a", "f4":"b"}}""" + val another_complex_json_object = """{"k1": [1, 2, {"key": 5}], "k2": {"key2": [1, 2]}}""" + val empty_json_array = """[]""" + val invalid_json_object = """{[1,2]}""" + val another_invalid_json_object = """{"key": 45, "random_string"}""" + + checkEvaluation(JsonObjectKeys(Literal(empty_json_object)), Seq.empty[UTF8String]) + checkEvaluation(JsonObjectKeys(Literal(simple_json_object)), Seq("key")) + checkEvaluation(JsonObjectKeys(Literal(another_simple_json_object)), Seq("key", "key2")) + checkEvaluation(JsonObjectKeys(Literal(json_object_with_array)), Seq("arrayKey")) + checkEvaluation(JsonObjectKeys(Literal(another_json_object_with_array)), Seq("key")) + checkEvaluation(JsonObjectKeys(Literal(complex_json_object)), Seq("f1", "f2")) + checkEvaluation(JsonObjectKeys(Literal(another_complex_json_object)), Seq("k1", "k2")) + checkEvaluation(JsonObjectKeys(Literal(invalid_json_object)), null) + checkEvaluation(JsonObjectKeys(Literal(another_invalid_json_object)), null) + + val exception = intercept[TestFailedException] { + checkEvaluation(JsonObjectKeys(Literal(null_object)), null) + }.getCause + + assert(exception.isInstanceOf[IllegalArgumentException]) Review comment: ditto. This should be checked at 818. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org