Repository navigation
feat(operator): add Stable Incremental Merge Sort (Scala) - #3774
Conversation
…debounced valueChanges Previously the Settings form updated only the FormControl; nothing invoked setWorkflowDataTransferBatchSize(...) unless a manual handler fired, so the new value often wasn’t propagated/persisted. This change wires the control to a debounced valueChanges pipeline (Number-coerced, validated, distinctUntilChanged) that calls confirmUpdateDataTransferBatchSize(...). - Add debounceTime(300), map/filter/distinctUntilChanged, untilDestroyed(this) - Keep existing persistence policy (persist only when logged-in) Behavior: - Typing a valid number updates workflow settings and triggers persistence (once after 300ms of inactivity). - Reload shows the saved value.
…ize via debounced valueChanges" This reverts commit 7e7f5e3.
…debounced valueChanges Previously the Settings form updated only the FormControl; nothing invoked setWorkflowDataTransferBatchSize(...) unless a manual handler fired, so the new value often wasn’t propagated/persisted. This change wires the control to a debounced valueChanges pipeline (Number-coerced, validated, distinctUntilChanged) that calls confirmUpdateDataTransferBatchSize(...). - Add debounceTime(300), map/filter/distinctUntilChanged, untilDestroyed(this) - Keep existing persistence policy (persist only when logged-in) Behavior: - Typing a valid number updates workflow settings and triggers persistence (once after 300ms of inactivity). - Reload shows the saved value.
Signed-off-by: carloea2 <[email protected]>
|
@mengw15 Can you review it? I also assigned @Yicong-Huang as a reviewer. |
There was a problem hiding this comment.
Thanks for the PR. I haven't gone through all details yet, here are some comments:
- We should discuss whether we want to include Limit and Offset into Sort operator. For SQL, having LIMIT and OFFSET can be good optimization for a plan with sort. But we are dealing on the operator level, and users of operators may get confused by multiple limit and offsets (we have limit operator already). Think of standard Python sort, pandas sort, etc, they just sort the input data without other parameters. This is a design decision, and I am voting for "simplicity + modularity" over "performance".
- Your executor code is too defensive, meaning that you are checking everything to be null, invalid, or unsupported values. However, during runtime, having those checks have overheads. For operators, we have compilation phase to help validate operator parameters (e.g., a limit has to be a non-negative int). For data, we have schema validation before network layer to make sure the incoming data is exactly as described by the schema. Thus my suggestions is:
A. move all operator parameter validations to compilation phase (see comments for details), so that they are conducted only once during compilation, not repeatedly for every tuple, and
B. remove all checks on incoming data, as they are not necessary. - I did not go to details of your merge sort implementation. I see that you are implementing from scratch using recursion. Two suggestions:
A. If during pipelining, you are only accumulating data, and conduct sort only when all data finished (inonFinish), then I suggest you use a standard java/scala sort implementation, instead of implementing your own. The standard version would be much more stable.
B. If you want to use your own implementation, I suggest you explore sort it incrementally. This might be the only reason why we need to implement it by ourselves instead of using the standard sort. Your current implementation is NOT incremental. It only gets sorted when all the data are received. For merge sort, you should be able to incrementally keep multiple sorted buckets while data is coming in, and only conduct merge phase when all data are received. Incremental version can make user experience better.
|
@carloea2 Other PR related comments:
|
|
Next actions I will do:
Thank you |
|
New changes are ready. Thank you. I could not change the tags of the PR (just as an extra note). |
|
Thanks. @mengw15 Do you want to review it before @Yicong-Huang's pass? |
sure |
This commit removes the option of placing nulls first or last, also follows other operators conventions in not placing "." in their descriptions. Finally reuses Sort Criteria Unit to match previous python sort implementation
Add apache header
|
New changes are ready for review @mengw15, I still want to confirm whether the current reuse of SortCriteriaUnit matches your expectation. Thank you. |
Moved the new sort to shared folder with previous sort
|
I just made the commit to apply the folder structure changes. Thanks, |
|
I also prepared a workflow to test the new sort, |
There was a problem hiding this comment.
This version is much better! Some more comments:
- use meaningful variable names, method names. Avoid using single-character names. Variable names such as
va,vb,tpeand method names such asexecuteis not clear at all, could be very confusing. - add docs for each method, especially you have many non-trivial methods such as
pushRun,mergeRuns, please well document about their scope, limitations, expected output and possible issues. Add unit tests for those non-trivial methods to verify them. - good to have: for some general methods, such as compare, tupleOf, schemaOf, consider add to more general places, so that these code can be reused. Think about what should be encapsulated in each module. For instance, the method
compareNonNulluses only AttribtueType, then it might be better to put this method insideAttribtueType.
|
Hello good afternoon, I will take a look into your comments, thank you very much. |
|
I do not know what what be the exact use case to sort a binary field. But I just do not want user to select a binary field to sort and get an exception. I think we can support it, and let user decide whether sort binary is useful or not. If we do not support it, then we need to add a frontend logic to disallow user selecting field in binary type.
…On Oct 14, 2025 at 3:02 PM -0700, carloea2 ***@***.***>, wrote:
@carloea2 commented on this pull request.
In common/workflow-operator/src/main/scala/org/apache/amber/operator/sort/StableMergeSortOpExec.scala:
> + throw new IllegalStateException(s"Unsupported attribute type $other in StableMergeSort")
+ }
Yes, but I wonder if it is binary, then greater or lower will greatly depend on the user context, no?
If it is just by value, why not using another corresponding data type such as long?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@chenlica could you share your thoughts? I’m inclined to show a warning when a user tries to sort a binary field as @Yicong-Huang mentioned, maybe something like: “Sorting on binary fields isn’t supported.” |
|
I suggest we disallow sort on a binary attribute. The frontend should disallow it. |
In this case, I suggest we merge this PR to unblock the existing use case, and @carloea2 can create an issue to track the implementation of frontend disallow logic. What do you think? |
|
I agree. Let's finish this PR, and deal with the problem of "not sorting on binary attributes" as a separate issue. |
|
Can we move the extraction of general utilities for reuse as another PR as well? I have identified some places where code can be reused but I think this PR is already large enough. For this PR I am planning on adding docs, improving variables and methods naming and add unit tests for several non trivial methods. is this plan OK? |
sounds good. please open issues for future tasks. |
Added doc strings, unit testing of internal methods and renaming of vars and methods
|
Added the docs, renaming of variables/methods and unit tests to check incremental behavior and internal methods of Exec. This week I will create issues about the extraction of general utilities and linking those to the pending conversations here to mark them as resolved. Thank you. |
Yicong-Huang
left a comment
There was a problem hiding this comment.
LGTM.
Please change PR description to use our new template, and fix minor comments and code format before merging.
|
@carloea2 Please take care of these comments quickly so that we can finish this PR. |
|
Ready to merge |
**feat(operator): add Stable Merge Sort (Scala) with multi-key ordering, nulls handling, and offset/limit (Closes apache#3763)** --- ## Summary Adds a new **Stable Merge Sort** operator in Scala. Performs stable per-partition sort with multiple keys and post-sort offset/limit. **Closes apache#3763.** ### Highlights * New files: * `StableMergeSortOpDesc.scala` – logical desc + JSON schema. * `StableMergeSortOpExec.scala` – stable merge sort on buffered tuples. * `StableMergeSortOpExecSpec.scala` – tests. * Features: * Per-key options: `order: asc|desc`, `nulls: first|last`, `caseInsensitive` (STRING only). * Supported types: STRING, INTEGER, LONG, DOUBLE, BOOLEAN, TIMESTAMP. * Stable ordering preserved for equal keys. * Offset/limit applied **after** sorting. ### Tests * Asc/desc integers (stability). * Case-sensitive vs case-insensitive strings. * Nulls first/last. * Multi-key across mixed types. * Offset + limit. * Missing attribute / unsupported type errors. * Large input sanity. * Buffers until `onFinish`. ### Example config ```json { "keys": [ { "attribute": "dept", "order": "asc", "nulls": "last" }, { "attribute": "score", "order": "desc", "nulls": "last" }, { "attribute": "name", "order": "asc", "nulls": "last", "caseInsensitive": true } ], "offset": 0, "limit": null } ``` --- --------- Signed-off-by: carloea2 <[email protected]>
**feat(operator): add Stable Merge Sort (Scala) with multi-key ordering, nulls handling, and offset/limit (Closes apache#3763)** --- ## Summary Adds a new **Stable Merge Sort** operator in Scala. Performs stable per-partition sort with multiple keys and post-sort offset/limit. **Closes apache#3763.** ### Highlights * New files: * `StableMergeSortOpDesc.scala` – logical desc + JSON schema. * `StableMergeSortOpExec.scala` – stable merge sort on buffered tuples. * `StableMergeSortOpExecSpec.scala` – tests. * Features: * Per-key options: `order: asc|desc`, `nulls: first|last`, `caseInsensitive` (STRING only). * Supported types: STRING, INTEGER, LONG, DOUBLE, BOOLEAN, TIMESTAMP. * Stable ordering preserved for equal keys. * Offset/limit applied **after** sorting. ### Tests * Asc/desc integers (stability). * Case-sensitive vs case-insensitive strings. * Nulls first/last. * Multi-key across mixed types. * Offset + limit. * Missing attribute / unsupported type errors. * Large input sanity. * Buffers until `onFinish`. ### Example config ```json { "keys": [ { "attribute": "dept", "order": "asc", "nulls": "last" }, { "attribute": "score", "order": "desc", "nulls": "last" }, { "attribute": "name", "order": "asc", "nulls": "last", "caseInsensitive": true } ], "offset": 0, "limit": null } ``` --- --------- Signed-off-by: carloea2 <[email protected]>
feat(operator): add Stable Merge Sort (Scala) with multi-key ordering, nulls handling, and offset/limit (Closes #3763)
Summary
Adds a new Stable Merge Sort operator in Scala. Performs stable per-partition sort with multiple keys and post-sort offset/limit.
Closes #3763.
Highlights
New files:
StableMergeSortOpDesc.scala– logical desc + JSON schema.StableMergeSortOpExec.scala– stable merge sort on buffered tuples.StableMergeSortOpExecSpec.scala– tests.Features:
order: asc|desc,nulls: first|last,caseInsensitive(STRING only).Tests
onFinish.Example config
{ "keys": [ { "attribute": "dept", "order": "asc", "nulls": "last" }, { "attribute": "score", "order": "desc", "nulls": "last" }, { "attribute": "name", "order": "asc", "nulls": "last", "caseInsensitive": true } ], "offset": 0, "limit": null }