Add range query support to DSL query executor with field-type-aware value handling#22511
Add range query support to DSL query executor with field-type-aware value handling#22511ask-kamal-nayan wants to merge 9 commits into
Conversation
PR Reviewer Guide 🔍(Review updated until commit 84652b1)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 84652b1 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 4c9c0cb
Suggestions up to commit 3369ce7
Suggestions up to commit 36c559f
Suggestions up to commit 7b4abfd
Suggestions up to commit 45bcca2
|
|
❌ Gradle check result for 9268cfc: 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? |
|
Persistent review updated to latest commit fd9f479 |
|
Persistent review updated to latest commit cd677aa |
|
❌ Gradle check result for cd677aa: 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? |
cd677aa to
8ed6f07
Compare
|
Persistent review updated to latest commit 8ed6f07 |
8ed6f07 to
a667826
Compare
|
Persistent review updated to latest commit a667826 |
|
❌ Gradle check result for a667826: 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? |
a667826 to
f909d76
Compare
|
Persistent review updated to latest commit f909d76 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #22511 +/- ##
============================================
+ Coverage 73.48% 73.50% +0.02%
- Complexity 76460 76510 +50
============================================
Files 6104 6104
Lines 346582 346582
Branches 49879 49879
============================================
+ Hits 254675 254746 +71
+ Misses 71664 71596 -68
+ Partials 20243 20240 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
f909d76 to
564b67c
Compare
|
Persistent review updated to latest commit 564b67c |
|
❌ Gradle check result for 564b67c: 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? |
564b67c to
4d8e3ae
Compare
|
Persistent review updated to latest commit 4d8e3ae |
There was a problem hiding this comment.
Instead of adding separate tests, would it be possible to utilize the extended test framework like this: https://github.com/nssuresh2007/OpenSearch/blob/main/sandbox/plugins/dsl-query-executor/src/test/resources/golden/terms_with_avg_aggregation.json to define input DSL, RelNode and the output in a single file?
|
Persistent review updated to latest commit 9b6c870 |
| */ | ||
| private RexNode createLiteral(Object value, RelDataTypeField field, ConversionContext ctx, SqlTypeName fieldTypeName) { | ||
| if (value instanceof Long && isDateType(fieldTypeName)) { | ||
| RelDataType timestampType = ctx.getRexBuilder().getTypeFactory().createSqlType(SqlTypeName.TIMESTAMP, 3); |
There was a problem hiding this comment.
date_nanos field uses TIMESTAMP(9) precision. Using 3 would lower that precision value right? Is there a way to avoid it?
There was a problem hiding this comment.
Correct — precision 3 here would silently truncate date_nanos values. So for now added check to reject nanosecond-precision date fields with a ConversionException so results stay faithful. Full support is blocked by Calcite's default RelDataTypeSystem clamping timestamp literals to precision 3.
| Object adjustedTo = to; | ||
| boolean toInclusive = rangeQuery.includeUpper(); | ||
| if (isIntegerType(fieldTypeName) && hasDecimalPart(to)) { | ||
| long truncated = toLongValue(to); |
There was a problem hiding this comment.
Can you check if this would work for scaled_float and unsigned_long as well, to confirm if those would not be truncated?
There was a problem hiding this comment.
Good catch, checked, and both would hit this truncation path: the schema maps them to plain BIGINT, so the translator can't distinguish them from long (scaled_float's scaling_factor never reaches the translator; unsigned_long values above Long.MAX_VALUE wrap under the signed narrowing). Fixing this needs schema-level type markers.
|
Persistent review updated to latest commit 45bcca2 |
|
Persistent review updated to latest commit 7b4abfd |
PR Code Analyzer ❗AI-powered 'Code-Diff-Analyzer' found issues on commit fab62d8.
The table above displays the top 10 most important findings. Pull Requests Author(s): Please update your Pull Request according to the report above. Repository Maintainer(s): You can Thanks. |
|
Persistent review updated to latest commit 36c559f |
|
❌ Gradle check result for 36c559f: null 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? |
36c559f to
3369ce7
Compare
|
Persistent review updated to latest commit 3369ce7 |
|
❌ Gradle check result for 3369ce7: 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? |
Signed-off-by: Kamal Nayan <askkamal@amazon.com>
Signed-off-by: Kamal Nayan <askkamal@amazon.com>
…tests Signed-off-by: Kamal Nayan <askkamal@amazon.com>
Signed-off-by: Kamal Nayan <askkamal@amazon.com>
Signed-off-by: Kamal Nayan <askkamal@amazon.com>
…nd handling Signed-off-by: Kamal Nayan <askkamal@amazon.com>
Signed-off-by: Kamal Nayan <askkamal@amazon.com>
Signed-off-by: Kamal Nayan <askkamal@amazon.com>
3369ce7 to
4c9c0cb
Compare
|
Persistent review updated to latest commit 4c9c0cb |
Signed-off-by: Kamal Nayan <askkamal@amazon.com>
4c9c0cb to
84652b1
Compare
|
Persistent review updated to latest commit 84652b1 |
Description
Adds
RangeQueryTranslatorto thedsl-query-executorsandbox plugin, converting DSLrangequeries into Calcite comparison expressions (>=,>,<=,<) for execution on the multi-engine analytics path.This PR supersedes #21331: it carries the original implementation commits (authorship preserved), rebased onto current main, and adds behavioral fixes aligning the translator with legacy
_searchsemantics, verified against the corresponding server code paths.Supported after this PR
{"range": {"price": {"gte": 100, "lte": 500}}}, numeric strings coerced ("gte": "100"), doubles, decimal bounds on integer fields ("gt": 10.5matches values from 11){"range": {"brand": {"gte": "apple", "lte": "dell"}}}format(e.g.dd/MM/yyyy),epoch_millis, date math (now-7d,2022-06-15||/M), rounding operators,time_zonerelationINTERSECTS/CONTAINS/WITHINaccepted and ignored on scalar fields (matchingSimpleMappedFieldType);DISJOINTrejectedIS NOT NULL), matchingRangeQueryBuilder.doToQueryDISJOINTrewriteUnsupported parameters fail fast with
ConversionException(boost,_name) rather than silently changing result semantics.Fixes on top of the original implementation
DateMathParser. Previously every string was date-parsed, breaking numeric-string and keyword ranges.roundUp=!includeLower, upper withroundUp=includeUpper, matchingDateFieldMapper.dateRangeQuery. Previouslygt/ltwith day-granularity strings rounded the wrong direction and returned wrong results (e.g."gt": "2022-01-01"included most of Jan 1). Also removes a false-positive where/date-format separators (e.g."31/12/2022"withdd/MM/yyyy) suppressed end-of-day rounding.epoch_millisis absolute —time_zoneno longer shifts epoch values (was silently off by the zone offset when combined).TIMESTAMP(3)literals are produced only for date-typed fields. Previously anyLongbound became a timestamp, even on numeric fields.NumberFieldMappertruncate-and-adjust semantics ("gt": 10.5→ matches from 11;"lt": -10.5→ matches through -11), applied identically to string-origin decimals, with overflow guards at each type's MIN/MAX returning match-none instead of wrapping around.IS_NOT_NULL, matching the legacy exists-query rewrite (previously an error).relationparity on scalar fields —CONTAINS/WITHINare accepted and ignored exactly asSimpleMappedFieldType.rangeQuerydoes; onlyDISJOINTis rejected. Previously all non-INTERSECTSvalues were rejected, breaking queries that work on the legacy path._name(queryName) rejected — consistent with the other translators' unsupported-parameter handling; previously silently ignored (matched_queriescannot be populated on this path).Testing
RangeQueryTranslatorTests: 62 tests — original shape assertions plus value-level assertions (exact epoch millis for format/timezone/rounding paths, literal types, coercion, overflow boundaries), written test-first: 18 tests documented the bugs above before the fixesdsl-query-executormodule: 202 tests, 0 failures./gradlew -Dsandbox.enabled=true :sandbox:plugins:dsl-query-executor:testDslRangeQueryITmigrated to current test-framework APIs (indexDocremoval,TotalHits.value()) and annotated@AwaitsFixwith the same condition as the plugin's other integration tests (analytics E2E pipeline not yet wired); it compiles and will activate with themNotes for reviewers
DECIMAL(RexLiteralrejectsINTEGERin strict mode); tests assert value correctness + not-TIMESTAMPrather than a specific numericSqlTypeNameboost(no scoring on this path yet),_name(no per-hitmatched_queriesside-channel), ranges over analyzedtextfields (legacy compares analyzed terms; this path compares stored values),allowExpensiveQueriesgate (cluster-setting concern, different execution model)now-based date-math tests;TIME-typed fields currently receive date treatment viaisDateType(no such fields exist on this path in practice)Related Issues
Relates to #20914
Supersedes #21331
Check List
--signoffRelated Issues
Resolves #[Issue number to be closed when this PR is merged]
Check List
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.