Github user ilganeli commented on a diff in the pull request:
https://github.com/apache/spark/pull/5236#discussion_r28037051
--- Diff:
network/common/src/main/java/org/apache/spark/network/util/JavaUtils.java ---
@@ -121,4 +125,69 @@ private static boolean isSymlink(File file) throws
IOException {
}
return
!fileInCanonicalDir.getCanonicalFile().equals(fileInCanonicalDir.getAbsoluteFile());
}
+
+ private static ImmutableMap<String, TimeUnit> timeSuffixes =
+ ImmutableMap.<String, TimeUnit>builder()
+ .put("us", TimeUnit.MICROSECONDS)
+ .put("ms", TimeUnit.MILLISECONDS)
+ .put("s", TimeUnit.SECONDS)
+ .put("m", TimeUnit.MINUTES)
+ .put("min", TimeUnit.MINUTES)
+ .put("h", TimeUnit.HOURS)
+ .put("d", TimeUnit.DAYS)
+ .build();
+
+ /**
+ * Convert a passed time string (e.g. 50s, 100ms, or 250us) to a time
count for
+ * internal use. If no suffix is provided a direct conversion is
attempted.
+ */
+ private static long parseTimeString(String str, TimeUnit unit) {
+ String lower = str.toLowerCase().trim();
+
+ try {
+ String suffix = "";
+ long val = -1;
+ Matcher m = Pattern.compile("(-?[0-9]+)([a-z]+)?").matcher(lower);
+ if (m.matches()) {
+ val = Long.parseLong(m.group(1));
+ suffix = m.group(2);
+ } else {
+ throw new NumberFormatException("Failed to parse time string: " +
str);
+ }
+
+ return unit.convert(val, (suffix != null) &&
timeSuffixes.containsKey(suffix) ?
--- End diff --
Marcelo - great catch! I've added a test case for this and fixed it in the
latest commit.
Sent with Good (www.good.com)
-----Original Message-----
From: Marcelo Vanzin
[[email protected]<mailto:[email protected]>]
Sent: Wednesday, April 08, 2015 11:58 PM Eastern Standard Time
To: apache/spark
Cc: Ganelin, Ilya
Subject: Re: [spark] [SPARK-5931][CORE] Use consistent naming for time
properties (#5236)
In
network/common/src/main/java/org/apache/spark/network/util/JavaUtils.java<https://github.com/apache/spark/pull/5236#discussion_r28033893>:
> + */
> + private static long parseTimeString(String str, TimeUnit unit) {
> + String lower = str.toLowerCase().trim();
> +
> + try {
> + String suffix = "";
> + long val = -1;
> + Matcher m = Pattern.compile("(-?[0-9]+)([a-z]+)?").matcher(lower);
> + if (m.matches()) {
> + val = Long.parseLong(m.group(1));
> + suffix = m.group(2);
> + } else {
> + throw new NumberFormatException("Failed to parse time string: "
+ str);
> + }
> +
> + return unit.convert(val, (suffix != null) &&
timeSuffixes.containsKey(suffix) ?
This will use the unit parameter for any suffix that is not in
timeSuffixes. The containsKey check should be separate and an exception should
be thrown if the suffix is not there.
The unit tests don't catch this because all the invalid suffixes have
spaces in them, so the regex doesn't match.
â
Reply to this email directly or view it on
GitHub<https://github.com/apache/spark/pull/5236/files#r28033893>.
________________________________________________________
The information contained in this e-mail is confidential and/or proprietary
to Capital One and/or its affiliates. The information transmitted herewith is
intended only for use by the individual or entity to which it is addressed. If
the reader of this message is not the intended recipient, you are hereby
notified that any review, retransmission, dissemination, distribution, copying
or other use of, or taking of any action in reliance upon this information is
strictly prohibited. If you have received this communication in error, please
contact the sender and delete the material from your computer.
---
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]