Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.spark.sql.catalyst.util

import java.util.HexFormat
import java.util.concurrent.atomic.AtomicBoolean

import org.apache.spark.internal.Logging
Expand Down Expand Up @@ -101,11 +102,16 @@ object SparkStringUtils extends Logging {
truncatedString(seq, "", sep, "", maxFields)
}

private final lazy val SPACE_DELIMITED_UPPERCASE_HEX =
HexFormat.of().withDelimiter(" ").withUpperCase()

/**
* Returns a pretty string of the byte array which prints each byte as a hex digit and add spaces
* between them. For example, [1A C0].
*/
def getHexString(bytes: Array[Byte]): String = bytes.map("%02X".format(_)).mkString("[", " ", "]")
def getHexString(bytes: Array[Byte]): String = {
s"[${SPACE_DELIMITED_UPPERCASE_HEX.formatHex(bytes)}]"
}

def sideBySide(left: String, right: String): Seq[String] = {
sideBySide(left.split("\n").toImmutableArraySeq, right.split("\n").toImmutableArraySeq)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ object StringUtils extends Logging {
"(?s)" + out.result() // (?s) enables dotall mode, causing "." to match new lines
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the function that should be deleted in #42184?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I can not answer your question since I wasn't there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both org.apache.spark.sql.catalyst.util.StringUtils and getHexString are public, should we keep them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catalyst package is private by contract

* Returns a pretty string of the byte array which prints each byte as a hex digit and add spaces
* between them. For example, [1A C0].
*/
def getHexString(bytes: Array[Byte]): String = bytes.map("%02X".format(_)).mkString("[", " ", "]")

private[this] val trueStrings =
Set("t", "true", "y", "yes", "1").map(UTF8String.fromString)

Expand Down