Github user vanzin commented on a diff in the pull request:
https://github.com/apache/spark/pull/5236#discussion_r27441386
--- Diff: core/src/main/scala/org/apache/spark/util/Utils.scala ---
@@ -1010,6 +1010,65 @@ private[spark] object Utils extends Logging {
)
}
+ /** Check whether a time-suffix was provided for the time string. */
+ private def hasTimeSuffix(str: String) : Boolean = {
+ val lower = str.toLowerCase.trim()
+ lower.endsWith("ms") || lower.endsWith("us") || lower.endsWith("s")
+ }
+
+ val timeError = "Time must be specified as seconds (s), " +
+ "milliseconds (ms), or microseconds (us) e.g. 50s, 100ms, or 250us."
+
+ /**
+ * 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.
+ */
+ @throws(classOf[NumberFormatException])
+ private def timeStringToUs(str: String) : Long = {
+ try {
+ val lower = str.toLowerCase.trim()
+ if (lower.endsWith("ms")) {
+ lower.substring(0, lower.length - 2).toLong * 1000
+ } else if (lower.endsWith("us")) {
+ lower.substring(0, lower.length - 2).toLong
+ } else if (lower.endsWith("s")) {
+ lower.substring(0, lower.length - 1).toLong * 1000 * 1000
+ } else {
+ // Invalid suffix, force correct formatting
+ lower.toLong
+ }
+ } catch {
+ case e: NumberFormatException => throw new
NumberFormatException(timeError)
+ }
+ }
+
+ /**
+ * Convert a time parameter such as (50s, 100ms, or 250us) to
microseconds for internal use. If
+ * no suffix is provided, the passed number is assumed to be in us.
+ */
+ @throws(classOf[NumberFormatException])
+ def timeStringAsUs(str: String): Long = {
+ timeStringToUs(str)
+ }
+
+ /**
+ * Convert a time parameter such as (50s, 100ms, or 250us) to
microseconds for internal use. If
+ * no suffix is provided, the passed number is assumed to be in ms.
+ */
+ @throws(classOf[NumberFormatException])
+ def timeStringAsMs(str : String) : Long = {
+ timeStringToUs(str)/1000
--- End diff --
nit: spaces between `/` (here and elsewhere)
---
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]