Search in sources :

Example 11 with StatisticsObjectConfiguration

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

the class StatisticsAbstractTest method makeStatistics.

/**
 * Collect or refresh statistics.
 *
 * @param collect If {@code true} - collect new statistics, if {@code false} - update existing.
 * @param targets
 */
private void makeStatistics(boolean collect, StatisticsTarget... targets) {
    try {
        Map<StatisticsTarget, Long> expectedVersion = new HashMap<>();
        IgniteStatisticsManagerImpl statMgr = statisticsMgr(0);
        for (StatisticsTarget target : targets) {
            StatisticsObjectConfiguration currCfg = statMgr.statisticConfiguration().config(target.key());
            Predicate<StatisticsColumnConfiguration> pred;
            if (F.isEmpty(target.columns()))
                pred = c -> true;
            else {
                Set<String> cols = Arrays.stream(target.columns()).collect(Collectors.toSet());
                pred = c -> cols.contains(c.name());
            }
            Long expVer = (currCfg == null) ? 1L : currCfg.columnsAll().values().stream().filter(pred).mapToLong(StatisticsColumnConfiguration::version).min().orElse(0L) + 1;
            expectedVersion.put(target, expVer);
        }
        if (collect)
            statisticsMgr(0).collectStatistics(buildDefaultConfigurations(targets));
        else
            statisticsMgr(0).refreshStatistics(targets);
        awaitStatistics(TIMEOUT, expectedVersion);
    } catch (Exception ex) {
        throw new IgniteException(ex);
    }
}
Also used : Arrays(java.util.Arrays) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) IgniteEx(org.apache.ignite.internal.IgniteEx) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Matcher(java.util.regex.Matcher) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) IgniteH2Indexing(org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration) IgniteThreadPoolExecutor(org.apache.ignite.thread.IgniteThreadPoolExecutor) StatisticsColumnConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration) G(org.apache.ignite.internal.util.typedef.G) F(org.apache.ignite.internal.util.typedef.F) IgniteStatisticsHelper.buildDefaultConfigurations(org.apache.ignite.internal.processors.query.stat.IgniteStatisticsHelper.buildDefaultConfigurations) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Predicate(java.util.function.Predicate) IgniteException(org.apache.ignite.IgniteException) Set(java.util.Set) SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) Ignite(org.apache.ignite.Ignite) Collectors(java.util.stream.Collectors) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) List(java.util.List) Lock(java.util.concurrent.locks.Lock) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) HashMap(java.util.HashMap) StatisticsColumnConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration) IgniteException(org.apache.ignite.IgniteException) IgniteException(org.apache.ignite.IgniteException)

Example 12 with StatisticsObjectConfiguration

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

the class IgniteStatisticsHelper method buildDefaultConfigurations.

/**
 * Build object configurations array with all default parameters from specified targets.
 *
 * @param targets Targets to build configurations from.
 * @return StatisticsObjectConfiguration array.
 */
public static StatisticsObjectConfiguration[] buildDefaultConfigurations(StatisticsTarget... targets) {
    StatisticsObjectConfiguration[] res = Arrays.stream(targets).map(t -> {
        List<StatisticsColumnConfiguration> colCfgs;
        if (t.columns() == null)
            colCfgs = Collections.emptyList();
        else
            colCfgs = Arrays.stream(t.columns()).map(name -> new StatisticsColumnConfiguration(name, null)).collect(Collectors.toList());
        return new StatisticsObjectConfiguration(t.key(), colCfgs, StatisticsObjectConfiguration.DEFAULT_OBSOLESCENCE_MAX_PERCENT);
    }).toArray(StatisticsObjectConfiguration[]::new);
    return res;
}
Also used : SchemaManager(org.apache.ignite.internal.processors.query.h2.SchemaManager) F(org.apache.ignite.internal.util.typedef.F) Arrays(java.util.Arrays) QueryUtils(org.apache.ignite.internal.processors.query.QueryUtils) Collection(java.util.Collection) Set(java.util.Set) HashMap(java.util.HashMap) IgniteLogger(org.apache.ignite.IgniteLogger) UUID(java.util.UUID) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Column(org.h2.table.Column) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) StatisticsKeyMessage(org.apache.ignite.internal.processors.query.stat.messages.StatisticsKeyMessage) Map(java.util.Map) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration) StatisticsColumnConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration) Collections(java.util.Collections) ArrayList(java.util.ArrayList) List(java.util.List) StatisticsColumnConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration)

Aggregations

StatisticsObjectConfiguration (org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration)12 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 ArrayList (java.util.ArrayList)6 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)6 StatisticsColumnConfiguration (org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration)6 Collections (java.util.Collections)4 List (java.util.List)4 Set (java.util.Set)4 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)4 F (org.apache.ignite.internal.util.typedef.F)4 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Function (java.util.function.Function)3 Collectors (java.util.stream.Collectors)3 IgniteLogger (org.apache.ignite.IgniteLogger)3 QueryUtils (org.apache.ignite.internal.processors.query.QueryUtils)3 Collection (java.util.Collection)2 UUID (java.util.UUID)2