Search in sources :

Example 1 with StatisticsKey

use of org.apache.ignite.internal.processors.query.stat.StatisticsKey in project ignite by apache.

the class ColumnLocalDataViewSupplier method columnLocalStatisticsViewSupplier.

/**
 * Statistics column local node data view filterable supplier.
 *
 * @param filter Filter.
 * @return Iterable with statistics column local node data views.
 */
public Iterable<StatisticsColumnLocalDataView> columnLocalStatisticsViewSupplier(Map<String, Object> filter) {
    String type = (String) filter.get(StatisticsColumnPartitionDataViewWalker.TYPE_FILTER);
    if (type != null && !StatisticsColumnConfigurationView.TABLE_TYPE.equalsIgnoreCase(type))
        return Collections.emptyList();
    String schema = (String) filter.get(StatisticsColumnLocalDataViewWalker.SCHEMA_FILTER);
    String name = (String) filter.get(StatisticsColumnLocalDataViewWalker.NAME_FILTER);
    String column = (String) filter.get(StatisticsColumnPartitionDataViewWalker.COLUMN_FILTER);
    Map<StatisticsKey, ObjectStatisticsImpl> locStatsMap;
    if (!F.isEmpty(schema) && !F.isEmpty(name)) {
        StatisticsKey key = new StatisticsKey(schema, name);
        ObjectStatisticsImpl objLocStat = repo.getLocalStatistics(key);
        if (objLocStat == null)
            return Collections.emptyList();
        locStatsMap = Collections.singletonMap(key, objLocStat);
    } else
        locStatsMap = repo.localStatisticsMap().entrySet().stream().filter(e -> F.isEmpty(schema) || schema.equals(e.getKey().schema())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    List<StatisticsColumnLocalDataView> res = new ArrayList<>();
    for (Map.Entry<StatisticsKey, ObjectStatisticsImpl> localStatsEntry : locStatsMap.entrySet()) {
        StatisticsKey key = localStatsEntry.getKey();
        ObjectStatisticsImpl stat = localStatsEntry.getValue();
        if (column == null) {
            for (Map.Entry<String, ColumnStatistics> colStat : localStatsEntry.getValue().columnsStatistics().entrySet()) {
                StatisticsColumnLocalDataView colStatView = new StatisticsColumnLocalDataView(key, colStat.getKey(), stat);
                res.add(colStatView);
            }
        } else {
            ColumnStatistics colStat = localStatsEntry.getValue().columnStatistics(column);
            if (colStat != null) {
                StatisticsColumnLocalDataView colStatView = new StatisticsColumnLocalDataView(key, column, stat);
                res.add(colStatView);
            }
        }
    }
    return res;
}
Also used : StatisticsColumnLocalDataViewWalker(org.apache.ignite.internal.managers.systemview.walker.StatisticsColumnLocalDataViewWalker) F(org.apache.ignite.internal.util.typedef.F) List(java.util.List) ObjectStatisticsImpl(org.apache.ignite.internal.processors.query.stat.ObjectStatisticsImpl) Map(java.util.Map) IgniteStatisticsRepository(org.apache.ignite.internal.processors.query.stat.IgniteStatisticsRepository) StatisticsColumnPartitionDataViewWalker(org.apache.ignite.internal.managers.systemview.walker.StatisticsColumnPartitionDataViewWalker) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ColumnStatistics(org.apache.ignite.internal.processors.query.stat.ColumnStatistics) StatisticsKey(org.apache.ignite.internal.processors.query.stat.StatisticsKey) ColumnStatistics(org.apache.ignite.internal.processors.query.stat.ColumnStatistics) StatisticsKey(org.apache.ignite.internal.processors.query.stat.StatisticsKey) ArrayList(java.util.ArrayList) ObjectStatisticsImpl(org.apache.ignite.internal.processors.query.stat.ObjectStatisticsImpl) Map(java.util.Map)

Example 2 with StatisticsKey

use of org.apache.ignite.internal.processors.query.stat.StatisticsKey in project ignite by apache.

the class ColumnConfigurationViewSupplier method columnConfigurationViewSupplier.

/**
 * Statistics column configuration view filterable supplier.
 *
 * @param filter Filter.
 * @return Iterable with selected statistics column configuration views.
 */
public Iterable<StatisticsColumnConfigurationView> columnConfigurationViewSupplier(Map<String, Object> filter) {
    String schema = (String) filter.get(StatisticsColumnConfigurationViewWalker.SCHEMA_FILTER);
    String name = (String) filter.get(StatisticsColumnConfigurationViewWalker.NAME_FILTER);
    Collection<StatisticsObjectConfiguration> configs;
    try {
        if (!F.isEmpty(schema) && !F.isEmpty(name)) {
            StatisticsKey key = new StatisticsKey(schema, name);
            StatisticsObjectConfiguration keyCfg = cfgMgr.config(key);
            if (keyCfg == null)
                return Collections.emptyList();
            configs = Collections.singletonList(keyCfg);
        } else
            configs = cfgMgr.getAllConfig();
    } catch (IgniteCheckedException e) {
        log.warning("Error while getting statistics configuration: " + e.getMessage(), e);
        configs = Collections.emptyList();
    }
    List<StatisticsColumnConfigurationView> res = new ArrayList<>();
    for (StatisticsObjectConfiguration cfg : configs) {
        for (StatisticsColumnConfiguration colCfg : cfg.columnsAll().values()) {
            if (!colCfg.tombstone())
                res.add(new StatisticsColumnConfigurationView(cfg, colCfg));
        }
    }
    return res;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) StatisticsKey(org.apache.ignite.internal.processors.query.stat.StatisticsKey) ArrayList(java.util.ArrayList) StatisticsColumnConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration)

Example 3 with StatisticsKey

use of org.apache.ignite.internal.processors.query.stat.StatisticsKey in project ignite by apache.

the class CommandProcessor method processAnalyzeCommand.

/**
 * Process analyze command.
 *
 * @param cmd Sql analyze command.
 */
private void processAnalyzeCommand(SqlAnalyzeCommand cmd) throws IgniteCheckedException {
    ctx.security().authorize(SecurityPermission.CHANGE_STATISTICS);
    IgniteH2Indexing indexing = (IgniteH2Indexing) ctx.query().getIndexing();
    StatisticsObjectConfiguration[] objCfgs = cmd.configurations().stream().map(t -> {
        if (t.key().schema() == null) {
            StatisticsKey key = new StatisticsKey(cmd.schemaName(), t.key().obj());
            return new StatisticsObjectConfiguration(key, t.columns().values(), t.maxPartitionObsolescencePercent());
        } else
            return t;
    }).toArray(StatisticsObjectConfiguration[]::new);
    indexing.statsManager().collectStatistics(objCfgs);
}
Also used : GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) QueryUtils(org.apache.ignite.internal.processors.query.QueryUtils) GridQueryKillResponse(org.apache.ignite.internal.processors.query.messages.GridQueryKillResponse) SqlCreateUserCommand(org.apache.ignite.internal.sql.command.SqlCreateUserCommand) MvccUtils.txStart(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.txStart) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) Map(java.util.Map) NoOperation(org.h2.command.dml.NoOperation) SqlSetStreamingCommand(org.apache.ignite.internal.sql.command.SqlSetStreamingCommand) GridIoPolicy(org.apache.ignite.internal.managers.communication.GridIoPolicy) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) SqlCreateIndexCommand(org.apache.ignite.internal.sql.command.SqlCreateIndexCommand) GridQueryTypeDescriptor(org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor) QueryField(org.apache.ignite.internal.processors.query.QueryField) CIX2(org.apache.ignite.internal.util.typedef.CIX2) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Event(org.apache.ignite.events.Event) Set(java.util.Set) QueryEntityEx(org.apache.ignite.internal.processors.query.QueryEntityEx) AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn) SqlAnalyzeCommand(org.apache.ignite.internal.sql.command.SqlAnalyzeCommand) DataType(org.h2.value.DataType) SqlRefreshStatitsicsCommand(org.apache.ignite.internal.sql.command.SqlRefreshStatitsicsCommand) PARAM_WRAP_VALUE(org.apache.ignite.internal.processors.query.h2.sql.GridSqlQueryParser.PARAM_WRAP_VALUE) Message(org.apache.ignite.plugin.extensions.communication.Message) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) BulkLoadStreamerWriter(org.apache.ignite.internal.processors.bulkload.BulkLoadStreamerWriter) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteLogger(org.apache.ignite.IgniteLogger) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) SecurityPermission(org.apache.ignite.plugin.security.SecurityPermission) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) LinkedHashMap(java.util.LinkedHashMap) Column(org.h2.table.Column) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridSqlAlterTableAddColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlAlterTableAddColumn) SqlBeginTransactionCommand(org.apache.ignite.internal.sql.command.SqlBeginTransactionCommand) SqlIndexColumn(org.apache.ignite.internal.sql.command.SqlIndexColumn) MvccUtils(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils) SqlKillQueryCommand(org.apache.ignite.internal.sql.command.SqlKillQueryCommand) NestedTxMode(org.apache.ignite.internal.processors.query.NestedTxMode) SqlDropUserCommand(org.apache.ignite.internal.sql.command.SqlDropUserCommand) Value(org.h2.value.Value) ServiceMXBeanImpl(org.apache.ignite.internal.ServiceMXBeanImpl) GridQueryProperty(org.apache.ignite.internal.processors.query.GridQueryProperty) GridSqlCreateIndex(org.apache.ignite.internal.processors.query.h2.sql.GridSqlCreateIndex) GridSqlAlterTableDropColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlAlterTableDropColumn) BulkLoadParser(org.apache.ignite.internal.processors.bulkload.BulkLoadParser) SqlBulkLoadCommand(org.apache.ignite.internal.sql.command.SqlBulkLoadCommand) GridRunningQueryInfo(org.apache.ignite.internal.processors.query.GridRunningQueryInfo) DropIndex(org.h2.command.ddl.DropIndex) GridSqlDropTable(org.apache.ignite.internal.processors.query.h2.sql.GridSqlDropTable) AtomicLong(java.util.concurrent.atomic.AtomicLong) GridTopic(org.apache.ignite.internal.GridTopic) SqlClientContext(org.apache.ignite.internal.processors.query.SqlClientContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) TransactionsMXBeanImpl(org.apache.ignite.internal.TransactionsMXBeanImpl) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) CacheMode(org.apache.ignite.cache.CacheMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) SqlRollbackTransactionCommand(org.apache.ignite.internal.sql.command.SqlRollbackTransactionCommand) SqlAlterUserCommand(org.apache.ignite.internal.sql.command.SqlAlterUserCommand) DmlBulkLoadDataConverter(org.apache.ignite.internal.processors.query.h2.dml.DmlBulkLoadDataConverter) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) SqlAlterTableCommand(org.apache.ignite.internal.sql.command.SqlAlterTableCommand) IgniteCluster(org.apache.ignite.IgniteCluster) StatisticsTarget(org.apache.ignite.internal.processors.query.stat.StatisticsTarget) CreateTable(org.h2.command.ddl.CreateTable) QueryEntity(org.apache.ignite.cache.QueryEntity) UpdatePlan(org.apache.ignite.internal.processors.query.h2.dml.UpdatePlan) SqlCommand(org.apache.ignite.internal.sql.command.SqlCommand) EventType(org.apache.ignite.events.EventType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GridSqlStatement(org.apache.ignite.internal.processors.query.h2.sql.GridSqlStatement) UUID(java.util.UUID) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) Objects(java.util.Objects) SqlKillContinuousQueryCommand(org.apache.ignite.internal.sql.command.SqlKillContinuousQueryCommand) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SqlKillScanQueryCommand(org.apache.ignite.internal.sql.command.SqlKillScanQueryCommand) BulkLoadAckClientParameters(org.apache.ignite.internal.processors.bulkload.BulkLoadAckClientParameters) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) NotNull(org.jetbrains.annotations.NotNull) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) GridSqlColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlColumn) GridQueryKillRequest(org.apache.ignite.internal.processors.query.messages.GridQueryKillRequest) UpdatePlanBuilder(org.apache.ignite.internal.processors.query.h2.dml.UpdatePlanBuilder) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) QueryMXBeanImpl(org.apache.ignite.internal.QueryMXBeanImpl) SqlCommitTransactionCommand(org.apache.ignite.internal.sql.command.SqlCommitTransactionCommand) MvccUtils.tx(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.tx) HashMap(java.util.HashMap) GridSqlCreateTable(org.apache.ignite.internal.processors.query.h2.sql.GridSqlCreateTable) SqlKillServiceCommand(org.apache.ignite.internal.sql.command.SqlKillServiceCommand) IgniteClosureX(org.apache.ignite.internal.util.lang.IgniteClosureX) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) BulkLoadCacheWriter(org.apache.ignite.internal.processors.bulkload.BulkLoadCacheWriter) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration) BulkLoadContextCursor(org.apache.ignite.cache.query.BulkLoadContextCursor) StatisticsKey(org.apache.ignite.internal.processors.query.stat.StatisticsKey) QueryIndexType(org.apache.ignite.cache.QueryIndexType) F(org.apache.ignite.internal.util.typedef.F) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) Iterator(java.util.Iterator) SqlKillComputeTaskCommand(org.apache.ignite.internal.sql.command.SqlKillComputeTaskCommand) GridSqlDropIndex(org.apache.ignite.internal.processors.query.h2.sql.GridSqlDropIndex) SqlDropStatisticsCommand(org.apache.ignite.internal.sql.command.SqlDropStatisticsCommand) SqlKillTransactionCommand(org.apache.ignite.internal.sql.command.SqlKillTransactionCommand) MvccUtils.mvccEnabled(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.mvccEnabled) IgniteQueryErrorCode(org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode) SqlDropIndexCommand(org.apache.ignite.internal.sql.command.SqlDropIndexCommand) Prepared(org.h2.command.Prepared) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) BulkLoadProcessor(org.apache.ignite.internal.processors.bulkload.BulkLoadProcessor) CreateIndex(org.h2.command.ddl.CreateIndex) ComputeMXBeanImpl(org.apache.ignite.internal.ComputeMXBeanImpl) Collections(java.util.Collections) QueryIndex(org.apache.ignite.cache.QueryIndex) DropTable(org.h2.command.ddl.DropTable) GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) StatisticsKey(org.apache.ignite.internal.processors.query.stat.StatisticsKey) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration)

