Tabnine Logo
JavaDStream.map
Code IndexAdd Tabnine to your IDE (free)

How to use
map
method
in
org.apache.spark.streaming.api.java.JavaDStream

Best Java code snippets using org.apache.spark.streaming.api.java.JavaDStream.map (Showing top 20 results out of 315)

origin: databricks/learning-spark

  Flags.getInstance().getWindowLength(),
  Flags.getInstance().getSlideInterval());
JavaDStream<String> ip = accessLogsDStream.map(
 new Function<ApacheAccessLog, String>() {
  public String call(ApacheAccessLog entry) {
  }});
JavaDStream<Long> requestCountRBW = accessLogsDStream.map(new Function<ApacheAccessLog, Long>() {
  public Long call(ApacheAccessLog entry) {
   return 1L;
origin: databricks/learning-spark

= logData.map(new Functions.ParseFromLogLine()).cache();
origin: org.apache.beam/beam-runners-spark

final Iterable<WindowedValue<T>> windowedValues =
  StreamSupport.stream(timestampedValues.spliterator(), false)
    .map(
      timestampedValue ->
        WindowedValue.of(
  jssc.sparkContext()
    .parallelize(CoderHelpers.toByteArrays(windowedValues, windowCoder))
    .map(CoderHelpers.fromByteFunction(windowCoder));
origin: baghelamit/iot-traffic-monitor

/**
 * Method to get total traffic counts of different type of vehicles for each route.
 * 
 * @param filteredIotDataStream IoT data stream
 */
public void processTotalTrafficData(JavaDStream<IoTData> filteredIotDataStream) {
  // We need to get count of vehicle group by routeId and vehicleType
  JavaPairDStream<AggregateKey, Long> countDStreamPair = filteredIotDataStream
      .mapToPair(iot -> new Tuple2<>(new AggregateKey(iot.getRouteId(), iot.getVehicleType()), 1L))
      .reduceByKey((a, b) -> a + b);
  
  // Need to keep state for total count
  JavaMapWithStateDStream<AggregateKey, Long, Long, Tuple2<AggregateKey, Long>> countDStreamWithStatePair = countDStreamPair
      .mapWithState(StateSpec.function(totalSumFunc).timeout(Durations.seconds(3600)));//maintain state for one hour
  // Transform to dstream of TrafficData
  JavaDStream<Tuple2<AggregateKey, Long>> countDStream = countDStreamWithStatePair.map(tuple2 -> tuple2);
  JavaDStream<TotalTrafficData> trafficDStream = countDStream.map(totalTrafficDataFunc);
  // Map Cassandra table column
  Map<String, String> columnNameMappings = new HashMap<String, String>();
  columnNameMappings.put("routeId", "routeid");
  columnNameMappings.put("vehicleType", "vehicletype");
  columnNameMappings.put("totalCount", "totalcount");
  columnNameMappings.put("timeStamp", "timestamp");
  columnNameMappings.put("recordDate", "recorddate");
  // call CassandraStreamingJavaUtil function to save in DB
  javaFunctions(trafficDStream).writerBuilder("traffickeyspace", "total_traffic",
      CassandraJavaUtil.mapToRow(TotalTrafficData.class, columnNameMappings)).saveToCassandra();
}
origin: jaibeermalik/searchanalytics-bigdata

public JavaPairDStream<Integer, String> topProductViewsCountInLastOneHour(
    JavaDStream<String> fileStream) {
  JavaDStream<String> onlyQueryStringStream = fileStream
      .filter(new Function<String, Boolean>() {
        @Override
        public Boolean call(String eventString) throws Exception {
          LOG.debug("Filtering the incoming event stream: {}",
              eventString);
          String productIdString = getProductIdString(eventString);
          if (productIdString != null && productIdString != ""
              && productIdString != "null") {
            LOG.debug("Valid productid found : {}",
                productIdString);
            return true;
          }
          return false;
        }
      });
  JavaPairDStream<String, Integer> productIdCountsStream = onlyQueryStringStream
      .map(new PairFunction<String, String, Integer>() {
        @Override
        public Tuple2<String, Integer> call(String eventString) {
          String productIdString = getProductIdString(eventString);
          return new Tuple2<String, Integer>(productIdString, 1);
        }
      });
  return getSortedTopCount(productIdCountsStream);
}
origin: jaibeermalik/searchanalytics-bigdata

public JavaPairDStream<Integer, String> topQueryStringsCountInLastOneHour(
    JavaDStream<String> fileStream) {
  JavaDStream<String> onlyQueryStringStream = fileStream
      .filter(new Function<String, Boolean>() {
        @Override
        public Boolean call(String eventString) throws Exception {
          LOG.debug("Filtering the incoming event stream: {}",
              eventString);
          String queryString = getQueryString(eventString);
          if (queryString != null && queryString != ""
              && queryString != "null") {
            LOG.debug("Valid querystring found : {}",
                queryString);
            return true;
          }
          return false;
        }
      });
  JavaPairDStream<String, Integer> queryStringStream = onlyQueryStringStream
      .map(new PairFunction<String, String, Integer>() {
        @Override
        public Tuple2<String, Integer> call(String eventString) {
          String queryString = getQueryString(eventString);
          return new Tuple2<String, Integer>(queryString, 1);
        }
      });
  return getSortedTopCount(queryStringStream);
}
origin: jaibeermalik/searchanalytics-bigdata

.map(new PairFunction<SparkFlumeEvent, String, Integer>() {
origin: jaibeermalik/searchanalytics-bigdata

.map(new PairFunction<SparkFlumeEvent, String, Integer>() {
  @Override
  public Tuple2<String, Integer> call(SparkFlumeEvent event) {
origin: org.apache.beam/beam-runners-spark

@Override
@SuppressWarnings("unchecked")
public void cache(String storageLevel, Coder<?> coder) {
 // we "force" MEMORY storage level in streaming
 if (!StorageLevel.fromString(storageLevel).equals(StorageLevel.MEMORY_ONLY_SER())) {
  LOG.warn(
    "Provided StorageLevel: {} is ignored for streams, using the default level: {}",
    storageLevel,
    StorageLevel.MEMORY_ONLY_SER());
 }
 // Caching can cause Serialization, we need to code to bytes
 // more details in https://issues.apache.org/jira/browse/BEAM-2669
 Coder<WindowedValue<T>> wc = (Coder<WindowedValue<T>>) coder;
 this.dStream =
   dStream.map(CoderHelpers.toByteFunction(wc)).cache().map(CoderHelpers.fromByteFunction(wc));
}
origin: org.apache.spark/spark-streaming-flume

 public static void main(String[] args) throws Exception {
  if (args.length != 2) {
   System.err.println("Usage: JavaFlumeEventCount <host> <port>");
   System.exit(1);
  }

  String host = args[0];
  int port = Integer.parseInt(args[1]);

  Duration batchInterval = new Duration(2000);
  SparkConf sparkConf = new SparkConf().setAppName("JavaFlumeEventCount");
  JavaStreamingContext ssc = new JavaStreamingContext(sparkConf, batchInterval);
  JavaReceiverInputDStream<SparkFlumeEvent> flumeStream =
   FlumeUtils.createStream(ssc, host, port);

  flumeStream.count();

  flumeStream.count().map(in -> "Received " + in + " flume events.").print();

  ssc.start();
  ssc.awaitTermination();
 }
}
origin: org.apache.spark/spark-streaming_2.11

@SuppressWarnings("unchecked")
@Test
public void testMap() {
 List<List<String>> inputData = Arrays.asList(
   Arrays.asList("hello", "world"),
   Arrays.asList("goodnight", "moon"));
 List<List<Integer>> expected = Arrays.asList(
   Arrays.asList(5,5),
   Arrays.asList(9,4));
 JavaDStream<String> stream = JavaTestUtils.attachTestInputStream(ssc, inputData, 1);
 JavaDStream<Integer> letterCount = stream.map(String::length);
 JavaTestUtils.attachTestOutputStream(letterCount);
 List<List<Integer>> result = JavaTestUtils.runStreams(ssc, 2, 2);
 assertOrderInvariantEquals(expected, result);
}
origin: org.apache.spark/spark-streaming_2.10

@Test
public void testMap() {
 List<List<String>> inputData = Arrays.asList(
  Arrays.asList("hello", "world"),
  Arrays.asList("goodnight", "moon"));
 List<List<Integer>> expected = Arrays.asList(
  Arrays.asList(5, 5),
  Arrays.asList(9, 4));
 JavaDStream<String> stream = JavaTestUtils.attachTestInputStream(ssc, inputData, 1);
 JavaDStream<Integer> letterCount = stream.map(String::length);
 JavaTestUtils.attachTestOutputStream(letterCount);
 List<List<Integer>> result = JavaTestUtils.runStreams(ssc, 2, 2);
 assertOrderInvariantEquals(expected, result);
}
origin: org.apache.spark/spark-streaming_2.11

@Test
public void testMap() {
 List<List<String>> inputData = Arrays.asList(
  Arrays.asList("hello", "world"),
  Arrays.asList("goodnight", "moon"));
 List<List<Integer>> expected = Arrays.asList(
  Arrays.asList(5, 5),
  Arrays.asList(9, 4));
 JavaDStream<String> stream = JavaTestUtils.attachTestInputStream(ssc, inputData, 1);
 JavaDStream<Integer> letterCount = stream.map(String::length);
 JavaTestUtils.attachTestOutputStream(letterCount);
 List<List<Integer>> result = JavaTestUtils.runStreams(ssc, 2, 2);
 assertOrderInvariantEquals(expected, result);
}
origin: org.apache.spark/spark-streaming_2.10

@SuppressWarnings("unchecked")
@Test
public void testMap() {
 List<List<String>> inputData = Arrays.asList(
   Arrays.asList("hello", "world"),
   Arrays.asList("goodnight", "moon"));
 List<List<Integer>> expected = Arrays.asList(
   Arrays.asList(5,5),
   Arrays.asList(9,4));
 JavaDStream<String> stream = JavaTestUtils.attachTestInputStream(ssc, inputData, 1);
 JavaDStream<Integer> letterCount = stream.map(String::length);
 JavaTestUtils.attachTestOutputStream(letterCount);
 List<List<Integer>> result = JavaTestUtils.runStreams(ssc, 2, 2);
 assertOrderInvariantEquals(expected, result);
}
origin: org.apache.spark/spark-streaming_2.11

@SuppressWarnings("unchecked")
@Test
public void testCheckpointMasterRecovery() throws InterruptedException {
 List<List<String>> inputData = Arrays.asList(
   Arrays.asList("this", "is"),
   Arrays.asList("a", "test"),
   Arrays.asList("counting", "letters"));
 List<List<Integer>> expectedInitial = Arrays.asList(
   Arrays.asList(4,2));
 List<List<Integer>> expectedFinal = Arrays.asList(
   Arrays.asList(1,4),
   Arrays.asList(8,7));
 File tempDir = Files.createTempDir();
 tempDir.deleteOnExit();
 ssc.checkpoint(tempDir.getAbsolutePath());
 JavaDStream<String> stream = JavaCheckpointTestUtils.attachTestInputStream(ssc, inputData, 1);
 JavaDStream<Integer> letterCount = stream.map(String::length);
 JavaCheckpointTestUtils.attachTestOutputStream(letterCount);
 List<List<Integer>> initialResult = JavaTestUtils.runStreams(ssc, 1, 1);
 assertOrderInvariantEquals(expectedInitial, initialResult);
 Thread.sleep(1000);
 ssc.stop();
 ssc = new JavaStreamingContext(tempDir.getAbsolutePath());
 // Tweak to take into consideration that the last batch before failure
 // will be re-processed after recovery
 List<List<Integer>> finalResult = JavaCheckpointTestUtils.runStreams(ssc, 2, 3);
 assertOrderInvariantEquals(expectedFinal, finalResult.subList(1, 3));
 ssc.stop();
 Utils.deleteRecursively(tempDir);
}
origin: org.apache.spark/spark-streaming_2.10

@SuppressWarnings("unchecked")
@Test
public void testCheckpointMasterRecovery() throws InterruptedException {
 List<List<String>> inputData = Arrays.asList(
   Arrays.asList("this", "is"),
   Arrays.asList("a", "test"),
   Arrays.asList("counting", "letters"));
 List<List<Integer>> expectedInitial = Arrays.asList(
   Arrays.asList(4,2));
 List<List<Integer>> expectedFinal = Arrays.asList(
   Arrays.asList(1,4),
   Arrays.asList(8,7));
 File tempDir = Files.createTempDir();
 tempDir.deleteOnExit();
 ssc.checkpoint(tempDir.getAbsolutePath());
 JavaDStream<String> stream = JavaCheckpointTestUtils.attachTestInputStream(ssc, inputData, 1);
 JavaDStream<Integer> letterCount = stream.map(String::length);
 JavaCheckpointTestUtils.attachTestOutputStream(letterCount);
 List<List<Integer>> initialResult = JavaTestUtils.runStreams(ssc, 1, 1);
 assertOrderInvariantEquals(expectedInitial, initialResult);
 Thread.sleep(1000);
 ssc.stop();
 ssc = new JavaStreamingContext(tempDir.getAbsolutePath());
 // Tweak to take into consideration that the last batch before failure
 // will be re-processed after recovery
 List<List<Integer>> finalResult = JavaCheckpointTestUtils.runStreams(ssc, 2, 3);
 assertOrderInvariantEquals(expectedFinal, finalResult.subList(1, 3));
 ssc.stop();
 Utils.deleteRecursively(tempDir);
}
origin: org.apache.spark/spark-streaming_2.11

 private <K, S, T> void testOperation(
   List<List<K>> input,
   StateSpec<K, Integer, S, T> mapWithStateSpec,
   List<Set<T>> expectedOutputs,
   List<Set<Tuple2<K, S>>> expectedStateSnapshots) {
  int numBatches = expectedOutputs.size();
  JavaDStream<K> inputStream = JavaTestUtils.attachTestInputStream(ssc, input, 2);
  JavaMapWithStateDStream<K, Integer, S, T> mapWithStateDStream = JavaPairDStream.fromJavaDStream(
   inputStream.map(x -> new Tuple2<>(x, 1))).mapWithState(mapWithStateSpec);

  List<Set<T>> collectedOutputs =
    Collections.synchronizedList(new ArrayList<Set<T>>());
  mapWithStateDStream.foreachRDD(rdd -> collectedOutputs.add(Sets.newHashSet(rdd.collect())));
  List<Set<Tuple2<K, S>>> collectedStateSnapshots =
    Collections.synchronizedList(new ArrayList<Set<Tuple2<K, S>>>());
  mapWithStateDStream.stateSnapshots().foreachRDD(rdd ->
    collectedStateSnapshots.add(Sets.newHashSet(rdd.collect())));
  BatchCounter batchCounter = new BatchCounter(ssc.ssc());
  ssc.start();
  ((ManualClock) ssc.ssc().scheduler().clock())
    .advance(ssc.ssc().progressListener().batchDuration() * numBatches + 1);
  batchCounter.waitUntilBatchesCompleted(numBatches, 10000);

  Assert.assertEquals(expectedOutputs, collectedOutputs);
  Assert.assertEquals(expectedStateSnapshots, collectedStateSnapshots);
 }
}
origin: org.apache.spark/spark-streaming_2.10

 private <K, S, T> void testOperation(
   List<List<K>> input,
   StateSpec<K, Integer, S, T> mapWithStateSpec,
   List<Set<T>> expectedOutputs,
   List<Set<Tuple2<K, S>>> expectedStateSnapshots) {
  int numBatches = expectedOutputs.size();
  JavaDStream<K> inputStream = JavaTestUtils.attachTestInputStream(ssc, input, 2);
  JavaMapWithStateDStream<K, Integer, S, T> mapWithStateDStream = JavaPairDStream.fromJavaDStream(
   inputStream.map(x -> new Tuple2<>(x, 1))).mapWithState(mapWithStateSpec);

  List<Set<T>> collectedOutputs =
    Collections.synchronizedList(new ArrayList<Set<T>>());
  mapWithStateDStream.foreachRDD(rdd -> collectedOutputs.add(Sets.newHashSet(rdd.collect())));
  List<Set<Tuple2<K, S>>> collectedStateSnapshots =
    Collections.synchronizedList(new ArrayList<Set<Tuple2<K, S>>>());
  mapWithStateDStream.stateSnapshots().foreachRDD(rdd ->
    collectedStateSnapshots.add(Sets.newHashSet(rdd.collect())));
  BatchCounter batchCounter = new BatchCounter(ssc.ssc());
  ssc.start();
  ((ManualClock) ssc.ssc().scheduler().clock())
    .advance(ssc.ssc().progressListener().batchDuration() * numBatches + 1);
  batchCounter.waitUntilBatchesCompleted(numBatches, 10000);

  Assert.assertEquals(expectedOutputs, collectedOutputs);
  Assert.assertEquals(expectedStateSnapshots, collectedStateSnapshots);
 }
}
origin: org.apache.beam/beam-runners-spark

  mapWithStateDStream
    .flatMap(new Tuple2byteFlatMapFunction())
    .map(CoderHelpers.fromByteFunction(coder));
return new UnboundedDataset<>(readUnboundedStream, Collections.singletonList(id));
origin: co.cask.cdap/cdap-data-streams

 .map(new WrapOutputTransformFunction<>(stageSpec.getName()));
return new DStreamCollection<>(sec, outputDStream);
org.apache.spark.streaming.api.javaJavaDStreammap

Popular methods of JavaDStream

  • foreachRDD
  • mapToPair
  • union
  • filter
  • flatMap
  • dstream
  • countByValue
  • cache
  • transformToPair
  • window
  • count
  • transform
  • count,
  • transform,
  • countByValueAndWindow,
  • flatMapToPair,
  • print,
  • reduceByWindow,
  • repartition,
  • glom,
  • mapPartitions

Popular in Java

  • Reactive rest calls using spring rest template
  • getSharedPreferences (Context)
  • requestLocationUpdates (LocationManager)
  • getApplicationContext (Context)
  • Table (com.google.common.collect)
    A collection that associates an ordered pair of keys, called a row key and a column key, with a sing
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • Timer (java.util)
    Timers schedule one-shot or recurring TimerTask for execution. Prefer java.util.concurrent.Scheduled
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
  • ReentrantLock (java.util.concurrent.locks)
    A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now