本文整理汇总了Java中com.hazelcast.mapreduce.KeyValueSource类的典型用法代码示例。如果您正苦于以下问题:Java KeyValueSource类的具体用法?Java KeyValueSource怎么用?Java KeyValueSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyValueSource类属于com.hazelcast.mapreduce包,在下文中一共展示了KeyValueSource类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: execute
import com.hazelcast.mapreduce.KeyValueSource; //导入依赖的package包/类
@Override
public void execute(HazelcastInstance hazelcastInstance)
throws Exception {
JobTracker jobTracker = hazelcastInstance.getJobTracker("default");
IList<Person> list = hazelcastInstance.getList("persons");
KeyValueSource<String, Person> source = KeyValueSource.fromList(list);
Job<String, Person> job = jobTracker.newJob(source);
ICompletableFuture future = job.mapper(new SalaryMapper()) //
.combiner(new SalaryCombinerFactory()) //
.reducer(new SalaryReducerFactory()) //
.submit();
System.out.println(ToStringPrettyfier.toString(future.get()));
}
开发者ID:noctarius,项目名称:hazelcast-mapreduce-presentation,代码行数:19,代码来源:Tutorial4.java
示例2: execute
import com.hazelcast.mapreduce.KeyValueSource; //导入依赖的package包/类
@Override
public void execute(HazelcastInstance hazelcastInstance)
throws Exception {
JobTracker jobTracker = hazelcastInstance.getJobTracker("default");
IMap<String, SalaryYear> map = hazelcastInstance.getMap("salaries");
KeyValueSource<String, SalaryYear> source = KeyValueSource.fromMap(map);
Job<String, SalaryYear> job = jobTracker.newJob(source);
JobCompletableFuture<Integer> future = job //
.mapper(new SalarySumMapper()) //
.combiner(new SalarySumCombinerFactory()) //
.reducer(new SalarySumReducerFactory()) //
.submit(new SalarySumCollator());
System.out.println("Salary sum: " + future.get());
}
开发者ID:noctarius,项目名称:hazelcast-mapreduce-presentation,代码行数:20,代码来源:Tutorial6.java
示例3: execute
import com.hazelcast.mapreduce.KeyValueSource; //导入依赖的package包/类
@Override
public void execute(HazelcastInstance hazelcastInstance)
throws Exception {
JobTracker jobTracker = hazelcastInstance.getJobTracker("default");
IList<Person> list = hazelcastInstance.getList("persons");
KeyValueSource<String, Person> source = KeyValueSource.fromList(list);
Job<String, Person> job = jobTracker.newJob(source);
// Collect all people by state
ICompletableFuture future = job.mapper(new StateBasedCountMapper()).submit();
// Count people by state
// ICompletableFuture future = job.mapper(new StateBasedCountMapper()).reducer(new CountReducerFactory()).submit();
// Same as above but with precalculation per node
// ICompletableFuture future = job.mapper(new StateBasedCountMapper()).combiner(new CountCombinerFactory())
// .reducer(new CountReducerFactory()).submit();
System.out.println(ToStringPrettyfier.toString(future.get()));
}
开发者ID:noctarius,项目名称:hazelcast-mapreduce-presentation,代码行数:24,代码来源:Tutorial3.java
示例4: execute
import com.hazelcast.mapreduce.KeyValueSource; //导入依赖的package包/类
public void execute(HazelcastInstance hazelcastInstance)
throws Exception {
JobTracker jobTracker = hazelcastInstance.getJobTracker("default");
IMap<String, Double> map = hazelcastInstance.getMap("inputs");
map.put("EventA", new Double(Math.random() * 99 + 1));
map.put("EventB", new Double(Math.random() * 99 + 1));
KeyValueSource<String, Double> source = KeyValueSource.fromMap(map);
Job<String, Double> job = jobTracker.newJob(source);
JobCompletableFuture<List<KeyValueTuple>> future = job //
.mapper(new InvertedMapper()) //
.combiner(new InvertedCombinerFactory()) //
.reducer(new InvertedReducerFactory()) //
.submit(new InvertedCollator());
System.out.println("Result: " + ToStringPrettyfier.toString(future.get()));
}
开发者ID:bgokden,项目名称:predictblty,代码行数:22,代码来源:SparseMatrixMultiplication.java
示例5: predict
import com.hazelcast.mapreduce.KeyValueSource; //导入依赖的package包/类
@Override
public Collection<Classification> predict(Collection<? extends Object> data) throws Exception {
this.trainingdata = getTrainingdata();
JobTracker jobTracker = hazelcastInstance.getJobTracker("default");
KeyValueSource<Map<String, Serializable>, Classification> source = KeyValueSource.fromMap(this.trainingdata);
Job<Map<String, Serializable>, Classification> job = jobTracker.newJob(source);
JobCompletableFuture<List<Classification>> future = job //
.mapper(new DistanceBasedClassificationAlgorithmMapper(this.options,data)) //
.combiner(new DistanceBasedClassificationAlgorithmCombinerFactory(this.options)) //
.reducer(new DistanceBasedClassificationAlgorithmReducerFactory(this.options)) //
.submit(new DistanceBasedClassificationAlgorithmCollator(this.options));
return future.get();
}
开发者ID:bgokden,项目名称:predictblty,代码行数:18,代码来源:DistanceBasedClassificationAlgorithm.java
示例6: predict
import com.hazelcast.mapreduce.KeyValueSource; //导入依赖的package包/类
@Override
public Collection<Classification> predict(Collection<? extends Object> data) throws Exception {
this.trainingdata = getTrainingdata();
JobTracker jobTracker = hazelcastInstance.getJobTracker("default");
KeyValueSource<ByteHolder, ClassifiedFeature> source = KeyValueSource.fromMap(this.trainingdata);
Job<ByteHolder, ClassifiedFeature> job = jobTracker.newJob(source);
//
JobCompletableFuture<List<Classification>> future = job //
.mapper(new UserBasedCollaborativeFilteringRecommendationAlgorithmMapper(this.options,data)) //
.combiner(new DistanceBasedClassificationAlgorithmCombinerFactory(this.options)) //
.reducer(new DistanceBasedClassificationAlgorithmReducerFactory(this.options)) //
.submit(new DistanceBasedClassificationAlgorithmCollator(this.options));
return future.get();
}
开发者ID:bgokden,项目名称:predictblty,代码行数:18,代码来源:UserBasedCollaborativeFilteringRecommendationAlgorithm.java
示例7: mapReduceAverage
import com.hazelcast.mapreduce.KeyValueSource; //导入依赖的package包/类
private static double mapReduceAverage(HazelcastInstance hazelcastInstance)
throws Exception {
JobTracker jobTracker = hazelcastInstance.getJobTracker("default");
IMap<String, String> map = hazelcastInstance.getMap("numbers");
KeyValueSource<String, String> source = KeyValueSource.fromMap(map);
Job<String, String> job = jobTracker.newJob(source);
ICompletableFuture<Double> future = job
.mapper(new TokenizerMapper())
.combiner(new NumberCountCombinerFactory())
.reducer(new NumberCountAndOpReducerFactory())
.submit(new AverageCollator());
future.andThen(finishInfoCallback());
return future.get();
}
开发者ID:FutureProcessing,项目名称:HazelcastShowAndTell,代码行数:18,代码来源:HazelcastMapReducerJob.java
示例8: mapReduce
import com.hazelcast.mapreduce.KeyValueSource; //导入依赖的package包/类
private static Map<String, Long> mapReduce(HazelcastInstance hazelcastInstance)
throws Exception {
// Retrieving the JobTracker by name
JobTracker jobTracker = hazelcastInstance.getJobTracker("default");
// Creating the KeyValueSource for a Hazelcast IMap
IMap<String, String> map = hazelcastInstance.getMap("articles");
KeyValueSource<String, String> source = KeyValueSource.fromMap(map);
Job<String, String> job = jobTracker.newJob(source);
// Creating a new Job
ICompletableFuture<Map<String, Long>> future = job // returned future
.mapper(new TokenizerMapper()) // adding a mapper
.combiner(new WordCountCombinerFactory()) // adding a combiner through the factory
.reducer(new WordCountReducerFactory()) // adding a reducer through the factory
.submit(); // submit the task
// Attach a callback listener
future.andThen(buildCallback());
// Wait and retrieve the result
return future.get();
}
开发者ID:noctarius,项目名称:hz-map-reduce,代码行数:26,代码来源:MapReduceDemo.java
示例9: mapReduceCollate
import com.hazelcast.mapreduce.KeyValueSource; //导入依赖的package包/类
private static long mapReduceCollate(HazelcastInstance hazelcastInstance)
throws Exception {
// Retrieving the JobTracker by name
JobTracker jobTracker = hazelcastInstance.getJobTracker("default");
// Creating the KeyValueSource for a Hazelcast IMap
IMap<String, String> map = hazelcastInstance.getMap("articles");
KeyValueSource<String, String> source = KeyValueSource.fromMap(map);
// Creating a new Job
Job<String, String> job = jobTracker.newJob(source);
ICompletableFuture<Long> future = job // returned future
.mapper(new TokenizerMapper()) // adding a mapper
.combiner(new WordCountCombinerFactory()) // adding a combiner through the factory
.reducer(new WordCountReducerFactory()) // adding a reducer through the factory
.submit(new WordCountCollator()); // submit the task and supply a collator
// Wait and retrieve the result
return future.get();
}
开发者ID:noctarius,项目名称:hz-map-reduce,代码行数:23,代码来源:MapReduceDemo.java
示例10: execute
import com.hazelcast.mapreduce.KeyValueSource; //导入依赖的package包/类
@Override
public void execute(HazelcastInstance hazelcastInstance)
throws Exception {
JobTracker jobTracker = hazelcastInstance.getJobTracker("default");
IList<Person> list = hazelcastInstance.getList("persons");
KeyValueSource<String, Person> source = KeyValueSource.fromList(list);
Job<String, Person> job = jobTracker.newJob(source);
ICompletableFuture<List<Map.Entry<String, Integer>>> future = //
job.mapper(new SalaryMapper()) //
.combiner(new SalaryCombinerFactory()) //
.reducer(new SalaryReducerFactory()) //
.submit(new SalaryCollator());
// Intermediate result
List<Map.Entry<String, Integer>> orderedSalariesByState = future.get();
Map.Entry<String, Integer> topSalary = orderedSalariesByState.get(0);
IList<Crime> crimesList = hazelcastInstance.getList("crimes");
KeyValueSource<String, Crime> crimeSource = KeyValueSource.fromList(crimesList);
Job<String, Crime> crimeJob = jobTracker.newJob(crimeSource);
ICompletableFuture<Map<CrimeCategory, Integer>> crimeFuture = //
crimeJob.mapper(new CrimeMapper(topSalary.getKey())) //
.reducer(new CrimeReducerFactory()) //
.submit();
System.out.println(ToStringPrettyfier.toString(crimeFuture.get()));
}
开发者ID:noctarius,项目名称:hazelcast-mapreduce-presentation,代码行数:34,代码来源:Tutorial5.java
示例11: main
import com.hazelcast.mapreduce.KeyValueSource; //导入依赖的package包/类
public static void main(String[] args)
throws Exception {
// Prepare Hazelcast cluster
HazelcastInstance hazelcastInstance = buildCluster(3);
try {
// Read data
fillMapWithData(hazelcastInstance);
JobTracker tracker = hazelcastInstance.getJobTracker("default");
IMap<String, String> map = hazelcastInstance.getMap(MAP_NAME);
KeyValueSource<String, String> source = KeyValueSource.fromMap(map);
Job<String, String> job = tracker.newJob(source);
ICompletableFuture<Map<String, Integer>> future = job
.mapper(new TokenizerMapper())
// Activate Combiner to add combining phase!
// .combiner(new WordcountCombinerFactory())
.reducer(new WordcountReducerFactory())
.submit();
System.out.println(ToStringPrettyfier.toString(future.get()));
} finally {
// Shutdown cluster
Hazelcast.shutdownAll();
}
}
开发者ID:noctarius,项目名称:hazelcast-mapreduce-presentation,代码行数:34,代码来源:WordCount.java
示例12: doMapReduce
import com.hazelcast.mapreduce.KeyValueSource; //导入依赖的package包/类
private static void doMapReduce(
final HazelcastInstance instance,
final String filename) throws ExecutionException, InterruptedException, IOException
{
final IMap<Integer, SpatialPoint> geomap = instance.getMap(GEOMAP);
final JobTracker tracker = instance.getJobTracker("default");
final Job<Integer, SpatialPoint> job = tracker.newJob(KeyValueSource.fromMap(geomap));
final ICompletableFuture<Map<Integer, Integer>> future = job.
mapper(new FeatureMapper(HEXMAP)).
reducer(new FeatureReducerFactory()).
submit();
final FileOutputStream fileOutputStream = new FileOutputStream(filename);
try
{
final PrintStream printStream = new PrintStream(fileOutputStream);
printStream.format("ID,POPULATION%n");
final Map<Integer, Integer> result = future.get();
for (final Map.Entry<Integer, Integer> entry : result.entrySet())
{
printStream.format("%d,%d%n", entry.getKey(), entry.getValue());
}
printStream.flush();
}
finally
{
fileOutputStream.close();
}
}
开发者ID:mraad,项目名称:HZSpatial,代码行数:30,代码来源:Main.java
示例13: mapReduce
import com.hazelcast.mapreduce.KeyValueSource; //导入依赖的package包/类
@TimeStep(prob = 0.5)
public void mapReduce(ThreadState state) throws Exception {
JobTracker tracker = targetInstance.getJobTracker(Thread.currentThread().getName() + name);
KeyValueSource<Integer, Employee> source = KeyValueSource.fromMap(map);
Job<Integer, Employee> job = tracker.newJob(source);
ICompletableFuture<Map<Integer, Set<Employee>>> future = job
.mapper(new ModIdMapper(2))
.combiner(new RangeIdCombinerFactory(10, 30))
.reducer(new IdReducerFactory(10, 20, 30))
.submit();
Map<Integer, Set<Employee>> result = future.get();
for (Set<Employee> set : result.values()) {
for (Employee employee : set) {
assertTrue(employee.getId() % 2 == 0);
assertTrue(employee.getId() >= 10 && employee.getId() <= 30);
assertTrue(employee.getId() != 10);
assertTrue(employee.getId() != 20);
assertTrue(employee.getId() != 30);
}
}
state.operationCounter.mapReduce++;
}
开发者ID:hazelcast,项目名称:hazelcast-simulator,代码行数:28,代码来源:MapReduceTest.java
示例14: main
import com.hazelcast.mapreduce.KeyValueSource; //导入依赖的package包/类
public static void main(String[] args)
throws Exception {
// Prepare Hazelcast cluster
HazelcastInstance hazelcastInstance = buildCluster(3);
try {
// Read data
fillMapWithData(hazelcastInstance);
JobTracker tracker = hazelcastInstance.getJobTracker(TRACKER_NAME);
IMap<String, String> map = hazelcastInstance.getMap(MAP_NAME);
KeyValueSource<String, String> source = KeyValueSource.fromMap(map);
Job<String, String> job = tracker.newJob(source);
final JobCompletableFuture<List<Map.Entry<String, Integer>>> future = job
.mapper(new TokenizerMapper())
// Activate Combiner to add combining phase!
// .combiner(new WordcountCombinerFactory())
.reducer(new WordcountReducerFactory())
// .submit();
// add collator for sorting and top10
.submit(new WordcountCollator());
future.andThen(new ExecutionCallback<List<Map.Entry<String, Integer>>>() {
@Override public void onResponse(List<Map.Entry<String, Integer>> response) {
System.out.println(ToStringPrettyfier.toString(response));
}
@Override public void onFailure(Throwable t) {
}
});
//System.out.println(ToStringPrettyfier.toString(future.get()));
} finally {
// Shutdown cluster
//Hazelcast.shutdownAll();
}
}
开发者ID:gAmUssA,项目名称:jpoint-2016-computing-talk,代码行数:45,代码来源:WordCountExample.java
示例15: execute
import com.hazelcast.mapreduce.KeyValueSource; //导入依赖的package包/类
@Override
public void execute(HazelcastInstance hazelcastInstance)
throws Exception {
JobTracker jobTracker = hazelcastInstance.getJobTracker("default");
IList<Person> list = hazelcastInstance.getList("persons");
KeyValueSource<String, Person> source = KeyValueSource.fromList(list);
Job<String, Person> job = jobTracker.newJob(source);
// Find all people named James
ICompletableFuture future = job.mapper(new PersonMapper("James")).submit();
System.out.println(ToStringPrettyfier.toString(future.get()));
}
开发者ID:noctarius,项目名称:hazelcast-mapreduce-presentation,代码行数:17,代码来源:Tutorial1.java
示例16: execute
import com.hazelcast.mapreduce.KeyValueSource; //导入依赖的package包/类
@Override
public void execute(HazelcastInstance hazelcastInstance)
throws Exception {
JobTracker jobTracker = hazelcastInstance.getJobTracker("default");
IList<Person> list = hazelcastInstance.getList("persons");
KeyValueSource<String, Person> source = KeyValueSource.fromList(list);
Job<String, Person> job = jobTracker.newJob(source);
// Find all people grouped by state
// ICompletableFuture future = job.mapper(new StateBasedMapper()).submit();
// Find all people for the given state
ICompletableFuture future = job.mapper(new StateBasedMapper("CA")).submit();
System.out.println(ToStringPrettyfier.toString(future.get()));
}
开发者ID:noctarius,项目名称:hazelcast-mapreduce-presentation,代码行数:20,代码来源:Tutorial2.java
示例17: testMR
import com.hazelcast.mapreduce.KeyValueSource; //导入依赖的package包/类
@Test
public void testMR() throws IOException, ExecutionException, InterruptedException
{
final Config config = new ClasspathXmlConfig("hazelcast.xml");
final HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
try
{
final IMap<Integer, SpatialPolygon> hexmap = instance.getMap("hexmap");
final SpatialPolygon spatialPolygon = new SpatialPolygon();
spatialPolygon.id = 0;
spatialPolygon.polygon.startPath(0, 0);
spatialPolygon.polygon.lineTo(10, 0);
spatialPolygon.polygon.lineTo(10, 10);
spatialPolygon.polygon.lineTo(0, 10);
spatialPolygon.polygon.lineTo(0, 0);
spatialPolygon.polygon.closeAllPaths();
spatialPolygon.polygon.queryEnvelope2D(spatialPolygon.envelope2D);
hexmap.put(spatialPolygon.id, spatialPolygon);
final IMap<Integer, SpatialPoint> geomap = instance.getMap("geomap");
final SpatialPoint spatialPoint = new SpatialPoint();
spatialPoint.id = 0;
spatialPoint.point.setXY(5, 5);
spatialPoint.point.queryEnvelope2D(spatialPoint.envelope2D);
geomap.put(spatialPoint.id, spatialPoint);
final JobTracker tracker = instance.getJobTracker("default");
final Job<Integer, SpatialPoint> job = tracker.newJob(KeyValueSource.fromMap(geomap));
final ICompletableFuture<Map<Integer, Integer>> future = job.
mapper(new FeatureMapper("hexmap")).
reducer(new FeatureReducerFactory()).
submit();
final Map<Integer, Integer> result = future.get();
Assert.assertEquals(1, result.size());
final Map.Entry<Integer, Integer> next = result.entrySet().iterator().next();
Assert.assertEquals(0, next.getKey().intValue());
Assert.assertEquals(1, next.getValue().intValue());
}
finally
{
instance.shutdown();
}
}
开发者ID:mraad,项目名称:HZSpatial,代码行数:47,代码来源:MRTest.java
注:本文中的com.hazelcast.mapreduce.KeyValueSource类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论