Skip to content

Commit

Permalink
Fix a wrong indentation issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarutak committed Apr 16, 2021
1 parent 4aee19e commit a77d95b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.apache.spark.sql.catalyst.json
import java.io.Writer

import com.fasterxml.jackson.core._
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter

import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.expressions.SpecializedGetters
Expand Down Expand Up @@ -73,7 +74,7 @@ private[sql] class JacksonGenerator(

private val gen = {
val generator = new JsonFactory().createGenerator(writer).setRootValueSeparator(null)
if (options.pretty) generator.useDefaultPrettyPrinter() else generator
if (options.pretty) generator.setPrettyPrinter(new DefaultPrettyPrinter("")) else generator
}

private val lineSeparator: String = options.lineSeparatorInWrite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2844,6 +2844,31 @@ abstract class JsonSuite
assert(readback.collect sameElements Array(Row(0), Row(1), Row(2)))
}
}

test("SPARK-35104: Fix wrong indentation for multiple JSON even if `pretty` option is true") {
withSQLConf(SQLConf.LEAF_NODE_DEFAULT_PARALLELISM.key -> "1") {
withTempPath { path =>
val basePath = path.getCanonicalPath
val df = Seq("a", "b", "c").toDF
df.write.option("pretty", "true").json(basePath)

val expectedText =
s"""{
| "value" : "a"
|}
|{
| "value" : "b"
|}
|{
| "value" : "c"
|}
|""".stripMargin
val actualText = spark.read.option("wholetext", "true")
.text(basePath).map(_.getString(0)).collect().mkString
assert(actualText === expectedText)
}
}
}
}

class JsonV1Suite extends JsonSuite {
Expand Down

0 comments on commit a77d95b

Please sign in to comment.