Github user NathanHowell commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16386#discussion_r100474809
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/json/JacksonParser.scala
 ---
    @@ -48,69 +47,102 @@ class JacksonParser(
     
       // A `ValueConverter` is responsible for converting a value from 
`JsonParser`
       // to a value in a field for `InternalRow`.
    -  private type ValueConverter = (JsonParser) => Any
    +  private type ValueConverter = JsonParser => AnyRef
     
       // `ValueConverter`s for the root schema for all fields in the schema
    -  private val rootConverter: ValueConverter = makeRootConverter(schema)
    +  private val rootConverter = makeRootConverter(schema)
     
       private val factory = new JsonFactory()
       options.setJacksonOptions(factory)
     
       private val emptyRow: Seq[InternalRow] = Seq(new 
GenericInternalRow(schema.length))
     
    +  private val corruptFieldIndex = 
schema.getFieldIndex(options.columnNameOfCorruptRecord)
    +
       @transient
    -  private[this] var isWarningPrintedForMalformedRecord: Boolean = false
    +  private var printWarningForMalformedRecord: (() => UTF8String) => Unit = 
{ record =>
    +    def sampleRecord: String = {
    +      if (options.wholeFile) {
    +        ""
    +      } else {
    +        s"Sample record: ${record()}\n"
    +      }
    +    }
    +
    +    def footer: String = {
    +      s"""Code example to print all malformed records (scala):
    +         |===================================================
    +         |// The corrupted record exists in column 
${options.columnNameOfCorruptRecord}.
    +         |val parsedJson = spark.read.json("/path/to/json/file/test.json")
    +         |
    +       """.stripMargin
    +    }
    +
    +    if (options.permissive) {
    +      logWarning(
    +        s"""Found at least one malformed record. The JSON reader will 
replace
    +           |all malformed records with placeholder null in current 
$PERMISSIVE_MODE parser mode.
    +           |To find out which corrupted records have been replaced with 
null, please use the
    +           |default inferred schema instead of providing a custom schema.
    +           |
    +           |${sampleRecord ++ footer}
    +           |
    +         """.stripMargin)
    +    } else if (options.dropMalformed) {
    +      logWarning(
    +        s"""Found at least one malformed record. The JSON reader will drop
    +           |all malformed records in current $DROP_MALFORMED_MODE parser 
mode. To find out which
    +           |corrupted records have been dropped, please switch the parser 
mode to $PERMISSIVE_MODE
    +           |mode and use the default inferred schema.
    +           |
    +           |${sampleRecord ++ footer}
    +           |
    +         """.stripMargin)
    +    }
    +
    +    printWarningForMalformedRecord = _ => ()
    --- End diff --
    
    @cloud-fan please take a look at aafe7bded6e614dddaed74d15cecfb8b1a78a639, 
I hope this is more clear


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to