-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dateTime specified as sortable field in sorting clause #170
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changelog entry needed.
Initial quick-pass review complete. I didn't dig through it in great detail, but left a comments on the things I saw with a quick scan.
@@ -51,6 +51,17 @@ public OrderByColumn(PostAggregation postAggregation, SortDirection direction) { | |||
} | |||
|
|||
/** | |||
* Constructor. | |||
* | |||
* @param dateTime a dateTime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this constructor is quite different from the rest, and it takes very generic parameters, it should get more description as to why it exists and what it's intended to be used for. Additionally, the comment for this parameter is not great... if I give it, for example, 2017-02-01T10:25
, something tells me it wouldn't do the right thing.
If we could have a way to create this that didn't require the user to specify the column name, that would be great. A static factory method that takes a direction, for example.
if ( | ||
sorts != null && | ||
!sorts.isEmpty() && | ||
sorts.toLowerCase(Locale.ENGLISH).contains(DATE_TIME_STRING.toLowerCase(Locale.ENGLISH)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we simplify this conditional, or isolate it's complexity into a helper method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, why are we lower-casing this keyword? Do we do that anywhere else in the API for keywords?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also also, why use contains
, why not use startsWith
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we use contains, we can educate user with proper error message. If we use starts with, error message would be 'dateTime is not metric......'. It may restrict the user to think sort is allowed only for metrics.
@@ -114,6 +116,8 @@ | |||
|
|||
private final DruidFilterBuilder filterBuilder; | |||
|
|||
private Optional<OrderByColumn> dateTimeSort = Optional.ofNullable(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than defaulting to a null
Optional
, we should use Optional.emtpy()
} | ||
return Optional.of(new OrderByColumn(dateTimeWithDirection.get(0), sortDirection)); | ||
} | ||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be up a line
} catch (IllegalArgumentException ignored) { | ||
String sortDirectionName = dateTimeWithDirection.get(1); | ||
LOG.debug(SORT_DIRECTION_INVALID.logFormat(sortDirectionName)); | ||
throw new BadApiRequestException(SORT_DIRECTION_INVALID.format(sortDirectionName)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this code duplicated with the existing code that deals with sort ordering?
//Requested sort on dateTime - It has to be first field in the string | ||
this.dateTimeSort = generateDateTimeSortColumn(sorts.substring(0, sorts.indexOf(","))); | ||
//Separating dateTimeSort from the complete api sort value string | ||
sorts = sorts.substring(sorts.indexOf(",") + 1, sorts.length()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If sorts
is a method parameter, it's generally a bad idea to modify method parameters. They should be treated as immutable.
@@ -73,6 +73,8 @@ | |||
SORT_METRICS_NOT_SORTABLE_FORMAT("Sorting not possible on metric(s) '%s'."), | |||
SORT_METRICS_UNDEFINED("Metric(s) in sort expression '%s' do not exist."), | |||
|
|||
DATE_TIME_SORT_VALUE_INVALID("dateTime must always be the first field in the sort list"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, it doesn't always need to be the first field in the list. It only needs to be the 1st one when it's being sorted on...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we have decided to have dateTime as first value for the sort param if we want to sort based on dateTime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point is that if it's not sorted on at all, or there are no sorts, it doesn't need to be there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message is displayed only when dateTime
is part of the sort list but not the first one. If there is no sort list or if there is no request for dateTime
sort, we will not reach till this error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, and that's my point... the error message indicates (emphasis added):
dateTime must always be the first field
By the error message indicating always, it may be confusing. A more accurate error message would remove that confusion.
Response r = jtb.getHarness().target("data/shapes/day/color") | ||
.queryParam("metrics","height") | ||
.queryParam("dateTime","2014-09-01%2F2014-09-10") | ||
.queryParam("sort","dateTime|DESC,height|ASC") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this "success" test doesn't belong in the ErrorDataServletSpec
, I feel like it belongs in a Spec that's focused on sorting. If there isn't already a place that's testing that, we should make one 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we should add a test for sorting by dateTime
that doesn't specify the direction, and uses the default.
PR #178 considers all these changes. Hence closing this PR. |
This PR is first one among the 'dateTime' based sort feature.