-
Notifications
You must be signed in to change notification settings - Fork 140
feat: Optimizing Sorting Performance via Radix Sort Algorithm #589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e891f48
Optimizing Sorting Performance via Radix Sort Algorithm
ftljk 6499b64
Fix style
ftljk 3547a1a
Optimizing the efficiency of the radix sort algorithm
ftljk 2fa1ca0
Max String Precision
ftljk 5fb83d6
add tests
ftljk 9e8d9fe
modify pom
ftljk 0888bf8
fix style
ftljk d3eb972
fix style2
ftljk 4a8e18d
fix style2
ftljk 7405473
refractor equals for BinaryStringType
ftljk ad182ee
concurrency-safe sorting
ftljk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...-runtime/src/main/java/org/apache/geaflow/dsl/runtime/function/table/OrderByHeapSort.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.geaflow.dsl.runtime.function.table; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.PriorityQueue; | ||
| import org.apache.geaflow.dsl.common.data.Row; | ||
| import org.apache.geaflow.dsl.common.function.FunctionContext; | ||
| import org.apache.geaflow.dsl.runtime.function.table.order.SortInfo; | ||
| import org.apache.geaflow.dsl.runtime.function.table.order.TopNRowComparator; | ||
|
|
||
| public class OrderByHeapSort implements OrderByFunction { | ||
|
|
||
| private final SortInfo sortInfo; | ||
|
|
||
| private PriorityQueue<Row> topNQueue; | ||
|
|
||
| private TopNRowComparator<Row> topNRowComparator; | ||
|
|
||
| public OrderByHeapSort(SortInfo sortInfo) { | ||
| this.sortInfo = sortInfo; | ||
| } | ||
|
|
||
| @Override | ||
| public void open(FunctionContext context) { | ||
| this.topNRowComparator = new TopNRowComparator<>(sortInfo); | ||
| this.topNQueue = new PriorityQueue<>( | ||
| sortInfo.fetch, topNRowComparator.getNegativeComparator()); | ||
| } | ||
|
|
||
| @Override | ||
| public void process(Row row) { | ||
| if (topNQueue.size() == sortInfo.fetch) { | ||
| if (sortInfo.orderByFields.isEmpty()) { | ||
| return; | ||
| } | ||
| Row top = topNQueue.peek(); | ||
| if (topNQueue.comparator().compare(top, row) < 0) { | ||
| topNQueue.remove(); | ||
| topNQueue.add(row); | ||
| } | ||
| } else { | ||
| topNQueue.add(row); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Iterable<Row> finish() { | ||
| List<Row> results = new ArrayList<>(); | ||
| while (!topNQueue.isEmpty()) { | ||
| results.add(topNQueue.remove()); | ||
| } | ||
| Collections.reverse(results); | ||
| topNQueue.clear(); | ||
| return results; | ||
| } | ||
| } |
59 changes: 59 additions & 0 deletions
59
...runtime/src/main/java/org/apache/geaflow/dsl/runtime/function/table/OrderByRadixSort.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.geaflow.dsl.runtime.function.table; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import org.apache.geaflow.dsl.common.data.Row; | ||
| import org.apache.geaflow.dsl.common.function.FunctionContext; | ||
| import org.apache.geaflow.dsl.runtime.function.table.order.MultiFieldRadixSort; | ||
| import org.apache.geaflow.dsl.runtime.function.table.order.SortInfo; | ||
|
|
||
| public class OrderByRadixSort implements OrderByFunction { | ||
|
|
||
| private final SortInfo sortInfo; | ||
|
|
||
| private List<Row> allRows; | ||
|
|
||
| public OrderByRadixSort(SortInfo sortInfo) { | ||
| this.sortInfo = sortInfo; | ||
| } | ||
|
|
||
| @Override | ||
| public void open(FunctionContext context) { | ||
| this.allRows = new ArrayList<>(); | ||
| } | ||
|
|
||
| @Override | ||
| public void process(Row row) { | ||
| if (sortInfo.fetch == 0) { | ||
| return; | ||
| } | ||
| allRows.add(row); | ||
| } | ||
|
|
||
| @Override | ||
| public Iterable<Row> finish() { | ||
| List<Row> sortedRows = new ArrayList<>(allRows); | ||
| MultiFieldRadixSort.multiFieldRadixSort(sortedRows, sortInfo); | ||
| allRows.clear(); | ||
| return sortedRows; | ||
| } | ||
| } |
62 changes: 62 additions & 0 deletions
62
...l-runtime/src/main/java/org/apache/geaflow/dsl/runtime/function/table/OrderByTimSort.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.geaflow.dsl.runtime.function.table; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import org.apache.geaflow.dsl.common.data.Row; | ||
| import org.apache.geaflow.dsl.common.function.FunctionContext; | ||
| import org.apache.geaflow.dsl.runtime.function.table.order.SortInfo; | ||
| import org.apache.geaflow.dsl.runtime.function.table.order.TopNRowComparator; | ||
|
|
||
| public class OrderByTimSort implements OrderByFunction { | ||
|
|
||
| private final SortInfo sortInfo; | ||
|
|
||
| private List<Row> allRows; | ||
|
|
||
| private TopNRowComparator<Row> topNRowComparator; | ||
|
|
||
| public OrderByTimSort(SortInfo sortInfo) { | ||
| this.sortInfo = sortInfo; | ||
| } | ||
|
|
||
| @Override | ||
| public void open(FunctionContext context) { | ||
| this.topNRowComparator = new TopNRowComparator<>(sortInfo); | ||
| this.allRows = new ArrayList<>(); | ||
| } | ||
|
|
||
| @Override | ||
| public void process(Row row) { | ||
| if (sortInfo.fetch == 0) { | ||
| return; | ||
| } | ||
| allRows.add(row); | ||
| } | ||
|
|
||
| @Override | ||
| public Iterable<Row> finish() { | ||
| List<Row> sortedRows = new ArrayList<>(allRows); | ||
| sortedRows.sort(topNRowComparator); | ||
| allRows.clear(); | ||
| return sortedRows; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.