Class MapReducerJdbcSinglethread<X>

  • All Implemented Interfaces:
    Serializable, Mappable<X>

    public class MapReducerJdbcSinglethread<X>
    extends MapReducer<X>
    A simple implementation of the OSHDB API using a JDBC database as backend, where calculations are run sequentially.
    See Also:
    Serialized Form
    • Field Detail

      • executionStartTimeMillis

        protected long executionStartTimeMillis
        Stores the start time of reduce/stream operation as returned by System.currentTimeMillis(). Used to determine query timeouts.
    • Method Detail

      • isCancelable

        public boolean isCancelable()
        Description copied from class: MapReducer
        Returns if the current backend can be canceled (e.g. in a query timeout).
        Overrides:
        isCancelable in class MapReducer<X>
      • mapReduceCellsOSMContribution

        protected <R,​S> S mapReduceCellsOSMContribution​(SerializableFunction<OSMContribution,​R> mapper,
                                                              SerializableSupplier<S> identitySupplier,
                                                              SerializableBiFunction<S,​R,​S> accumulator,
                                                              SerializableBinaryOperator<S> combiner)
                                                       throws Exception
        Description copied from class: MapReducer
        Generic map-reduce used by the `OSMContributionView`.

        The combination of the used types and identity/reducer functions must make "mathematical" sense:

        • the accumulator and combiner functions need to be associative,
        • values generated by the identitySupplier factory must be an identity for the combiner function: `combiner(identitySupplier(),x)` must be equal to `x`,
        • the combiner function must be compatible with the accumulator function: `combiner(u, accumulator(identitySupplier(), t)) == accumulator.apply(u, t)`

        Functionally, this interface is similar to Java11 Stream's reduce(identity,accumulator,combiner) interface.

        Specified by:
        mapReduceCellsOSMContribution in class MapReducer<X>
        Type Parameters:
        R - the data type returned by the `mapper` function
        S - the data type used to contain the "reduced" (intermediate and final) results
        Parameters:
        mapper - a function that's called for each `OSMContribution`
        identitySupplier - a factory function that returns a new starting value to reduce results into (e.g. when summing values, one needs to start at zero)
        accumulator - a function that takes a result from the `mapper` function (type <R>) and an accumulation value (type <S>, e.g. the result of `identitySupplier()`) and returns the "sum" of the two; contrary to `combiner`, this function is allowed to alter (mutate) the state of the accumulation value (e.g. directly adding new values to an existing Set object)
        combiner - a function that calculates the "sum" of two <S> values; this function must be pure (have no side effects), and is not allowed to alter the state of the two input objects it gets!
        Returns:
        the result of the map-reduce operation, the final result of the last call to the `combiner` function, after all `mapper` results have been aggregated (in the `accumulator` and `combiner` steps)
        Throws:
        Exception
      • flatMapReduceCellsOSMContributionGroupedById

        protected <R,​S> S flatMapReduceCellsOSMContributionGroupedById​(SerializableFunction<List<OSMContribution>,​Iterable<R>> mapper,
                                                                             SerializableSupplier<S> identitySupplier,
                                                                             SerializableBiFunction<S,​R,​S> accumulator,
                                                                             SerializableBinaryOperator<S> combiner)
                                                                      throws Exception
        Description copied from class: MapReducer
        Generic "flat" version of the map-reduce used by the `OSMContributionView`, with by-osm-id grouped input to the `mapper` function.

        Contrary to the "normal" map-reduce, the "flat" version adds the possibility to return any number of results in the `mapper` function. Additionally, this interface provides the `mapper` function with a list of all `OSMContribution`s of a particular OSM entity. This is used to do more complex analyses that require the full edit history of the respective OSM entities as input.

        The combination of the used types and identity/reducer functions must make "mathematical" sense:

        • the accumulator and combiner functions need to be associative,
        • values generated by the identitySupplier factory must be an identity for the combiner function: `combiner(identitySupplier(),x)` must be equal to `x`,
        • the combiner function must be compatible with the accumulator function: `combiner(u, accumulator(identitySupplier(), t)) == accumulator.apply(u, t)`

        Functionally, this interface is similar to Java11 Stream's reduce(identity,accumulator,combiner) interface.

        Specified by:
        flatMapReduceCellsOSMContributionGroupedById in class MapReducer<X>
        Type Parameters:
        R - the data type returned by the `mapper` function
        S - the data type used to contain the "reduced" (intermediate and final) results
        Parameters:
        mapper - a function that's called for all `OSMContribution`s of a particular OSM entity; returns a list of results (which can have any number of entries).
        identitySupplier - a factory function that returns a new starting value to reduce results into (e.g. when summing values, one needs to start at zero)
        accumulator - a function that takes a result from the `mapper` function (type <R>) and an accumulation value (type <S>, e.g. the result of `identitySupplier()`) and returns the "sum" of the two; contrary to `combiner`, this function is allowed to alter (mutate) the state of the accumulation value (e.g. directly adding new values to an existing Set object)
        combiner - a function that calculates the "sum" of two <S> values; this function must be pure (have no side effects), and is not allowed to alter the state of the two input objects it gets!
        Returns:
        the result of the map-reduce operation, the final result of the last call to the `combiner` function, after all `mapper` results have been aggregated (in the `accumulator` and `combiner` steps)
        Throws:
        Exception
      • mapReduceCellsOSMEntitySnapshot

        protected <R,​S> S mapReduceCellsOSMEntitySnapshot​(SerializableFunction<OSMEntitySnapshot,​R> mapper,
                                                                SerializableSupplier<S> identitySupplier,
                                                                SerializableBiFunction<S,​R,​S> accumulator,
                                                                SerializableBinaryOperator<S> combiner)
                                                         throws Exception
        Description copied from class: MapReducer
        Generic map-reduce used by the `OSMEntitySnapshotView`.

        The combination of the used types and identity/reducer functions must make "mathematical" sense:

        • the accumulator and combiner functions need to be associative,
        • values generated by the identitySupplier factory must be an identity for the combiner function: `combiner(identitySupplier(),x)` must be equal to `x`,
        • the combiner function must be compatible with the accumulator function: `combiner(u, accumulator(identitySupplier(), t)) == accumulator.apply(u, t)`

        Functionally, this interface is similar to Java11 Stream's reduce(identity,accumulator,combiner) interface.

        Specified by:
        mapReduceCellsOSMEntitySnapshot in class MapReducer<X>
        Type Parameters:
        R - the data type returned by the `mapper` function
        S - the data type used to contain the "reduced" (intermediate and final) results
        Parameters:
        mapper - a function that's called for each `OSMEntitySnapshot`
        identitySupplier - a factory function that returns a new starting value to reduce results into (e.g. when summing values, one needs to start at zero)
        accumulator - a function that takes a result from the `mapper` function (type <R>) and an accumulation value (type <S>, e.g. the result of `identitySupplier()`) and returns the "sum" of the two; contrary to `combiner`, this function is allowed to alter (mutate) the state of the accumulation value (e.g. directly adding new values to an existing Set object)
        combiner - a function that calculates the "sum" of two <S> values; this function must be pure (have no side effects), and is not allowed to alter the state of the two input objects it gets!
        Returns:
        the result of the map-reduce operation, the final result of the last call to the `combiner` function, after all `mapper` results have been aggregated (in the `accumulator` and `combiner` steps)
        Throws:
        Exception
      • flatMapReduceCellsOSMEntitySnapshotGroupedById

        protected <R,​S> S flatMapReduceCellsOSMEntitySnapshotGroupedById​(SerializableFunction<List<OSMEntitySnapshot>,​Iterable<R>> mapper,
                                                                               SerializableSupplier<S> identitySupplier,
                                                                               SerializableBiFunction<S,​R,​S> accumulator,
                                                                               SerializableBinaryOperator<S> combiner)
                                                                        throws Exception
        Description copied from class: MapReducer
        Generic "flat" version of the map-reduce used by the `OSMEntitySnapshotView`, with by-osm-id grouped input to the `mapper` function.

        Contrary to the "normal" map-reduce, the "flat" version adds the possibility to return any number of results in the `mapper` function. Additionally, this interface provides the `mapper` function with a list of all `OSMContribution`s of a particular OSM entity. This is used to do more complex analyses that require the full list of snapshots of the respective OSM entities as input.

        The combination of the used types and identity/reducer functions must make "mathematical" sense:

        • the accumulator and combiner functions need to be associative,
        • values generated by the identitySupplier factory must be an identity for the combiner function: `combiner(identitySupplier(),x)` must be equal to `x`,
        • the combiner function must be compatible with the accumulator function: `combiner(u, accumulator(identitySupplier(), t)) == accumulator.apply(u, t)`

        Functionally, this interface is similar to Java11 Stream's reduce(identity,accumulator,combiner) interface.

        Specified by:
        flatMapReduceCellsOSMEntitySnapshotGroupedById in class MapReducer<X>
        Type Parameters:
        R - the data type returned by the `mapper` function
        S - the data type used to contain the "reduced" (intermediate and final) results
        Parameters:
        mapper - a function that's called for all `OSMEntitySnapshot`s of a particular OSM entity; returns a list of results (which can have any number of entries)
        identitySupplier - a factory function that returns a new starting value to reduce results into (e.g. when summing values, one needs to start at zero)
        accumulator - a function that takes a result from the `mapper` function (type <R>) and an accumulation value (type <S>, e.g. the result of `identitySupplier()`) and returns the "sum" of the two; contrary to `combiner`, this function is allowed to alter (mutate) the state of the accumulation value (e.g. directly adding new values to an existing Set object)
        combiner - a function that calculates the "sum" of two <S> values; this function must be pure (have no side effects), and is not allowed to alter the state of the two input objects it gets!
        Returns:
        the result of the map-reduce operation, the final result of the last call to the `combiner` function, after all `mapper` results have been aggregated (in the `accumulator` and `combiner` steps)
        Throws:
        Exception
      • isActive

        public boolean isActive()
      • isActive

        public default <T> boolean isActive​(T ignored)
      • osmType

        @Deprecated(since="0.7.0",
                    forRemoval=true)
        @Contract(pure=true)
        public default M osmType​(OSMType type1,
                                 OSMType... otherTypes)
        Deprecated, for removal: This API element is subject to removal in a future version.
        use oshdb-filter filter(String) instead
        Limits the analysis to the given osm entity types.
        Parameters:
        type1 - the set of osm types to filter (e.g. `OSMType.NODE`)
        otherTypes - more osm types which should be analyzed
        Returns:
        `this` mapReducer (can be used to chain multiple commands together)