-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #! - eclipse compilation * #40 - Sort operator with in-memory RSBK sorting * #40 - Spark SortTranslator * #40 - Flink SortTranslator * #40 - RangePartitioning * #40 - PR#99
- Loading branch information
Showing
31 changed files
with
1,208 additions
and
37 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...e/src/main/java/cz/seznam/euphoria/core/client/dataset/partitioning/RangePartitioner.java
This file contains 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,39 @@ | ||
/** | ||
* Copyright 2016-2017 Seznam.cz, a.s. | ||
* | ||
* Licensed 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 cz.seznam.euphoria.core.client.dataset.partitioning; | ||
|
||
import java.io.Serializable; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
class RangePartitioner<T extends Comparable<? super T> & Serializable> | ||
implements Partitioner<T> { | ||
|
||
private final List<T> ranges; | ||
|
||
public RangePartitioner(List<T> ranges) { | ||
this.ranges = ranges; | ||
} | ||
|
||
@Override | ||
public int getPartition(T element) { | ||
int search = Collections.binarySearch(ranges, element); | ||
if (search < 0) { | ||
return ((-search) - 1); | ||
} | ||
return search; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
.../src/main/java/cz/seznam/euphoria/core/client/dataset/partitioning/RangePartitioning.java
This file contains 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,58 @@ | ||
/** | ||
* Copyright 2016-2017 Seznam.cz, a.s. | ||
* | ||
* Licensed 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 cz.seznam.euphoria.core.client.dataset.partitioning; | ||
|
||
import cz.seznam.euphoria.shaded.guava.com.google.common.base.Preconditions; | ||
import cz.seznam.euphoria.shaded.guava.com.google.common.collect.Comparators; | ||
|
||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
/** | ||
* Partitioning based on ranges simulating total order. The ranges are expected to be provided | ||
* already sorted. | ||
* @param <T> type of ranges - must be a subtype {@link Comparable} as well as {@link Serializable} | ||
*/ | ||
public class RangePartitioning<T extends Comparable<? super T> & Serializable> | ||
implements Partitioning<T> { | ||
|
||
private final List<T> ranges; | ||
|
||
public RangePartitioning(List<T> ranges) { | ||
this.ranges = new ArrayList<>(ranges); | ||
Preconditions.checkArgument( | ||
Comparators.isInStrictOrder(ranges, Comparator.naturalOrder()), | ||
"Ranges are expected to be sorted!"); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public RangePartitioning(T ... ranges) { | ||
this(Arrays.asList(ranges)); | ||
} | ||
|
||
@Override | ||
public Partitioner<T> getPartitioner() { | ||
return new RangePartitioner<>(ranges); | ||
} | ||
|
||
@Override | ||
public int getNumPartitions() { | ||
return ranges.size() + 1; | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -203,8 +203,4 @@ public ReduceFunction<VALUE, OUT> getReducer() { | |
|
||
return DAG.of(reduceByKey, format); | ||
} | ||
|
||
|
||
|
||
|
||
} |
Oops, something went wrong.