Skip to content

Commit b5e5812

Browse files
bomengsrowen
authored andcommitted
[SPARK-12136][STREAMING] rddToFileName does not properly handle prefix and suffix parameters
The original code does not properly handle the cases where the prefix is null, but suffix is not null - the suffix should be used but is not. The fix is using StringBuilder to construct the proper file name. Author: bomeng <bmeng@us.ibm.com> Author: Bo Meng <mengbo@bos-macbook-pro.usca.ibm.com> Closes apache#10185 from bomeng/SPARK-12136. (cherry picked from commit e29704f) Signed-off-by: Sean Owen <sowen@cloudera.com>
1 parent f6d8661 commit b5e5812

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

streaming/src/main/scala/org/apache/spark/streaming/StreamingContext.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -887,12 +887,13 @@ object StreamingContext extends Logging {
887887
}
888888

889889
private[streaming] def rddToFileName[T](prefix: String, suffix: String, time: Time): String = {
890-
if (prefix == null) {
891-
time.milliseconds.toString
892-
} else if (suffix == null || suffix.length ==0) {
893-
prefix + "-" + time.milliseconds
894-
} else {
895-
prefix + "-" + time.milliseconds + "." + suffix
890+
var result = time.milliseconds.toString
891+
if (prefix != null && prefix.length > 0) {
892+
result = s"$prefix-$result"
893+
}
894+
if (suffix != null && suffix.length > 0) {
895+
result = s"$result.$suffix"
896896
}
897+
result
897898
}
898899
}

0 commit comments

Comments
 (0)