This is an automated email from the ASF dual-hosted git repository.

dspavlov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new b5892a6e377 IGNITE-28641 Restore outcommented docs section: Ignite 
compute and setLocal for query (#13114)
b5892a6e377 is described below

commit b5892a6e377ca97a32d6ddb953f492726478eeab
Author: ignitetcbot <[email protected]>
AuthorDate: Thu May 14 22:13:29 2026 +0300

    IGNITE-28641 Restore outcommented docs section: Ignite compute and setLocal 
for query (#13114)
    
    Codex co-authored-by: Dmitriy Pavlov <[email protected]>
---
 .../ignite/snippets/DistributedComputing.java      | 52 +++++++++++++++++
 .../distributed-computing.adoc                     | 67 ++++++----------------
 2 files changed, 69 insertions(+), 50 deletions(-)

diff --git 
a/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/DistributedComputing.java
 
b/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/DistributedComputing.java
index 9fe272dd62b..0a8c2587950 100644
--- 
a/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/DistributedComputing.java
+++ 
b/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/DistributedComputing.java
@@ -22,11 +22,17 @@ import java.util.Collection;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.atomic.AtomicLong;
 
+import javax.cache.Cache;
+
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteCluster;
 import org.apache.ignite.IgniteCompute;
 import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.ScanQuery;
+import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.lang.IgniteCallable;
 import org.apache.ignite.lang.IgniteFuture;
 import org.apache.ignite.resources.IgniteInstanceResource;
@@ -194,4 +200,50 @@ public class DistributedComputing {
 
     // end::access-data[]
 
+    // tag::local-scan-query[]
+    public static class AverageAgeTask implements IgniteCallable<long[]> {
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        @Override
+        public long[] call() throws Exception {
+            IgniteCache<Long, Person> cache = ignite.cache("person");
+            Affinity<Long> affinity = ignite.affinity("person");
+            ClusterNode localNode = ignite.cluster().localNode();
+
+            long[] sumAndCount = new long[2];
+
+            try (QueryCursor<Cache.Entry<Long, Person>> cursor = cache
+                    .query(new ScanQuery<Long, Person>().setLocal(true))) {
+                for (Cache.Entry<Long, Person> entry : cursor) {
+                    if (affinity.isPrimary(localNode, entry.getKey())) {
+                        sumAndCount[0] += entry.getValue().getAge();
+                        sumAndCount[1]++;
+                    }
+                }
+            }
+
+            return sumAndCount;
+        }
+    }
+
+    void calculateAverageAge(Ignite ignite) {
+        Collection<long[]> results = 
ignite.compute(ignite.cluster().forDataNodes("person"))
+                .broadcast(new AverageAgeTask());
+
+        long totalAge = 0;
+        long totalCount = 0;
+
+        for (long[] result : results) {
+            totalAge += result[0];
+            totalCount += result[1];
+        }
+
+        double averageAge = totalCount == 0 ? 0 : (double) totalAge / 
totalCount;
+
+        System.out.println("Average age: " + averageAge);
+    }
+
+    // end::local-scan-query[]
+
 }
diff --git a/docs/_docs/distributed-computing/distributed-computing.adoc 
b/docs/_docs/distributed-computing/distributed-computing.adoc
index 04ff69ffb73..92a4b07ff34 100644
--- a/docs/_docs/distributed-computing/distributed-computing.adoc
+++ b/docs/_docs/distributed-computing/distributed-computing.adoc
@@ -305,60 +305,27 @@ If you want to use the key and value objects inside 
`IgniteCallable` and `Ignite
 ====
 
 
-////////////////////////////////////////////////////////////////////////////////
-
-
-
-In the cases where you do not need to colocate computations with data but 
simply want to process all data remotely, you can run local cache queries 
inside the `call()` method. Consider the following example.
-
-Let's say we have a cache that stores information about persons and we want to 
calculate the average age of all persons. One way to accomplish this is to run 
a link:key-value-api/using-cache-queries[scan query] that will fetch the ages 
of all persons to the local node, where you can calculate the average age.
-
-A more efficient way, however, is to avoid network calls to other nodes by 
running the query locally on each remote node and aggregating the result on the 
local node.
-
-This task can be easily split
-
-[source, java]
--------------------------------------------------------------------------------
-private class AverageAgeJob implements IgniteCallable<Double> {
-
-    @IgniteInstanceResource
-    private Ignite ignite;
-
-    @Override
-    public Double call() throws Exception {
-
-        IgniteCache<Long, Person> cache = ignite.cache("person");
-
-        int localAvg = 0;
-        try (QueryCursor<Cache.Entry<Long, Person>> cursor = cache
-                .query(new ScanQuery<Long, Person>().setLocal(true))) {
-            for (Cache.Entry<Long, Person> entry : cursor) {
-                localAvg += (int) entry.getValue().getAge();
-            }
-        }
-
-        return (localAvg / (double) cache.size());
-    }
-}
-
--------------------------------------------------------------------------------
-Note that the scan query is executed in the local mode. It means that it will 
only fetch objects from the Person cache that are stored localy and will not 
request data from other nodes.
+=== Processing Cache Data Locally
 
-If you broadcast this task to all nodes, all person objecs will be processed 
(each locally), and the results are sent to the node that initiated the task.
-
-[source, java]
--------------------------------------------------------------------------------
-Ignite ignite = Ignition.ignite();
-
-double average = ignite.compute().broadcast(new 
AverageAgeTask()).stream().reduce(0D, (a, b) -> a + b);
--------------------------------------------------------------------------------
-
-
-The task is executed on every node, where it will query all persons stored 
locally and calculate the local average. Then the result are sent to the node 
that initiated the task and summed up. In this implementation, objects are not 
transferred via network.
+If you need to process all cache data remotely, you can broadcast a task to 
the data nodes and run a local cache query inside the task.
+In this mode, each node scans only the cache entries stored locally, processes 
them there, and returns only the aggregated result to the caller.
 
+For example, assume that a cache stores `Person` objects and it is necessary 
to calculate the average age of all persons.
+A regular link:key-value-api/using-cache-queries[scan query] transfers 
matching entries to the query initiator page by page.
+The following example avoids transferring the full dataset over the network: 
the task is broadcast to the nodes that store data for the `person` cache, and 
each node runs `ScanQuery.setLocal(true)`.
+The task checks primary ownership so backup copies are not counted twice.
 
+[tabs]
+--
+tab:Java[]
+[source,java]
+----
+include::{javaFile}[tag=local-scan-query,indent=0]
+----
+tab:C#/.NET[unsupported]
 
-////////////////////////////////////////////////////////////////////////////////
+tab:C++[unsupported]
+--
 
 
 
////////////////////////////////////////////////////////////////////////////////

Reply via email to