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

    https://github.com/apache/spark/pull/16386#discussion_r100650450
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/json/JacksonParser.scala
 ---
    @@ -394,36 +447,32 @@ class JacksonParser(
       }
     
       /**
    -   * Parse the string JSON input to the set of [[InternalRow]]s.
    +   * Parse the JSON input to the set of [[InternalRow]]s.
    +   *
    +   * @param recordLiteral an optional function that will be used to 
generate
    +   *   the corrupt record text instead of record.toString
        */
    -  def parse(input: String): Seq[InternalRow] = {
    -    if (input.trim.isEmpty) {
    -      Nil
    -    } else {
    -      try {
    -        Utils.tryWithResource(factory.createParser(input)) { parser =>
    -          parser.nextToken()
    -          rootConverter.apply(parser) match {
    -            case null => failedRecord(input)
    -            case row: InternalRow => row :: Nil
    -            case array: ArrayData =>
    -              // Here, as we support reading top level JSON arrays and 
take every element
    -              // in such an array as a row, this case is possible.
    -              if (array.numElements() == 0) {
    -                Nil
    -              } else {
    -                array.toArray[InternalRow](schema)
    -              }
    -            case _ =>
    -              failedRecord(input)
    +  def parse[T](
    +      record: T,
    +      createParser: (JsonFactory, T) => JsonParser,
    +      recordLiteral: PartialFunction[T, UTF8String] = 
PartialFunction.empty): Seq[InternalRow] = {
    --- End diff --
    
    Passing a function in instead of a closure saves an allocation that will be 
held for the duration of parsing, and is likely to be promoted to a later GC 
generation.
    
    If we went the closure route the function signature should be this:
    
    ```scala
    def parse(
      createParser: JsonFactory => JsonParser,
      recordLiteral: => UTF8String): Seq[InternalRow]
    ```


---
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