@FunctionalInterface public interface Mapper
A Mapper
object is used in a MapReduce job (see
RDFProcessors.mapReduce(Mapper, Reducer, boolean)
) for mapping a statement to zero or
more Value keys
; statements are then grouped by key and each partition is processed in
a reduce job (see Reducer
) to produce the final output statements. Mapping is done by
method map(Statement)
. It can return zero keys to drop the statement, or a key array
including BYPASS_KEY
to force the statement to be directly emitted in output,
bypassing the reduce stage.
A common type of Mapper
is the one extracting a component or hashing a subset of
components of the input statement. This mapper is already implemented and can be instantiated
using the factory method select(String)
.
Implementations of this interface should be thread-safe, as method map()
is meant to be
invoked concurrently by different threads on different statements.
Modifier and Type | Field and Description |
---|---|
static org.openrdf.model.URI |
BYPASS_KEY
Special key used to bypass the reduce stage and directly emit the statement in output.
|
Modifier and Type | Method and Description |
---|---|
static Mapper |
bypass(Mapper mapper,
Predicate<org.openrdf.model.Statement> predicate)
Returns a bypassed version of the input mapper that skips and marks with
BYPASS_KEY quads matching the specified predicate. |
static Mapper |
concat(Mapper... mappers)
Returns a
Mapper returning a concatenation of all the keys produced by the
Mapper s supplied for the input statement. |
static Mapper |
filter(Mapper mapper,
Predicate<org.openrdf.model.Statement> predicate)
Returns a filtered version of the input mapper that only maps quads matching the supplied
predicate.
|
org.openrdf.model.Value[] |
map(org.openrdf.model.Statement statement)
Maps a statement to zero or more
Value keys. |
static Mapper |
parse(String expression)
Parses a
Mapper out of the supplied expression string. |
static Mapper |
select(String components)
Returns a
Mapper returning a single key based on one or more selected components of
the input statement. |
static final org.openrdf.model.URI BYPASS_KEY
org.openrdf.model.Value[] map(org.openrdf.model.Statement statement) throws org.openrdf.rio.RDFHandlerException
Value
keys. When used in a MapReduce job,
returning zero keys has the effect of dropping the statements, otherwise the statement will
be put in each key partition, each one being later processed in a reduce job (see
Reducer
); if one of the keys is BYPASS_KEY
, then the statement will be
(also) directly emitted in output, bypassing the reduce stage (this can be used to apply
the MapReduce paradigm to only a subset of statements). Null keys are admissible in output
(e.g., to denote the default context).statement
- the statement to map, not nullValue
keys associated to the statement, not nullorg.openrdf.rio.RDFHandlerException
- on errorstatic Mapper bypass(Mapper mapper, @Nullable Predicate<org.openrdf.model.Statement> predicate)
BYPASS_KEY
quads matching the specified predicate.mapper
- the mapper to filterpredicate
- the predicate; if null, no bypassing is performedstatic Mapper filter(Mapper mapper, @Nullable Predicate<org.openrdf.model.Statement> predicate)
mapper
- the mapper to filterpredicate
- the predicate; if null, no filtering is performedstatic Mapper concat(Mapper... mappers)
Mapper
returning a concatenation of all the keys produced by the
Mapper
s supplied for the input statement. Duplicate keys for the same statement are
merged.mappers
- the mappers whose output has to be concatenatedMapper
static Mapper select(String components)
Mapper
returning a single key based on one or more selected components of
the input statement. Parameter components
is a s
, p
, o
,
c
string specifying which components should be selected. If a single component is
selected it is returned as the key unchanged. If multiple components are selected, they are
merged and hashed to produce the returned key. In any case, exactly one key is returned for
each input statement.components
- a string of symbols s
, p
, o
, c
specifying which
components to select, not null nor emptyMapper
@Nullable static Mapper parse(@Nullable String expression)
Mapper
out of the supplied expression string. The expression can be a
language: expression
script or a component expression supported by
select(String)
.expression
- the expression to parseCopyright © 2015–2016 FBK-irst. All rights reserved.