Repository navigation
[Feature][PPL] Publish partial rows for asynchronous Calcite queries - #5920
Conversation
PR Reviewer Guide 🔍(Review updated until commit 3fa6a0d)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 3fa6a0d Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 233f737
Suggestions up to commit 9db3b41
Suggestions up to commit da78e9d
Suggestions up to commit 81b5c13
Suggestions up to commit 146638b
|
|
Persistent review updated to latest commit 1122f45 |
|
Persistent review updated to latest commit 927a191 |
|
Persistent review updated to latest commit 146638b |
|
Persistent review updated to latest commit 81b5c13 |
|
Persistent review updated to latest commit da78e9d |
Codecov Report❌ Patch coverage is ❌ Your project check has failed because the head coverage (89.15%) is below the target coverage (99.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #5920 +/- ##
=============================================
+ Coverage 75.59% 89.15% +13.55%
- Complexity 10497 12218 +1721
=============================================
Files 971 979 +8
Lines 41474 41946 +472
Branches 4742 4824 +82
=============================================
+ Hits 31353 37397 +6044
+ Misses 8777 3077 -5700
- Partials 1344 1472 +128
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Persistent review updated to latest commit 9db3b41 |
9db3b41 to
233f737
Compare
|
Persistent review updated to latest commit 233f737 |
| } | ||
| listener.onResponse(response); | ||
| } catch (SQLException e) { | ||
| discardPartialRows(); |
There was a problem hiding this comment.
Which test fails if both discardPartialRows() calls (:346, :363) are removed? I removed them: :opensearch:test (1884 tests) and AsyncPPLPartialRowsIT (7/7) still pass. failureAfterRowsReturnsNoRows can't catch it, because a FAILED job never carries current (QueryJobStatus.java:88).
The discard is observable with plugins.calcite.fallback.allowed=true. I made a scan fail after about 3,000 rows had been published, by lowering plugins.query.memory_limit. With the discard, RUNNING polls show 0 rows during the ~3 s v2 fallback. Without it, they show 3,999 stale Calcite rows until FAILED.
Could we pin this with an engine unit test: a ResultSet that throws after N rows, then assert the tracker's snapshot is empty?
There was a problem hiding this comment.
Good catch, thanks. I moved the discard into buildResultSet, where the rows are published, and added build_result_set_discards_partial_rows_when_the_result_set_fails: the ResultSet throws after 3 rows, and the test asserts the tracker's snapshot is empty. It fails with the discard removed.
Async submit-timeout and GET responses now carry the rows the query has produced so far. The root ResultSet only emits final rows in final order, so buildResultSet publishes each converted row as it is read and every response is a complete view whose rows are a prefix of the final result; composite pages become visible the same way. A step that must see all rows first returns rows only after reading its input, timewrap publishes none, and rows are dropped if execution fails or falls back to the legacy engine. QueryRunner exposes currentResult() and close(); QueryJobStatus and Running carry the rows only while RUNNING. Submit and GET RUNNING bodies are rendered by the same formatter, and a query job's GET body uses PPL type names and warnings, matching the sync response. Resolves opensearch-project#5798 Signed-off-by: Kai Huang <[email protected]> Signed-off-by: verify <verify@local>
233f737 to
3fa6a0d
Compare
|
Persistent review updated to latest commit 3fa6a0d |
Description
Async PPL responses now return the rows a query has produced so far: the submit response when
wait_for_completion_timeoutexpires, andGET /_plugins/_async_query/{id}while the job isRUNNING.{"id": "<opaque-id>", "status": "RUNNING", "progress": {"fraction_done": 0.42}, "schema": [{"name": "n", "type": "int"}], "datarows": [[0], [1], [2]], "total": 3, "size": 3}How it works
flowchart LR subgraph exec["Query thread"] RS["Calcite ResultSet"] -->|each row| BRS["buildResultSet"] BRS -->|"add(row), warnings"| PR["PartialRows<br/>(on the query's tracker)"] BRS -.->|"failure / fallback: discard()"| PR end C["Client"] -->|"submit (wait expires)<br/>or GET while RUNNING"| QJ["QueryJob"] QJ -->|"currentResult(), then progress()"| R["PPLQueryRunner"] R -->|"snapshot()"| PR QJ --> F["AsyncQueryResultResponseFormatter<br/>(same for submit and GET)"] F -->|"progress + schema + datarows so far"| CThe rows a Calcite root
ResultSetemits are already final rows in final order; they are never retracted. So no plan classification is needed:OpenSearchExecutionEngine.buildResultSetappends each converted row to aPartialRowsbuffer held by the async query's tracker (the same object that holds progress since [Feature][PPL] Report progress for asynchronous Calcite queries #5910). Sync queries have no tracker and are unchanged.buildColumns, extracted). It is published only after the first row, so its schema equals the final schema. The buffer stops at the query size limit, as the final result does.stats ... by) pages reach the root as they are fetched, so they become visible without a composite-specific adapter.eventstats,statswithoutby, asortthat is not pushed down) returns rows only after it has read its whole input; a pushed-downsortstreams like a scan.timewrapreshapes all rows at the end, so it publishes none while running.Every response is a complete replacement view; there is no delta protocol.
Lifecycle seam (
core/job)QueryRunner.currentResult()(default empty), sampled outside the job monitor likeprogress().QueryJobStatus.current()andQueryResult.Running.current()carry the snapshot, present only whileRUNNING.QueryRunner.close()(default no-op, idempotent), called once the job is terminal. The PPL runner drops its progress and rows suppliers and its cancellation hook (which holds the query task), so a job retained forkeep_aliveno longer holds the buffer.Responses
RUNNINGbodies are now rendered by the same formatter (AsyncQueryResultResponseFormatter, with anidfield set only on submit), so they cannot drift. Query-job responses are built throughAsyncQueryResult.forQueryJoband marked explicitly, rather than inferred from other fields.PARTIAL_RESULTwhen a shard did not answer), as the final response does.CompletableFuturetimer thread, so theRUNNINGsubmit body, which can now hold thousands of rows, is formatted on the generic pool.Behavior changes to flag
bigint, notlong;int, notinteger.AsyncPPLQueryLifecycleITandAsyncPPLMultiNodeRoutingITdocumented the old difference on purpose and are updated.SUCCEEDEDbodies now includewarningswhen present.warnings.RUNNINGnow includesschema,datarows,total, andsize(empty when there are no rows yet). The submitRUNNINGbody gainssize.Observed
AsyncPPLPartialRowsIT,source=<fixture> | fields n(10,000 rows, 1,000 PIT pages), rows perRUNNINGresponse polled every 20 ms:0, 0, 789, 2057, 3179, 4699, 6329, 7939, 9769, thenSUCCEEDEDwith all 10,000, equal to sync.Tests
AsyncPPLPartialRowsIT(new): scan and row-localeval/wherereturn rows early; composite with 100-bucket pages returns rows before the last page; blockingeventstatsreturns rows only after reading all input; size limit 500;timewrap; failure after rows were visibleCalciteCrossClusterAsyncProgressIT, with a new remote partial-rows caseAsyncPPLProgressITAsyncPPLMultiNodeRoutingIT(asyncMultiNodeIT)AsyncPPLSecurityITAsyncPPLQueryLifecycleITcheckforcore,opensearch,ppl,async-query-core,async-query, and the pluginEach
AsyncPPLPartialRowsITcase asserts that the final schema and rows equal sync, and that everyRUNNINGresponse is a complete view whose rows are a prefix of the final rows, never shrink, and carry the final schema. New unit tests cover the job seam,PartialRows(including a concurrent writer/reader prefix check), the runner, routing, and the formatter.AsyncPPLQueryLifecycleIT: oneparity_*case fails per run, a different one each time. The same failure reproduces on a cleanupstream/main, so it is pre-existing and not caused by this PR. Withwait_for_completion_timeout=0, a fast analysis error now completes before the wait starts and is returned inline, instead of theRUNNINGid the test expects. This likely changed with #5915; I'll follow up separately.Related Issues
Resolves #5798
Part of #5765
Check List
--signoffor-s.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.