Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

dayamr
Copy link
Collaborator

@dayamr dayamr commented Feb 15, 2017

This PR is first one among the 'dateTime' based sort feature.

Copy link
Collaborator

@cdeszaq cdeszaq left a 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
Copy link
Collaborator

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))
Copy link
Collaborator

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?

Copy link
Collaborator

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?

Copy link
Collaborator

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?

Copy link
Collaborator Author

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);
Copy link
Collaborator

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 {
Copy link
Collaborator

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));
Copy link
Collaborator

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());
Copy link
Collaborator

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"),
Copy link
Collaborator

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...

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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")
Copy link
Collaborator

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 😉

Copy link
Collaborator

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.

@dayamr dayamr changed the title [ADDIGITS-4978] dateTime specified as sortable field in sorting clause dateTime specified as sortable field in sorting clause Feb 15, 2017
@cdeszaq
Copy link
Collaborator

cdeszaq commented Feb 27, 2017

Does #178 supercede this PR? Can this one be closed, or is it different from #178?

@dayamr
Copy link
Collaborator Author

dayamr commented Feb 27, 2017

PR #178 considers all these changes. Hence closing this PR.

@dayamr dayamr closed this Feb 27, 2017
@cdeszaq cdeszaq deleted the ADDIGITS-4978_add_dateTime_sort branch April 4, 2017 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants