Java Code Examples for org.apache.spark.api.java.JavaRDDLike

The following examples show how to use org.apache.spark.api.java.JavaRDDLike. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: beam   Source File: BoundedDataset.java    License: Apache License 2.0 6 votes vote down vote up
Iterable<WindowedValue<T>> getValues(PCollection<T> pcollection) {
  if (windowedValues == null) {
    WindowFn<?, ?> windowFn = pcollection.getWindowingStrategy().getWindowFn();
    Coder<? extends BoundedWindow> windowCoder = windowFn.windowCoder();
    final WindowedValue.WindowedValueCoder<T> windowedValueCoder;
    if (windowFn instanceof GlobalWindows) {
      windowedValueCoder = WindowedValue.ValueOnlyWindowedValueCoder.of(pcollection.getCoder());
    } else {
      windowedValueCoder =
          WindowedValue.FullWindowedValueCoder.of(pcollection.getCoder(), windowCoder);
    }
    JavaRDDLike<byte[], ?> bytesRDD = rdd.map(CoderHelpers.toByteFunction(windowedValueCoder));
    List<byte[]> clientBytes = bytesRDD.collect();
    windowedValues =
        clientBytes.stream()
            .map(bytes -> CoderHelpers.fromByteArray(bytes, windowedValueCoder))
            .collect(Collectors.toList());
  }
  return windowedValues;
}
 
Example 2
Source Project: beam   Source File: BoundedDataset.java    License: Apache License 2.0 5 votes vote down vote up
List<byte[]> getBytes(WindowedValue.WindowedValueCoder<T> wvCoder) {
  if (clientBytes == null) {
    JavaRDDLike<byte[], ?> bytesRDD = rdd.map(CoderHelpers.toByteFunction(wvCoder));
    clientBytes = bytesRDD.collect();
  }
  return clientBytes;
}
 
Example 3
Source Project: deeplearning4j   Source File: SharedTrainingMaster.java    License: Apache License 2.0 5 votes vote down vote up
protected <T, Repr extends JavaRDDLike<T, Repr>> long getTotalDataSetObjectCount(
                JavaRDDLike<T, Repr> trainingData) {
    if (collectTrainingStats)
        stats.logCountStart();

    long totalDataSetObjectCount = trainingData.count();

    if (collectTrainingStats)
        stats.logCountEnd();

    return totalDataSetObjectCount;
}
 
Example 4
protected <T, Repr extends JavaRDDLike<T, Repr>> long getTotalDataSetObjectCount(
                JavaRDDLike<T, Repr> trainingData) {
    if (collectTrainingStats)
        stats.logCountStart();
    long totalDataSetObjectCount = trainingData.count();
    if (collectTrainingStats)
        stats.logCountEnd();
    return totalDataSetObjectCount;
}
 
Example 5
public static int getPartitions(JavaRDDLike<?,?> rdd) {
    int rddPartitions = rdd.getNumPartitions();
    return Math.max(rddPartitions, getDefaultPartitions());
}
 
Example 6
public static int getPartitions(JavaRDDLike<?,?> rdd1, JavaRDDLike<?,?> rdd2) {
    int rddPartitions1 = rdd1.getNumPartitions();
    int rddPartitions2 = rdd2.getNumPartitions();
    int max = Math.max(rddPartitions1, rddPartitions2);
    return Math.max(max, getDefaultPartitions());
}