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

Fixed conversion of date field values when using multiple date formats #6266

Merged
merged 1 commit into from May 22, 2014
Merged

Fixed conversion of date field values when using multiple date formats #6266

merged 1 commit into from May 22, 2014

Conversation

colings86
Copy link
Contributor

When multiple date formats are specified using the || syntax in the field mappings the date_histogram aggregation breaks. This is because we are getting a parser rather than a printer from the date formatter for the object we use to convert the DateTime values back into Strings. Simple fix to get the printer form the date format and test to back it up

Closes #6239

@@ -142,7 +142,7 @@ public static FormatDateTimeFormatter forPattern(String input, Locale locale) {
} else {
DateTimeFormatter dateTimeFormatter = null;
for (int i = 0; i < formats.length; i++) {
DateTimeFormatter currentFormatter = forPattern(formats[i], locale).parser();
Copy link
Contributor

Choose a reason for hiding this comment

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

why doesn't break this in the single format case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because this is code is in an if statement which checks for "||" in the format. The single format cases use a standard formatter which work for both printing and parsing. This code creates a formatter which uses all of the formats to parse a date but only the first format for printing a date

Copy link
Contributor

Choose a reason for hiding this comment

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

@colings86 Is it correct to use the printer to define how dates should be parsed, I would rather expect it to be the role of parsers? I think we need in this iteration to collect parsers for all inputs formats as well as the printer of the first one? (while master currently uses the first parser as a printer, and your patch collect all printers to know how to parse)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jpountz Yes you a probably right, I'll change it to store the parsers for all format and just the first printer

@colings86
Copy link
Contributor Author

Closes #6239

@jpountz
Copy link
Contributor

jpountz commented May 22, 2014

LGTM

@s1monw
Copy link
Contributor

s1monw commented May 22, 2014

+1 to push

@s1monw s1monw removed the review label May 22, 2014
…le date formats

When multiple date formats are specified using the || syntax in the field mappings the date_histogram aggregation breaks.  This is because we are getting a parser rather than a printer from the date formatter for the object we use to convert the DateTime values back into Strings.  Simple fix to get the printer from the date format and test to back it up

Closes #6239
@colings86 colings86 merged commit cabd234 into elastic:master May 22, 2014
@colings86 colings86 deleted the fix/6239 branch May 22, 2014 09:31
@colings86 colings86 self-assigned this Aug 21, 2014
@clintongormley clintongormley changed the title Aggregations: Fixed conversion of date field values when using multiple date formats Fixed conversion of date field values when using multiple date formats Jun 7, 2015
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.

Aggregations: date_histogram aggregation breaks on date fields with multiple formats
4 participants