@@ -392,7 +392,7 @@ class JsonExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper with
392392 val jsonData = """ {"a": 1}"""
393393 val schema = StructType (StructField (" a" , IntegerType ) :: Nil )
394394 checkEvaluation(
395- JsonToStructs (schema, Map .empty, Literal (jsonData), gmtId, true ),
395+ JsonToStructs (schema, Map .empty, Literal (jsonData), gmtId),
396396 InternalRow (1 )
397397 )
398398 }
@@ -401,13 +401,13 @@ class JsonExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper with
401401 val jsonData = """ {"a" 1}"""
402402 val schema = StructType (StructField (" a" , IntegerType ) :: Nil )
403403 checkEvaluation(
404- JsonToStructs (schema, Map .empty, Literal (jsonData), gmtId, true ),
404+ JsonToStructs (schema, Map .empty, Literal (jsonData), gmtId),
405405 null
406406 )
407407
408408 // Other modes should still return `null`.
409409 checkEvaluation(
410- JsonToStructs (schema, Map (" mode" -> PermissiveMode .name), Literal (jsonData), gmtId, true ),
410+ JsonToStructs (schema, Map (" mode" -> PermissiveMode .name), Literal (jsonData), gmtId),
411411 null
412412 )
413413 }
@@ -416,70 +416,70 @@ class JsonExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper with
416416 val input = """ [{"a": 1}, {"a": 2}]"""
417417 val schema = ArrayType (StructType (StructField (" a" , IntegerType ) :: Nil ))
418418 val output = InternalRow (1 ) :: InternalRow (2 ) :: Nil
419- checkEvaluation(JsonToStructs (schema, Map .empty, Literal (input), gmtId, true ), output)
419+ checkEvaluation(JsonToStructs (schema, Map .empty, Literal (input), gmtId), output)
420420 }
421421
422422 test(" from_json - input=object, schema=array, output=array of single row" ) {
423423 val input = """ {"a": 1}"""
424424 val schema = ArrayType (StructType (StructField (" a" , IntegerType ) :: Nil ))
425425 val output = InternalRow (1 ) :: Nil
426- checkEvaluation(JsonToStructs (schema, Map .empty, Literal (input), gmtId, true ), output)
426+ checkEvaluation(JsonToStructs (schema, Map .empty, Literal (input), gmtId), output)
427427 }
428428
429429 test(" from_json - input=empty array, schema=array, output=empty array" ) {
430430 val input = " [ ]"
431431 val schema = ArrayType (StructType (StructField (" a" , IntegerType ) :: Nil ))
432432 val output = Nil
433- checkEvaluation(JsonToStructs (schema, Map .empty, Literal (input), gmtId, true ), output)
433+ checkEvaluation(JsonToStructs (schema, Map .empty, Literal (input), gmtId), output)
434434 }
435435
436436 test(" from_json - input=empty object, schema=array, output=array of single row with null" ) {
437437 val input = " { }"
438438 val schema = ArrayType (StructType (StructField (" a" , IntegerType ) :: Nil ))
439439 val output = InternalRow (null ) :: Nil
440- checkEvaluation(JsonToStructs (schema, Map .empty, Literal (input), gmtId, true ), output)
440+ checkEvaluation(JsonToStructs (schema, Map .empty, Literal (input), gmtId), output)
441441 }
442442
443443 test(" from_json - input=array of single object, schema=struct, output=single row" ) {
444444 val input = """ [{"a": 1}]"""
445445 val schema = StructType (StructField (" a" , IntegerType ) :: Nil )
446446 val output = InternalRow (1 )
447- checkEvaluation(JsonToStructs (schema, Map .empty, Literal (input), gmtId, true ), output)
447+ checkEvaluation(JsonToStructs (schema, Map .empty, Literal (input), gmtId), output)
448448 }
449449
450450 test(" from_json - input=array, schema=struct, output=null" ) {
451451 val input = """ [{"a": 1}, {"a": 2}]"""
452452 val schema = StructType (StructField (" a" , IntegerType ) :: Nil )
453453 val output = null
454- checkEvaluation(JsonToStructs (schema, Map .empty, Literal (input), gmtId, true ), output)
454+ checkEvaluation(JsonToStructs (schema, Map .empty, Literal (input), gmtId), output)
455455 }
456456
457457 test(" from_json - input=empty array, schema=struct, output=null" ) {
458458 val input = """ []"""
459459 val schema = StructType (StructField (" a" , IntegerType ) :: Nil )
460460 val output = null
461- checkEvaluation(JsonToStructs (schema, Map .empty, Literal (input), gmtId, true ), output)
461+ checkEvaluation(JsonToStructs (schema, Map .empty, Literal (input), gmtId), output)
462462 }
463463
464464 test(" from_json - input=empty object, schema=struct, output=single row with null" ) {
465465 val input = """ { }"""
466466 val schema = StructType (StructField (" a" , IntegerType ) :: Nil )
467467 val output = InternalRow (null )
468- checkEvaluation(JsonToStructs (schema, Map .empty, Literal (input), gmtId, true ), output)
468+ checkEvaluation(JsonToStructs (schema, Map .empty, Literal (input), gmtId), output)
469469 }
470470
471471 test(" from_json null input column" ) {
472472 val schema = StructType (StructField (" a" , IntegerType ) :: Nil )
473473 checkEvaluation(
474- JsonToStructs (schema, Map .empty, Literal .create(null , StringType ), gmtId, true ),
474+ JsonToStructs (schema, Map .empty, Literal .create(null , StringType ), gmtId),
475475 null
476476 )
477477 }
478478
479479 test(" SPARK-20549: from_json bad UTF-8" ) {
480480 val schema = StructType (StructField (" a" , IntegerType ) :: Nil )
481481 checkEvaluation(
482- JsonToStructs (schema, Map .empty, Literal (badJson), gmtId, true ),
482+ JsonToStructs (schema, Map .empty, Literal (badJson), gmtId),
483483 null )
484484 }
485485
@@ -491,14 +491,14 @@ class JsonExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper with
491491 c.set(2016 , 0 , 1 , 0 , 0 , 0 )
492492 c.set(Calendar .MILLISECOND , 123 )
493493 checkEvaluation(
494- JsonToStructs (schema, Map .empty, Literal (jsonData1), gmtId, true ),
494+ JsonToStructs (schema, Map .empty, Literal (jsonData1), gmtId),
495495 InternalRow (c.getTimeInMillis * 1000L )
496496 )
497497 // The result doesn't change because the json string includes timezone string ("Z" here),
498498 // which means the string represents the timestamp string in the timezone regardless of
499499 // the timeZoneId parameter.
500500 checkEvaluation(
501- JsonToStructs (schema, Map .empty, Literal (jsonData1), Option (" PST" ), true ),
501+ JsonToStructs (schema, Map .empty, Literal (jsonData1), Option (" PST" )),
502502 InternalRow (c.getTimeInMillis * 1000L )
503503 )
504504
@@ -512,8 +512,7 @@ class JsonExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper with
512512 schema,
513513 Map (" timestampFormat" -> " yyyy-MM-dd'T'HH:mm:ss" ),
514514 Literal (jsonData2),
515- Option (tz.getID),
516- true ),
515+ Option (tz.getID)),
517516 InternalRow (c.getTimeInMillis * 1000L )
518517 )
519518 checkEvaluation(
@@ -522,8 +521,7 @@ class JsonExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper with
522521 Map (" timestampFormat" -> " yyyy-MM-dd'T'HH:mm:ss" ,
523522 DateTimeUtils .TIMEZONE_OPTION -> tz.getID),
524523 Literal (jsonData2),
525- gmtId,
526- true ),
524+ gmtId),
527525 InternalRow (c.getTimeInMillis * 1000L )
528526 )
529527 }
@@ -532,7 +530,7 @@ class JsonExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper with
532530 test(" SPARK-19543: from_json empty input column" ) {
533531 val schema = StructType (StructField (" a" , IntegerType ) :: Nil )
534532 checkEvaluation(
535- JsonToStructs (schema, Map .empty, Literal .create(" " , StringType ), gmtId, true ),
533+ JsonToStructs (schema, Map .empty, Literal .create(" " , StringType ), gmtId),
536534 null
537535 )
538536 }
@@ -687,23 +685,24 @@ class JsonExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper with
687685
688686 test(" from_json missing fields" ) {
689687 for (forceJsonNullableSchema <- Seq (false , true )) {
690- val input =
691- """ {
688+ withSQLConf(SQLConf .FROM_JSON_FORCE_NULLABLE_SCHEMA .key -> forceJsonNullableSchema.toString) {
689+ val input =
690+ """ {
692691 | "a": 1,
693692 | "c": "foo"
694693 |}
695694 |""" .stripMargin
696- val jsonSchema = new StructType ()
697- .add(" a" , LongType , nullable = false )
698- .add(" b" , StringType , nullable = false )
699- .add(" c" , StringType , nullable = false )
700- val output = InternalRow (1L , null , UTF8String .fromString(" foo" ))
701- val expr = JsonToStructs (
702- jsonSchema, Map .empty, Literal .create(input, StringType ), gmtId, forceJsonNullableSchema )
703- checkEvaluation(expr, output)
704- val schema = expr.dataType
705- val schemaToCompare = if (forceJsonNullableSchema) jsonSchema.asNullable else jsonSchema
706- assert(schemaToCompare == schema)
695+ val jsonSchema = new StructType ()
696+ .add(" a" , LongType , nullable = false )
697+ .add(" b" , StringType , nullable = false )
698+ .add(" c" , StringType , nullable = false )
699+ val output = InternalRow (1L , null , UTF8String .fromString(" foo" ))
700+ val expr = JsonToStructs (jsonSchema, Map .empty, Literal .create(input, StringType ), gmtId)
701+ checkEvaluation(expr, output )
702+ val schema = expr.dataType
703+ val schemaToCompare = if (forceJsonNullableSchema) jsonSchema.asNullable else jsonSchema
704+ assert( schemaToCompare == schema)
705+ }
707706 }
708707 }
709708
0 commit comments