Github user vanzin commented on a diff in the pull request:
https://github.com/apache/spark/pull/5236#discussion_r27517486
--- Diff: core/src/main/scala/org/apache/spark/util/Utils.scala ---
@@ -1010,6 +1010,67 @@ private[spark] object Utils extends Logging {
)
}
+ val timeSuffixes = Map (
+ "us" -> TimeUnit.MICROSECONDS,
+ "ms" -> TimeUnit.MILLISECONDS,
+ "s" -> TimeUnit.SECONDS,
+ "min" -> TimeUnit.MINUTES,
+ "h" -> TimeUnit.HOURS,
+ "d" -> TimeUnit.DAYS
+ )
+ /**
+ * Convert a passed time string (e.g. 50s, 100ms, or 250us) to a
microsecond count for
+ * internal use. If no suffix is provided a direct conversion is
attempted.
+ */
+ def parseTimeString(str: String) : (Option[TimeUnit], Long) = {
--- End diff --
I think this method would be simpler if it took the desired "default" unit
as an argument. For example:
def convert(str: String, tgt: TimeUnit): Long = {
timeSuffixes
.collectFirst { case (k,v) if str.endsWith(k) =>
tgt.convert(str.substring(0, str.length() - k.length()).toLong,
v)
}
.getOrElse(str.toLong)
}
Then:
def timeStringAsMs(str : String) : Long = convert(str,
TimeUnit.MILLISECONDS)
(Assuming I understood what it means to have the time string with no
suffix.)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]