Example 4 with StatisticsKey

use of org.apache.ignite.internal.processors.query.stat.StatisticsKey in project ignite by apache.

the class GridH2Table method tableStatistics.

/**
 * Get actual table statistics if exists.
 *
 * @return Table statistics or {@code null} if there is no statistics available.
 */
public ObjectStatistics tableStatistics() {
    GridCacheContext cacheContext = cacheInfo.cacheContext();
    if (cacheContext == null)
        return null;
    IgniteH2Indexing indexing = (IgniteH2Indexing) cacheContext.kernalContext().query().getIndexing();
    return indexing.statsManager().getLocalStatistics(new StatisticsKey(identifier.schema(), identifier.table()));
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) StatisticsKey(org.apache.ignite.internal.processors.query.stat.StatisticsKey) IgniteH2Indexing(org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing)

Example 5 with StatisticsKey

use of org.apache.ignite.internal.processors.query.stat.StatisticsKey in project ignite by apache.

the class ColumnPartitionDataViewSupplier method columnPartitionStatisticsViewSupplier.

/**
 * Statistics column partition data view filterable supplier.
 *
 * @param filter Filter.
 * @return Iterable with statistics column partition data views.
 */
public Iterable<StatisticsColumnPartitionDataView> columnPartitionStatisticsViewSupplier(Map<String, Object> filter) {
    String type = (String) filter.get(StatisticsColumnPartitionDataViewWalker.TYPE_FILTER);
    if (type != null && !StatisticsColumnConfigurationView.TABLE_TYPE.equalsIgnoreCase(type))
        return Collections.emptyList();
    String schema = (String) filter.get(StatisticsColumnPartitionDataViewWalker.SCHEMA_FILTER);
    String name = (String) filter.get(StatisticsColumnPartitionDataViewWalker.NAME_FILTER);
    Integer partId = (Integer) filter.get(StatisticsColumnPartitionDataViewWalker.PARTITION_FILTER);
    String column = (String) filter.get(StatisticsColumnPartitionDataViewWalker.COLUMN_FILTER);
    Map<StatisticsKey, Collection<ObjectPartitionStatisticsImpl>> partsStatsMap;
    if (!F.isEmpty(schema) && !F.isEmpty(name)) {
        StatisticsKey key = new StatisticsKey(schema, name);
        Collection<ObjectPartitionStatisticsImpl> keyStat;
        if (partId == null)
            keyStat = store.getLocalPartitionsStatistics(key);
        else {
            ObjectPartitionStatisticsImpl partStat = store.getLocalPartitionStatistics(key, partId);
            keyStat = (partStat == null) ? Collections.emptyList() : Collections.singletonList(partStat);
        }
        partsStatsMap = Collections.singletonMap(key, keyStat);
    } else
        partsStatsMap = store.getAllLocalPartitionsStatistics(schema);
    List<StatisticsColumnPartitionDataView> res = new ArrayList<>();
    for (Map.Entry<StatisticsKey, Collection<ObjectPartitionStatisticsImpl>> partsStatsEntry : partsStatsMap.entrySet()) {
        StatisticsKey key = partsStatsEntry.getKey();
        for (ObjectPartitionStatisticsImpl partStat : partsStatsEntry.getValue()) {
            if (column == null) {
                for (Map.Entry<String, ColumnStatistics> colStatEntry : partStat.columnsStatistics().entrySet()) res.add(new StatisticsColumnPartitionDataView(key, colStatEntry.getKey(), partStat));
            } else {
                ColumnStatistics colStat = partStat.columnStatistics(column);
                if (colStat != null)
                    res.add(new StatisticsColumnPartitionDataView(key, column, partStat));
            }
        }
    }
    return res;
}
Also used : ColumnStatistics(org.apache.ignite.internal.processors.query.stat.ColumnStatistics) ArrayList(java.util.ArrayList) ObjectPartitionStatisticsImpl(org.apache.ignite.internal.processors.query.stat.ObjectPartitionStatisticsImpl) StatisticsKey(org.apache.ignite.internal.processors.query.stat.StatisticsKey) Collection(java.util.Collection) Map(java.util.Map)

Aggregations

StatisticsKey (org.apache.ignite.internal.processors.query.stat.StatisticsKey)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)3 Collections (java.util.Collections)2 List (java.util.List)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 StatisticsObjectConfiguration (org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration)2 F (org.apache.ignite.internal.util.typedef.F)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Objects (java.util.Objects)1 Set (java.util.Set)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1