Class ComputePartitionQueryMapReduceExample

java.lang.Object
org.apache.ignite.example.compute.ComputePartitionQueryMapReduceExample

public class ComputePartitionQueryMapReduceExample extends Object
This example demonstrates a partition-aware Map/Reduce pattern using the IgniteCompute.executeMapReduce(org.apache.ignite.compute.TaskDescriptor<T, R>, T) API together with the __PARTITION_ID virtual SQL column.

In the split phase, ComputePartitionQueryMapReduceExample.PersonCountByPartitionTask enumerates all partitions of the Person table via PartitionDistribution and dispatches one job per partition to the node that currently holds the primary replica. Each ComputePartitionQueryMapReduceExample.PartitionPersonCountJob filters rows with __PARTITION_ID and returns the local count. In the reduce phase the counts are summed.

Note: PartitionDistribution.primaryReplicas() captures partition locations at a point in time. If a partition is reassigned between the split and job execution, a job may run on a non-primary node, making the SQL query non-local. For guaranteed local execution use BroadcastJobTarget.table(java.lang.String) instead — see ComputeBroadcastExample for that approach.

See README.md in the examples directory for execution instructions.

  • Constructor Details

    • ComputePartitionQueryMapReduceExample

      public ComputePartitionQueryMapReduceExample()
  • Method Details

    • main

      public static void main(String[] args) throws Exception
      Main method of the example.
      Parameters:
      args - The command line arguments.
      Throws:
      Exception - if any error occurs.