use of com.hazelcast.jet.Jet in project hazelcast-jet-reference-manual by hazelcast.
the class HelloWorld method main.
public static void main(String[] args) {
// Create the specification of the computation pipeline. Note
// it's a pure POJO: no instance of Jet needed to create it.
Pipeline p = Pipeline.create();
p.drawFrom(Sources.<String>list("text")).flatMap(word -> traverseArray(word.toLowerCase().split("\\W+"))).filter(word -> !word.isEmpty()).groupingKey(wholeItem()).aggregate(counting()).drainTo(Sinks.map("counts"));
// Start Jet, populate the input list
JetInstance jet = Jet.newJetInstance();
try {
List<String> text = jet.getList("text");
text.add("hello world hello hello world");
text.add("world world hello world");
// Perform the computation
jet.newJob(p).join();
// Check the results
Map<String, Long> counts = jet.getMap("counts");
System.out.println("Count of hello: " + counts.get("hello"));
System.out.println("Count of world: " + counts.get("world"));
} finally {
Jet.shutdownAll();
}
}
use of com.hazelcast.jet.Jet in project hazelcast-jet-reference-manual by hazelcast.
the class ImdgConnectors method s14.
static void s14() {
JetInstance jet = Jet.newJetInstance();
// tag::s14[]
IList<Integer> inputList = jet.getList("inputList");
for (int i = 0; i < 10; i++) {
inputList.add(i);
}
Pipeline p = Pipeline.create();
p.drawFrom(Sources.<Integer>list("inputList")).map(i -> "item" + i).drainTo(Sinks.list("resultList"));
jet.newJob(p).join();
IList<String> resultList = jet.getList("resultList");
System.out.println("Results: " + new ArrayList<>(resultList));
// end::s14[]
}
use of com.hazelcast.jet.Jet in project hazelcast-jet-reference-manual by hazelcast.
the class LogDebug method s3.
static void s3() {
// tag::s3[]
Pipeline p = Pipeline.create();
p.drawFrom(Sources.<String>list("inputList")).flatMap(line -> traverseArray(line.toLowerCase().split("\\W+"))).filter(word -> !word.isEmpty()).peek().groupingKey(wholeItem()).aggregate(counting()).drainTo(Sinks.map("counts"));
// end::s3[]
// tag::s4[]
JetInstance jet = Jet.newJetInstance();
try {
jet.getList("inputList").addAll(asList("The quick brown fox", "jumped over the lazy dog"));
jet.newJob(p).join();
} finally {
Jet.shutdownAll();
}
// end::s4[]
}
use of com.hazelcast.jet.Jet in project gora by apache.
the class JetTest method jetWordCount.
@Test
public void jetWordCount() throws GoraException {
dataStoreOut = DataStoreFactory.getDataStore(Long.class, ResultPageView.class, utility.getConfiguration());
Query<Long, ResultPageView> query = dataStoreOut.newQuery();
JetEngine<Long, ResultPageView, Long, ResultPageView> jetEngine = new JetEngine<>();
Pattern delimiter = Pattern.compile("\\W+");
Pipeline p = Pipeline.create();
p.drawFrom(jetEngine.createDataSource(dataStoreOut, query)).flatMap(e -> traverseArray(delimiter.split(e.getValue().getUrl().toString()))).filter(word -> !word.isEmpty()).groupingKey(wholeItem()).aggregate(counting()).drainTo(Sinks.map("COUNTS"));
JetInstance jet = Jet.newJetInstance();
;
jet.newJob(p).join();
IMap<String, Long> counts = jet.getMap("COUNTS");
assertEquals(3L, (long) counts.get("the"));
}
Aggregations