Skip to content

Conversation

@kkhatua
Copy link
Contributor

@kkhatua kkhatua commented Feb 3, 2017

Fixed invalid representation of readable elapsed time using TimeUnit class in JDK.
e.g. 4545 sec is now correctly translated as 1h15m instead of 17h15m
TestCase has been added

@sudheeshkatkam
Copy link
Contributor

+1

Copy link
Contributor

@paul-rogers paul-rogers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor changes suggested. In particular, move the very handy duration format logic to a utility so we can reuse it elsewhere.

long milliSeconds = millis - TimeUnit.SECONDS.toMillis(TimeUnit.MILLISECONDS.toSeconds(millis));
String formattedDuration = "";
if (days >= 1) {
formattedDuration = days + "d" + hours + "h" + minutes + "m";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the display format? Maybe add some space:

5d 14h 2m

Instead of:

5d14h2m

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This display format is kept compact due to limited space within the cells of the table. Hence, we aim to keep only the first two major units. Hence, if something runs in hours, we report down to the minute, but not any more granular.

} else if (minutes >= 1) {
formattedDuration = minutes + "m" + seconds + "s";
} else {
formattedDuration = seconds + "." + milliSeconds + "s";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above won't work in general. If the time is 2 ms, you'll get an output of 0.2s, which is not quite right...

Here, consider using the very handy String.format method:

String.format("%.3f", seconds + milliSeconds / 1000.0 );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I'll update the test case as well and apply the String.format()

} else {
formattedDuration = seconds + "." + milliSeconds + "s";
}
return formattedDuration;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nit, but the code is clearer if you do:

if (cond1) {
    return expr1;
} else if (cond2) {
    return expr2;
} else {
    return expr3;
}

The above eliminates the temp variable and makes it very clear what is happening.

* @param millis Duration in milliseconds
* @return Human-Readable Duration Time
*/
public String shortDurationFormat(long millis) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used elsewhere? If so, consider making static (so we don't need an instance.) If only used here, consider making private.

In fact, maybe move this out to a utility class. This logic can be used anywhere we want to display a duration such as in logs, in tests, etc.

}
appendCell(timeFormat.format(new Date(p)), null);
String shortReadableDuration = shortDurationFormat(p);
appendCell(shortReadableDuration, link);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Drill, we like brevity:

appendCell(shortDurationFormat(p), link);

@kkhatua kkhatua force-pushed the DRILL-5230 branch 6 times, most recently from e837c62 to 94c0efb Compare February 6, 2017 22:54
@kkhatua
Copy link
Contributor Author

kkhatua commented Feb 6, 2017

@paul-rogers , @sudheeshkatkam
Committed changes based on your recommendations. I also noticed that some of the calls were passing fragment IDs as links, which were never applied. Based on the file history, my hunch is that it was meant for debugging and forgotten ever since. Corrected it by replacing these with the appropriate null values.

Copy link
Contributor

@paul-rogers paul-rogers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for moving the duration formatting to an easy-to-reuse utility!

One minor comment, one minor revision to the code that does the two format styles.

* @return Human-Readable Elapsed Time
*/
public static String getPrettyDuration(long startTimeMillis, long endTimeMillis) {
public static String getPrettyDuration(long startTimeMillis, long endTimeMillis, DurationFormat format) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is often cleaner to just have two methods, rather than one method with a "command". Since we need to split out the data into a bunch of fields, this can be done by another method that creates a structure. Then, since you've created the structure, it might as well be the class that does the format, and offer two format methods: compact and verbose.


/**
* Duration format definition
* @author kkhatua
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drill practice seems to be to omit the author. Many IDE's helpfully add this, but you can turn off that option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. Will fix that.

@kkhatua kkhatua force-pushed the DRILL-5230 branch 2 times, most recently from 3a17402 to e185c6d Compare February 9, 2017 02:07
Fixed invalid representation of readable elapsed time using `TimeUnit` class in JDK.
e.g. 4545 sec is now correctly translated as `1h15m` instead of `17h15m`
@kkhatua
Copy link
Contributor Author

kkhatua commented Feb 10, 2017

@paul-rogers Created a new SimpleDurationFormat class. We can expand to have more formats, or reimplement on lines of SimpleDateFormat by passing format strings in the future. Hope this helps.

Copy link
Contributor

@paul-rogers paul-rogers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pulling the duration format into a new class. Very helpful.
LGTM
+1

@kkhatua
Copy link
Contributor Author

kkhatua commented Feb 21, 2017

This closes PR #739

@kkhatua kkhatua closed this Feb 21, 2017
@kkhatua kkhatua deleted the DRILL-5230 branch February 27, 2017 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants