use of org.apache.ignite.internal.sql.optimizer.affinity.PartitionResult in project ignite by apache.
the class JdbcThinConnection method updateAffinityCache.
/**
* Recreates affinity cache if affinity topology version was changed and adds partition result to sql cache.
*
* @param qryReq Query request.
* @param res Jdbc Response.
*/
private void updateAffinityCache(JdbcQueryExecuteRequest qryReq, JdbcResponse res) {
if (partitionAwareness) {
AffinityTopologyVersion resAffVer = res.affinityVersion();
if (resAffVer != null && (affinityCache == null || affinityCache.version().compareTo(resAffVer) < 0)) {
affinityCache = new AffinityCache(resAffVer, connProps.getPartitionAwarenessPartitionDistributionsCacheSize(), connProps.getPartitionAwarenessSqlCacheSize());
}
// Partition result was requested.
if (res.response() instanceof JdbcQueryExecuteResult && qryReq.partitionResponseRequest()) {
PartitionResult partRes = ((JdbcQueryExecuteResult) res.response()).partitionResult();
if (partRes == null || affinityCache.version().equals(partRes.topologyVersion())) {
int cacheId = (partRes != null && partRes.tree() != null) ? GridCacheUtils.cacheId(partRes.cacheName()) : -1;
PartitionClientContext partClientCtx = partRes != null ? new PartitionClientContext(partRes.partitionsCount()) : null;
QualifiedSQLQuery qry = new QualifiedSQLQuery(qryReq.schemaName(), qryReq.sqlQuery());
JdbcThinPartitionResultDescriptor partResDescr = new JdbcThinPartitionResultDescriptor(partRes, cacheId, partClientCtx);
affinityCache.addSqlQuery(qry, partResDescr);
}
}
}
}
use of org.apache.ignite.internal.sql.optimizer.affinity.PartitionResult in project ignite by apache.
the class PartitionExtractor method extract.
/**
* Extract partitions.
*
* @param qry Query.
* @return Partitions.
*/
public PartitionResult extract(GridSqlQuery qry) throws IgniteCheckedException {
// No unions support yet.
if (!(qry instanceof GridSqlSelect))
return null;
GridSqlSelect select = (GridSqlSelect) qry;
// Prepare table model.
PartitionTableModel tblModel = prepareTableModel(select.from());
// Do extract.
PartitionNode tree = extractFromExpression(select.where(), tblModel, false);
assert tree != null;
// Reduce tree if possible.
tree = tree.optimize();
if (tree instanceof PartitionAllNode)
return null;
// Done.
return new PartitionResult(tree, tblModel.joinGroupAffinity(tree.joinGroup()), ctx.cache().context().exchange().readyAffinityVersion());
}
Aggregations