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

support only string format for date, root object & date range #28117

Merged
merged 5 commits into from
Aug 27, 2018

Conversation

nikoncode
Copy link
Contributor

@nikoncode nikoncode commented Jan 6, 2018

Limit date format attribute to String values only (to avoid serialization issues)
Closes #23650

@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

1 similar comment
@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@colings86 colings86 added >bug :Search Foundations/Mapping Index mappings, including merging and defining field types labels Apr 24, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

@cbuescher
Copy link
Member

@nikoncode sorry for the delay on this, I just found this in unanswered PR while scanning issues. I will update the branch by merging in master if you don't mind and will take a first look then.

@cbuescher cbuescher self-assigned this Jul 24, 2018
 Conflicts:
	core/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java
	core/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java
	core/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java
	core/src/test/java/org/elasticsearch/index/mapper/RootObjectMapperTests.java
Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

@nikoncode thanks again for opening this, I think the PR looks quite good already but I left a suggestion for a change. Would you be interested in making this change? I understand that after waiting for quite some time you might not be interested in working on this any longer. Let me know if you want to pick it up or would like somebody else to work on it. I think its a good change to get in.

@@ -265,7 +265,10 @@ private static IndexOptions nodeIndexOptionValue(final Object propNode) {
}

public static FormatDateTimeFormatter parseDateTimeFormatter(Object node) {
return Joda.forPattern(node.toString());
if (node instanceof String) {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of instance testing here I would suggest changing the method to only take a String argument (the format) and change all call sites to convert to String instead. I should be save to do so since we to it here anyway currently.
That way we also don't need to throw an exception for bad formats, Jodas "forPattern" will do so already.

@nikoncode
Copy link
Contributor Author

@cbuescher I'll handle it and mention you again to review.

@nikoncode
Copy link
Contributor Author

nikoncode commented Jul 29, 2018

@cbuescher I don't think that your suggestion is relevant.

Problem of the original issue is using String.toString() method on List to convert input into string value. As you know, this method produce comma separated values wrapped in square brackets (for example [el1]) and Jodas parser successfully parse this format and threat square brackets as part of user input. We need to differentiate cases when we have List separately from String cases. To do it I have added additional validation condition. Just to implement validation in single place.

If I will implement your recommendation:

  • Instead of generic validation (1 place) I will need to put the same condition to filter out this case before any usage (from 1 to 3 places).
  • I have two option how to convert parameter value:
    • String.toString() - just doesn't solve the problem;
    • (String) format - solves problem but throws ClassCastException instead of meaningful message, we can add 3 more catches to produce good message (see point one);
  • parseDateTimeFormatter method is part of TypeParsers class - the responsibility of this class is to extract useful objects from untyped values (and validate if required). Just look on any other method in this class, all of them get Object as input parameter and then going through validation + conversion chain returns useful value as the result.

@cbuescher
Copy link
Member

cbuescher commented Aug 6, 2018

Problem of the original issue is using String.toString() method on List to convert input into string value.

I see. I was trying to avoid adding the instanceof check and thought that simply using "toString()" at the call site would work. But I agree this is a bit awkward on Lists, although they would still be rejected by Joda then due to the contained square brackets, for example. But the exception messages are not very descriptive in that case, which is why you convinced me that your solution is better. I will run CI now and merge once that has passed sucessfully.

@cbuescher
Copy link
Member

@elasticmachine test this please

@cbuescher
Copy link
Member

@nikoncode would you mind adding a bit more detail to the first comment, since this is what the final commit message will be based on? Otherwise I can also write a few lines, but I think its better if the commit author adds a few words.

@cbuescher
Copy link
Member

@nikoncode I took the liberty to merge in the current state of the master branch because CI was failing without it. Hope you don't mind.
@elasticmachine test this please

@nikoncode
Copy link
Contributor Author

nikoncode commented Aug 12, 2018

@cbuescher I have changed my message.
Does it specific enough now?

@javanna javanna requested a review from cbuescher August 16, 2018 14:03
Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

Still looking good. I will merge this in shortly

@cbuescher cbuescher merged commit f1f6d4e into elastic:master Aug 27, 2018
cbuescher pushed a commit that referenced this pull request Aug 27, 2018
Limit date `format` attribute to String values only.

Closes #23650
jasontedor added a commit that referenced this pull request Aug 27, 2018
* master:
  Adjust BWC version on mapping version
  Token API supports the client_credentials grant (#33106)
  Build: forked compiler max memory matches jvmArgs (#33138)
  Introduce mapping version to index metadata (#33147)
  SQL: Enable aggregations to create a separate bucket for missing values (#32832)
  Fix grammar in contributing docs
  SECURITY: Fix Compile Error in ReservedRealmTests (#33166)
  APM server monitoring (#32515)
  Support only string `format` in date, root object & date range (#28117)
  [Rollup] Move toBuilders() methods out of rollup config objects (#32585)
  Fix forbiddenapis on java 11  (#33116)
  Apply publishing to genreate pom (#33094)
  Have circuit breaker succeed on unknown mem usage
  Do not lose default mapper on metadata updates (#33153)
  Fix a mappings update test (#33146)
  Reload Secure Settings REST specs & docs (#32990)
  Refactor CachingUsernamePassword realm (#32646)
jasontedor added a commit that referenced this pull request Aug 27, 2018
* 6.x:
  Introduce mapping version to index metadata (#33147)
  Move non duplicated actions back into xpack core (#32952)
  HLRC: Create server agnostic request and response (#32912)
  Build: forked compiler max memory matches jvmArgs (#33138)
  * Added breaking change section for GROUP BY behavior: now it considers null or empty values as a separate group/bucket. Previously, they were ignored. * This is part of backporting of #32832
  SQL: Enable aggregations to create a separate bucket for missing values (#32832)
  [TEST] version guard for reload rest-api-spec
  Fix grammar in contributing docs
  APM server monitoring (#32515)
  Support only string `format` in date, root object & date range (#28117)
  [Rollup] Move toBuilders() methods out of rollup config objects (#32585)
  Accept Gradle build scan agreement (#30645)
  Fix forbiddenapis on java 11  (#33116)
  Run forbidden api checks with runtimeJavaVersion (#32947)
  Apply publishing to genreate pom (#33094)
  Fix a mappings update test (#33146)
  Reload Secure Settings REST specs & docs (#32990)
  Refactor CachingUsernamePassword realm (#32646)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search Foundations/Mapping Index mappings, including merging and defining field types
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants