You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@nemo.apache.org by GitBox <gi...@apache.org> on 2022/08/01 04:19:40 UTC

[GitHub] [incubator-nemo] wonook commented on a diff in pull request #314: [NEMO-481] Add Stream examples

wonook commented on code in PR #314:
URL: https://github.com/apache/incubator-nemo/pull/314#discussion_r934125685


##########
examples/beam/src/main/java/org/apache/nemo/examples/beam/EDGARDocumentSuccessRate.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.nemo.examples.beam;
+
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.apache.beam.sdk.transforms.*;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.SlidingWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.joda.time.Duration;
+import org.joda.time.Instant;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Application for EDGAR dataset.
+ * Format: ip, date, time, zone, doc_cik, access number, doc_name, code, size, idx, norefer, noagent, find, crawler.
+ * Calculate the success rate of each document.
+ */
+public final class EDGARDocumentSuccessRate {
+  private static final Logger LOG = LoggerFactory.getLogger(EDGARDocumentSuccessRate.class.getName());
+
+  /**
+   * Private Constructor.
+   */
+  private EDGARDocumentSuccessRate() {
+  }
+
+  /**
+   * Main function for the BEAM program.
+   *
+   * @param args arguments.
+   */
+  public static void main(final String[] args) {
+    final String inputFilePath = args[0];
+    final String windowType = args[1];
+    final String outputFilePath = args[2];
+
+    final Window<KV<String, Integer>> windowFn;
+    if (windowType.equals("fixed")) {
+      windowFn = Window.into(FixedWindows.of(Duration.standardSeconds(5)));
+    } else {
+      windowFn = Window.into(SlidingWindows.of(Duration.standardSeconds(10))
+        .every(Duration.standardSeconds(5)));
+    }
+
+    final PipelineOptions options = NemoPipelineOptionsFactory.create();
+    options.setJobName("EDGAR: Document retrieval success rate");
+
+    final Pipeline p = Pipeline.create(options);
+
+    final PCollection<KV<String, Integer>> source = GenericSourceSink.read(p, inputFilePath)
+      .apply(ParDo.of(new DoFn<String, KV<String, Integer>>() {
+        @ProcessElement
+        public void processElement(@DoFn.Element final String elem,
+                                   final OutputReceiver<KV<String, Integer>> out) {
+          final String[] splitt = elem.split(",");
+          final Integer success = splitt[7].startsWith("2") ? 1 : 0;
+          try {
+            out.outputWithTimestamp(KV.of(splitt[6], success), Instant.parse(splitt[1] + "T" + splitt[2] + "Z"));
+          } catch (Exception e) {
+            LOG.warn("Parsing failed due to: ", e);
+          }
+        }
+      }));
+    source.apply(windowFn)

Review Comment:
   I'll include in the comment, but 1 means success, and 0 means failure. In this case, calculating the mean of the given 1s and 0s produces the success rate.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@nemo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org