-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow queries with filters to use fast-lane reducers
- Loading branch information
Showing
11 changed files
with
151 additions
and
113 deletions.
There are no files selected for viewing
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
28 changes: 28 additions & 0 deletions
28
oshdb-api/src/main/java/org/heigit/ohsome/oshdb/api/mapreducer/FilterFunction.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,28 @@ | ||
package org.heigit.ohsome.oshdb.api.mapreducer; | ||
|
||
import java.util.Collections; | ||
import org.heigit.ohsome.oshdb.util.function.SerializablePredicate; | ||
|
||
/** | ||
* A special map function that represents a filter. | ||
* | ||
* <p>Note that this class is using raw types on purpose because MapReducer's "map functions" | ||
* are designed to input and output arbitrary data types. The necessary type checks are performed | ||
* at at runtime in the respective setters.</p> | ||
*/ | ||
@SuppressWarnings({"rawtypes", "unchecked"}) // see javadoc above | ||
class FilterFunction extends MapFunction { | ||
private final SerializablePredicate filter; | ||
|
||
FilterFunction(SerializablePredicate filter) { | ||
super((x, ignored) -> filter.test(x) | ||
? Collections.singletonList(x) | ||
: Collections.emptyList(), | ||
true); | ||
this.filter = filter; | ||
} | ||
|
||
public boolean test(Object root) { | ||
return this.filter.test(root); | ||
} | ||
} |
Oops, something went wrong.