Skip to content

Conversation

@scottsom
Copy link

This changes makes it so you can index a value like "1.0" or "1.1" into whole
number field types like byte and integer. Without this change then the above
values would have resulted in an error, even with coerce set to true.

Closes #25819

@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?

Copy link
Author

Choose a reason for hiding this comment

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

This does not preserve the precision of large numbers that have a decimal part and exceed the fractional bits of double but are within min/max Long. For example, while both 4115420654264075766 and "4115420654264075766" will be indexed as 4115420654264075766, something like "4115420654264075766.1" will not be indexed as 4115420654264075766 due to String -> Double -> Long conversion.

Do we want to try to do something a bit more clever to handle this edge case?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'd just put a comment that we might not fail in all cases, but I don't think I would try to address it?

Copy link
Author

Choose a reason for hiding this comment

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

Do you mean a comment in the code or in the documentation? (i.e. a warning here https://www.elastic.co/guide/en/elasticsearch/reference/current/coerce.html)

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean in the code but just noticed there was one already

Copy link
Author

Choose a reason for hiding this comment

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

I removed this test since this change breaks it but I don't think that this test makes sense in the current state. For example, before this change that test would also break if you changed it from "2.0" to a decimal literal like 2.5. Now it is consistent (it will accept and truncate decimals, whether you quote them or not).

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense

@jpountz jpountz self-requested a review July 24, 2017 12:11
@elastic elastic deleted a comment from scottsom Jul 24, 2017
Copy link
Contributor

@jpountz jpountz Jul 24, 2017

Choose a reason for hiding this comment

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

Sorry I deleted your comment by mistake, so I am adding it back:

This only rejects coerce=false values for numbers with decimals but it won't reject strings, which seems to run contrary to how coercion is supposed to work. I did not change this behaviour. I just wanted to call it out as inconsistent with how the parse methods in AbstractXContentParser work, should this be changed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed it should be changed to be consistent, but let's do it in a separate PR? Thinking more about it, I'm wondering whether we should remove the coerce option instead. I opened #25861.

@jpountz
Copy link
Contributor

jpountz commented Jul 24, 2017

@elasticmachine Please test it.

Copy link
Contributor

@jpountz jpountz left a comment

Choose a reason for hiding this comment

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

It looks good to me, thanks for working on it.

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed it should be changed to be consistent, but let's do it in a separate PR? Thinking more about it, I'm wondering whether we should remove the coerce option instead. I opened #25861.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'd just put a comment that we might not fail in all cases, but I don't think I would try to address it?

@scottsom scottsom force-pushed the decimal_string_coerce branch from 92d11dc to a82bd08 Compare July 24, 2017 13:45
@scottsom
Copy link
Author

Added StandardCharsets.UTF_8 to the unit test to fix the build. Can you kick off that build again?

@jpountz
Copy link
Contributor

jpountz commented Jul 24, 2017

@elasticmachine Please test it.

…al part

This changes makes it so you can index a value like "1.0" or "1.1" into whole
number field types like byte and integer. Without this change then the above
values would have resulted in an error, even with coerce set to true.

Closes elastic#25819
@scottsom scottsom force-pushed the decimal_string_coerce branch from a82bd08 to 27371b0 Compare July 24, 2017 15:16
@scottsom
Copy link
Author

The build failure seems transient and/or unrelated to this change.

I've rebased onto the latest master since I see some newer changes that appear to be improving test stability.

@jpountz
Copy link
Contributor

jpountz commented Jul 25, 2017

@elasticmachine Test it please.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean in the code but just noticed there was one already

@jpountz jpountz merged commit 2f8def1 into elastic:master Jul 26, 2017
@jpountz
Copy link
Contributor

jpountz commented Jul 26, 2017

Thank you @scottsom !

jpountz pushed a commit that referenced this pull request Jul 26, 2017
…al part (#25835)

This changes makes it so you can index a value like "1.0" or "1.1" into whole
number field types like byte and integer. Without this change then the above
values would have resulted in an error, even with coerce set to true.

Closes #25819
jpountz pushed a commit that referenced this pull request Jul 26, 2017
…al part (#25835)

This changes makes it so you can index a value like "1.0" or "1.1" into whole
number field types like byte and integer. Without this change then the above
values would have resulted in an error, even with coerce set to true.

Closes #25819
@jpountz jpountz added :Search Foundations/Mapping Index mappings, including merging and defining field types v5.6.0 v6.0.0 labels Jul 26, 2017
jpountz pushed a commit that referenced this pull request Jul 26, 2017
…al part (#25835)

This changes makes it so you can index a value like "1.0" or "1.1" into whole
number field types like byte and integer. Without this change then the above
values would have resulted in an error, even with coerce set to true.

Closes #25819
@scottsom scottsom deleted the decimal_string_coerce branch July 26, 2017 13:46
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 v5.6.0 v6.0.0-beta1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants