Skip to content

Optimize the repetitive code in the NumericType.rangeQuery method of the NumberFieldMapper class#18901

Open
sunqijun1 wants to merge 5 commits intoopensearch-project:mainfrom
sunqijun1:dev/Simplifiedcode_NumberFieldMapper
Open

Optimize the repetitive code in the NumericType.rangeQuery method of the NumberFieldMapper class#18901
sunqijun1 wants to merge 5 commits intoopensearch-project:mainfrom
sunqijun1:dev/Simplifiedcode_NumberFieldMapper

Conversation

@sunqijun1
Copy link
Copy Markdown
Contributor

Description

I found that in the NumericType.rangeQuery, there is repetitive code in the calls for different types such as Long, Integer, double, etc., which affects readability. So I made optimizations to this part of the content, extracted the repetitive code, enhanced the readability of the code, and reduced code redundancy.

Related Issues

(https://github.com/opensearch-project/OpenSearch/pull/18530/files#r2158442607)

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 4, 2025

❌ Gradle check result for d80bd4c: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@sunqijun1 sunqijun1 force-pushed the dev/Simplifiedcode_NumberFieldMapper branch from d80bd4c to 03161d0 Compare August 4, 2025 04:59
@sunqijun1 sunqijun1 closed this Aug 4, 2025
@sunqijun1 sunqijun1 reopened this Aug 4, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 4, 2025

❌ Gradle check result for 03161d0: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@sunqijun1 sunqijun1 closed this Aug 4, 2025
@sunqijun1 sunqijun1 reopened this Aug 4, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 4, 2025

❌ Gradle check result for 03161d0: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@sunqijun1 sunqijun1 force-pushed the dev/Simplifiedcode_NumberFieldMapper branch from 61635e2 to 76046cd Compare August 4, 2025 07:50
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 5, 2025

❌ Gradle check result for fed0682: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@sunqijun1 sunqijun1 closed this Aug 5, 2025
@sunqijun1 sunqijun1 reopened this Aug 5, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 5, 2025

❌ Gradle check result for fed0682: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@sunqijun1 sunqijun1 closed this Aug 5, 2025
@sunqijun1 sunqijun1 reopened this Aug 5, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 5, 2025

❌ Gradle check result for fed0682: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@andrross
Copy link
Copy Markdown
Member

andrross commented Aug 6, 2025

@sunqijun1 I haven't reviewed the code change here but the backward compatibility tests that are failing are telling you this change breaks compatibility somehow. You can find the REPRODUCE WITH command in the build output that will give you a command to run the tests locally to help debug.

@sunqijun1 sunqijun1 closed this Aug 6, 2025
@sunqijun1 sunqijun1 reopened this Aug 6, 2025
@sunqijun1
Copy link
Copy Markdown
Contributor Author

@sunqijun1 I haven't reviewed the code change here but the backward compatibility tests that are failing are telling you this change breaks compatibility somehow. You can find the REPRODUCE WITH command in the build output that will give you a command to run the tests locally to help debug.

ok. I will check it

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 6, 2025

❌ Gradle check result for fed0682: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 9, 2025

❌ Gradle check result for fed0682: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Copy Markdown
Member

@sandeshkr419 sandeshkr419 left a comment

Choose a reason for hiding this comment

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

@sunqijun1 I think your backward compatibility is breaking most likely because you are removing some public methods - you can verify the same as well if this is true.

The method you introduced public <T extends Number> Query createRangeQuery is probably not super-intuitive to use (for end consumers) compared to existing methods like doubleRangeQuery for example.
Also, exposing this method as a public method puts too much control to end-users - which might be disastrous as OpenSearch might not be able to handle type incompatible changes which a consumer might specify)
Plus, any consumer of this method will now have worry about 10 different parameters to pass which is the case with method you introduced.

I do like the idea of refactored code, but here is my proposed changes:

  • Your new method createRangeQuery should be a private method/utility.
  • Existing methods based on data type like doubleRangeQuery, longRangeQuery can just do a call to the above private method - and they should still exist. They are simple, intuitive, and only expose a limited control.

We can make the new method public if in future we identify the need to expose building a customized range query where a consumer specifies their min/max/etc., but, I don't agree on exposing it publicly now for sure.

Although with the refactored changes, introducing a new data-type will become far easier.

(ignore my approval earlier - was clicking Request Changes, but clicked on the wrong button)

@opensearch-trigger-bot
Copy link
Copy Markdown
Contributor

This PR is stalled because it has been open for 30 days with no activity.

@opensearch-trigger-bot opensearch-trigger-bot bot added the stalled Issues that have stalled label Sep 15, 2025
@sunqijun1
Copy link
Copy Markdown
Contributor Author

sunqijun1 commented Sep 15, 2025 via email

@opensearch-trigger-bot opensearch-trigger-bot bot removed the stalled Issues that have stalled label Sep 16, 2025
@opensearch-trigger-bot
Copy link
Copy Markdown
Contributor

This PR is stalled because it has been open for 30 days with no activity.

@opensearch-trigger-bot opensearch-trigger-bot bot added the stalled Issues that have stalled label Oct 19, 2025
@sunqijun1
Copy link
Copy Markdown
Contributor Author

sunqijun1 commented Oct 19, 2025 via email

@opensearch-trigger-bot opensearch-trigger-bot bot removed the stalled Issues that have stalled label Nov 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants