Skip to content

Fix value parsing bug.#4095

Merged
LantaoJin merged 8 commits intoopensearch-project:mainfrom
ishaoxy:fix-value-parsing
Aug 26, 2025
Merged

Fix value parsing bug.#4095
LantaoJin merged 8 commits intoopensearch-project:mainfrom
ishaoxy:fix-value-parsing

Conversation

@ishaoxy
Copy link
Contributor

@ishaoxy ishaoxy commented Aug 21, 2025

Description

Problem:
Certain fields in JSON content were not correctly parsed when numeric or boolean values were represented as strings.

What I did:
Added parseLongValue, parseDoubleValue, and parseBooleanValue methods to safely handle:

  • Numeric strings (e.g., "123" → 123)

  • Boolean strings ("true" → true; "false" → false)

Special Handling:
Empty string ("") is parsed as:

  • 0 for numeric types (long, int, double, etc.)

  • false for boolean type

Related Issues

Resolves #3001

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • New PPL command checklist all confirmed.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff or -s.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>
Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>
@yuancu yuancu added the bug Something isn't working label Aug 21, 2025
if (node.isNumber()) {
return node.doubleValue();
} else if (node.isTextual()) {
return Double.parseDouble(node.textValue());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shall we throw a legible error if the text cannot be parsed as double?

If it already does so, please add such a test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The scheme restricts the written value to be able to be parsed into the specific type, otherwise an error will be reported. Therefore, this part of the code will definitely receive a field that can be parsed into a double type.

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>
Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>
Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>
Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>
Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>
Comment on lines +172 to +174
} else if (node.isTextual()) {
if (node.textValue().isEmpty()) {
return 0L;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you also include such cases in the tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, added.

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>
Copy link
Collaborator

@yuancu yuancu left a comment

Choose a reason for hiding this comment

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

LGTM

@LantaoJin LantaoJin merged commit fff3e3a into opensearch-project:main Aug 26, 2025
23 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Aug 26, 2025
* fix parsing-value bug

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

* add dataType IT

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

* modify it

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

* modify it

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

* fix IT error

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

* fix IT error

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

* fix empty string->number 0

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

* add empty string test

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

---------

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>
(cherry picked from commit fff3e3a)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
qianheng-aws pushed a commit that referenced this pull request Aug 26, 2025
* fix parsing-value bug



* add dataType IT



* modify it



* modify it



* fix IT error



* fix IT error



* fix empty string->number 0



* add empty string test



---------


(cherry picked from commit fff3e3a)

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Aug 29, 2025
* fix parsing-value bug

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

* add dataType IT

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

* modify it

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

* modify it

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

* fix IT error

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

* fix IT error

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

* fix empty string->number 0

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

* add empty string test

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>

---------

Signed-off-by: Xinyu Hao <haoxinyu@amazon.com>
(cherry picked from commit fff3e3a)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Swiddis pushed a commit that referenced this pull request Oct 30, 2025
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Lantao Jin <ltjin@amazon.com>
Fix value parsing bug. (#4095)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Enhance OS value parsing

3 participants