madhawa-gunasekara commented on a change in pull request #175: GORA-546 
Hazelcast Jet execution engine support
URL: https://github.com/apache/gora/pull/175#discussion_r303984749
 
 

 ##########
 File path: gora-jet/src/test/java/org/apache/gora/jet/JetTest.java
 ##########
 @@ -0,0 +1,132 @@
+package org.apache.gora.jet;
+
+import com.hazelcast.core.IMap;
+import com.hazelcast.jet.Jet;
+import com.hazelcast.jet.JetInstance;
+import com.hazelcast.jet.pipeline.BatchSource;
+import com.hazelcast.jet.pipeline.Pipeline;
+import com.hazelcast.jet.pipeline.Sinks;
+import org.apache.gora.jet.generated.Pageview;
+import org.apache.gora.jet.generated.ResultPageView;
+import org.apache.gora.query.Query;
+import org.apache.gora.store.DataStore;
+import org.apache.gora.store.DataStoreFactory;
+import org.apache.gora.util.GoraException;
+import org.apache.hadoop.conf.Configuration;
+import org.junit.Test;
+
+import java.util.regex.Pattern;
+
+import static com.hazelcast.jet.Traversers.traverseArray;
+import static com.hazelcast.jet.aggregate.AggregateOperations.counting;
+import static com.hazelcast.jet.function.Functions.wholeItem;
+
+public class JetTest {
+
+  private static DataStore<Long, Pageview> dataStore;
+  private static DataStore<Long, ResultPageView> dataStoreOut;
+  static Query<Long, Pageview> query = null;
+
+  @Test
+  public void testNewJetSource() {
+
+    Configuration conf =  new Configuration();
+
+    try {
+      dataStore = DataStoreFactory.getDataStore(Long.class, Pageview.class, 
conf);
+    } catch (GoraException e) {
+      e.printStackTrace();
+    }
+
+    try {
+      dataStoreOut = DataStoreFactory.getDataStore(Long.class, 
ResultPageView.class, conf);
+    } catch (GoraException e) {
+      e.printStackTrace();
+    }
+
+    query = dataStore.newQuery();
+    query.setStartKey(0L);
+    query.setEndKey(55L);
+
+    JetEngine<Long, Pageview, Long, ResultPageView> jetEngine = new 
JetEngine<>();
+    BatchSource<JetInputOutputFormat<Long, Pageview>> fileSource = 
jetEngine.createDataSource(dataStore, query);
+    Pipeline p = Pipeline.create();
+    p.drawFrom(fileSource)
+        .filter(item -> 
item.getValue().getIp().toString().equals("88.240.129.183"))
+        .map(e -> {
+          ResultPageView resultPageView = new ResultPageView();
+          resultPageView.setIp(e.getValue().getIp());
+          resultPageView.setTimestamp(e.getValue().getTimestamp());
+          resultPageView.setUrl(e.getValue().getUrl());
+          return new JetInputOutputFormat<Long, 
ResultPageView>(e.getValue().getTimestamp(), resultPageView);
+        })
+        .drainTo(jetEngine.createDataSink(dataStoreOut));
+
+    JetInstance jet = Jet.newJetInstance();
+    Jet.newJetInstance();
+    try {
+      jet.newJob(p).join();
+    } finally {
+      Jet.shutdownAll();
+    }
+  }
+
+  @Test
+  public void insertData() {
+    try {
+      dataStoreOut = DataStoreFactory.getDataStore(Long.class, 
ResultPageView.class, new Configuration());
+    } catch (GoraException e) {
+      e.printStackTrace();
+    }
+
+    ResultPageView resultPageView = new ResultPageView();
+    resultPageView.setIp("123");
+    resultPageView.setTimestamp(123L);
+    resultPageView.setUrl("I am the the one");
+
+    ResultPageView resultPageView1 = new ResultPageView();
+    resultPageView1.setIp("123");
+    resultPageView1.setTimestamp(123L);
+    resultPageView1.setUrl("How are you");
+
+    try {
+      dataStoreOut.put(1L,resultPageView);
+      dataStoreOut.put(2L,resultPageView1);
+      dataStoreOut.flush();
 
 Review comment:
   Verify whether insert has happened correctly by retrieving 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to