Github user maropu commented on a diff in the pull request: https://github.com/apache/spark/pull/22237#discussion_r214218549 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/JsonFunctionsSuite.scala --- @@ -469,4 +470,26 @@ class JsonFunctionsSuite extends QueryTest with SharedSQLContext { checkAnswer(sql("""select json[0] from jsonTable"""), Seq(Row(null))) } + + test("from_json invalid json - check modes") { + val df = Seq("""{"a" 1}""", """{"a": 2}""").toDS() + val schema = new StructType().add("a", IntegerType) + + checkAnswer( + df.select(from_json($"value", schema, Map("mode" -> "PERMISSIVE"))), + Row(Row(null)) :: Row(Row(2)) :: Nil) + + val exception1 = intercept[SparkException] { + df.select(from_json($"value", schema, Map("mode" -> "FAILFAST"))).collect() + }.getMessage + assert(exception1.contains( + "Malformed records are detected in record parsing. Parse Mode: FAILFAST.")) + + val exception2 = intercept[AnalysisException] { + df.select(from_json($"value", schema, Map("mode" -> "DROPMALFORMED"))).collect() --- End diff -- Can you fix the code to throw an analysis exception in analysis phases instead of execution phases (`.collect()` called)?
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org