maropu commented on a change in pull request #30647:
URL: https://github.com/apache/spark/pull/30647#discussion_r539039354
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala
##########
@@ -304,10 +304,13 @@ class Dataset[T] private[sql](
// For cells that are beyond `truncate` characters, replace it with the
// first `truncate-3` and "..."
schema.fieldNames.toSeq +: data.map { row =>
- row.toSeq.map { cell =>
+ row.toSeq.zip(newDf.schema).map { case (cell, f) =>
val str = cell match {
case null => "null"
case binary: Array[Byte] =>
binary.map("%02X".format(_)).mkString("[", " ", "]")
+ case _ if f.dataType == StringType =>
+ // Escapes meta-characters not to break the `showString` format
+ cell.toString.replaceAll("\n", "\\\\n").replaceAll("\t", "\\\\t")
Review comment:
Yea, that's a reasonable question; It seems `$` and `\` has a special
meaning in the second param of `replaceAll` and see:
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#replaceAll-java.lang.String-java.lang.String-
```
Note that backslashes (\) and dollar signs ($) in the replacement string may
cause the results
to be different than if it were being treated as a literal replacement
string; see Matcher.replaceAll.
Use Matcher.quoteReplacement(java.lang.String) to suppress the special
meaning
of these characters, if desired.
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]