Search in sources :

Example 1 with GridSqlAst

use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlAst in project ignite by apache.

the class DmlAstUtils method findParams.

/**
 * @param qry Select.
 * @param params Parameters.
 * @param target Extracted parameters.
 * @param paramIdxs Parameter indexes.
 * @return Extracted parameters list.
 */
private static List<Object> findParams(GridSqlSelect qry, Object[] params, ArrayList<Object> target, IntArray paramIdxs) {
    if (params.length == 0)
        return target;
    for (GridSqlAst el : qry.columns(false)) findParams((GridSqlElement) el, params, target, paramIdxs);
    findParams((GridSqlElement) qry.from(), params, target, paramIdxs);
    findParams((GridSqlElement) qry.where(), params, target, paramIdxs);
    // Don't search in GROUP BY and HAVING since they expected to be in select list.
    findParams((GridSqlElement) qry.limit(), params, target, paramIdxs);
    findParams((GridSqlElement) qry.offset(), params, target, paramIdxs);
    return target;
}
Also used : GridSqlAst(org.apache.ignite.internal.processors.query.h2.sql.GridSqlAst) GridSqlElement(org.apache.ignite.internal.processors.query.h2.sql.GridSqlElement)

Example 2 with GridSqlAst

use of org.apache.ignite.internal.processors.query.h2.sql.GridSqlAst in project ignite by apache.

the class GridSqlQueryParser method isLocalQuery.

/**
 * Check if query may be run locally on all caches mentioned in the query.
 * @param replicatedOnlyQry replicated-only query flag from original {@link SqlFieldsQuery}.
 * @return {@code true} if query may be run locally on all caches mentioned in the query, i.e. there's no need
 *     to run distributed query.
 * @see SqlFieldsQuery#isReplicatedOnly()
 */
public boolean isLocalQuery(boolean replicatedOnlyQry) {
    boolean hasCaches = false;
    for (Object o : h2ObjToGridObj.values()) {
        if (o instanceof GridSqlAlias)
            o = GridSqlAlias.unwrap((GridSqlAst) o);
        if (o instanceof GridSqlTable) {
            GridH2Table tbl = ((GridSqlTable) o).dataTable();
            if (tbl != null) {
                hasCaches = true;
                GridCacheContext cctx = tbl.cache();
                if (!cctx.isLocal() && !(replicatedOnlyQry && cctx.isReplicatedAffinityNode()))
                    return false;
            }
        }
    }
    // if there are no caches, original SqlFieldsQuery's isLocal flag will be used.
    return hasCaches;
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)

Aggregations

GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)1 GridSqlAst (org.apache.ignite.internal.processors.query.h2.sql.GridSqlAst)1 GridSqlElement (org.apache.ignite.internal.processors.query.h2.sql.GridSqlElement)1