[ 
https://issues.apache.org/jira/browse/IGNITE-2177?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15075349#comment-15075349
 ] 

Andrey Kornev commented on IGNITE-2177:
---------------------------------------

Why does it have to be so tightly coupled to SQL and H2 in particular? What was 
wrong with GridCacheReduceQuery and GridCacheQuery API from in GridGain 4.1, 
for example? 

I'm not implying that the old API is perfect. I'm neither suggesting that the 
4.1's implementation was ok. I'm simply saying that the API did capture the 
essence of what needs to be able to do parallel processing of large data sets 
efficiently. If the proposed API allows me to do just that without losing any 
data due to concurrent partition migrations and without being stuck with H2 
indexing engine or SQL-related stuff, then I'm all for it. But first, I'd be 
nice to see some examples demoing the API.

Thanks
Andrey

Just a reminder from way-way back:

{code:title=GridCacheQuery.java|borderStyle=solid}
    /**
     * Visits every entry from query result on every queried node for as long as
     * the visitor predicate returns {@code true}. Once the predicate returns 
false
     * or all entries in query result have been visited, the visiting process 
stops.
     *
     * Note that if the passed in grid projection is a local node, then query
     * will be executed locally without distribution to other nodes.
     * 
     * Also note that query state cannot be changed (clause, timeout etc.), 
except
     * arguments, if this method was called at least once.
     *
     * @param vis Visitor predicate.
     * @param grid Optional subgrid projection to execute this query on
     *      (if not provided, then the whole grid is used).
     * @return Future which will complete whenever visiting on all remote nodes 
completes or fails.
     */
    public GridFuture<?> visit(GridPredicate<Map.Entry<K, V>> vis, 
GridProjection... grid);
{code}

Some more...
{code:title=GridCacheReduceQuery.java|borderStyle=solid}
/**
 * Cache query with possible remote and local reducers. The execution sequence 
is
 * essentially identical to the one described in {@link GridCacheQuery} javadoc,
 * except that queried key-value pairs are given to an optional reducer
 * directly on the queried node and a single reduced value is returned back
 * to caller node. Then on the caller node, the collection of reduced values
 * is given to optionally provided local reducer. Based on whether local
 * reducer is provided or not, either a single value or a collection of
 * reduced values is returned to user.
 * 
 * Reduce Query Usage
 *
 * Here is a query example which calculates average salary for all cached 
employees of
 * any given company based on the same example data mode described in {@link 
GridCacheQuery}
 * documentation.
 * GridCache<Long, Person> cache = G.grid().cache();
 *
 * // Calculate average of salary of all employees in some company.
 * GridCacheReduceQuery<UUID, Person, GridTuple2<Double, Integer>, Double> qry =
 *   cache.createReduceQuery(SQL, Person.class,
 *     "from Person, Organization where "+
 *             "Person.orgId = Organization.id and lower(Organization.name) = 
lower(?)");
 *
 * // Set remote reducer to calculate sum of salaries and employee count on 
remote nodes.
 * qry.remoteReducer(new CO<GridReducer<Map.Entry<Long, Person>, 
GridTuple2<Double, Integer>>>() {
 *     private GridReducer<Map.Entry<Long, Person>, GridTuple2<Double, 
Integer>> rdc =
 *         new GridReducer<Map.Entry<Long, Person>, GridTuple2<Double, 
Integer>>() {
 *             private double sum;
 *             private int cnt;
 *
 *             @Override public boolean collect(Map.Entry<Long, Person> e) {
 *                 sum += e.getValue().getSalary();
 *
 *                 cnt++;
 *
 *                 // Continue collecting.
 *                 return true;
 *             }
 *
 *             @Override public GridTuple2<Double, Integer> apply() {
 *                 return new GridTuple2<Double, Integer>(sum, cnt);
 *             }
 *         };
 *
 *         @Override public GridReducer<Map.Entry<Long, Person>, 
GridTuple2<Double, Integer>> apply() {
 *             return rdc;
 *         }
 *     });
 *
 * // Set local reducer to reduce totals from queried nodes into overall 
average.
 * qry.localReducer(new CO<GridReducer<GridTuple2<Double, Integer>, Double>>() {
 *     private GridReducer<GridTuple2<Double, Integer>, Double> rdc =
 *         new GridReducer<GridTuple2<Double, Integer>, Double>() {
 *             private double sum;
 *             private int cnt;
 *
 *             @Override public boolean collect(GridTuple2<Double, Integer> e) {
 *                 sum += e.get1();
 *                 cnt += e.get2();
 *
 *                 // Continue collecting.
 *                 return true;
 *             }
 *
 *             @Override public Double apply() {
 *                 return cnt == 0 ? 0 : sum / cnt;
 *             }
 *         };
 *
 *         @Override public GridReducer<GridTuple2<Double, Integer>, Double> 
apply() {
 *             return rdc;
 *         }
 *     });
 *
 * // Query all nodes to find average salary of all GridGain employees.
 * double averageGridGainSalary = qry.with("GridGain").reduce(grid).get())
 *
 * // Query all nodes to find average salary of all employees working for 
"Other" company.
 * double averageOtherSalary = qry.with("Other").reduce(grid).get())
 *
 * @param <K> Key type.
 * @param <V> Value type.
 * @param <R1> Remotely reduced type.
 * @param <R2> Locally reduced type.
 * @author @java.author
 * @version @java.version
 */
public interface GridCacheReduceQuery<K, V, R1, R2> extends 
GridCacheQueryBase<K, V> ...
{code}

> User defined aggregate functions for SQL
> ----------------------------------------
>
>                 Key: IGNITE-2177
>                 URL: https://issues.apache.org/jira/browse/IGNITE-2177
>             Project: Ignite
>          Issue Type: Wish
>            Reporter: Sergi Vladykin
>             Fix For: 1.6
>
>
> Need to design some factory like abstraction for creating map part and reduce 
> part of the aggregate. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to