-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert varbinary MySQL columns to a readable form when sampling them
Summary: EN-160 #close Test Plan: manual Reviewers: carl, hurshal, ankur, john, allan Reviewed By: allan Subscribers: engineering-list Differential Revision: https://grizzly.memsql.com/D14946
- Loading branch information
Wayne Song
committed
Mar 1, 2016
1 parent
e443b97
commit c80241a
Showing
5 changed files
with
43 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
common/src/main/scala/com/memsql/spark/util/StringConversionUtils.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.memsql.spark.util | ||
|
||
object StringConversionUtils { | ||
def byteArrayToReadableString(bytes: Array[Byte]): String = { | ||
// Build up a string with hex encoding such that printable ASCII | ||
// characters get added as-is but other characters are added as an | ||
// escape sequence (e.g. \x7f). | ||
val sb = new StringBuilder() | ||
bytes.foreach(b => { | ||
if (b >= 0x20 && b <= 0x7e) { | ||
sb.append(b.toChar) | ||
} else { | ||
sb.append("\\x%02x".format(b)) | ||
} | ||
}) | ||
sb.toString | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters