Search in sources :

Example 11 with FactTable

use of io.cdap.cdap.data2.dataset2.lib.timeseries.FactTable in project cdap by caskdata.

the class DefaultMetricDatasetFactory method getOrCreateFactTable.

// todo: figure out roll time based on resolution from config? See DefaultMetricsTableFactory for example
@Override
public FactTable getOrCreateFactTable(int resolution) {
    String v3TableName = cConf.get(Constants.Metrics.METRICS_TABLE_PREFIX, Constants.Metrics.DEFAULT_METRIC_V3_TABLE_PREFIX) + ".ts." + resolution;
    int ttl = cConf.getInt(Constants.Metrics.RETENTION_SECONDS + "." + resolution + ".seconds", -1);
    TableProperties.Builder props = TableProperties.builder();
    // don't add TTL for MAX_RESOLUTION table. CDAP-1626
    if (ttl > 0 && resolution != Integer.MAX_VALUE) {
        props.setTTL(ttl);
    }
    // for efficient counters
    props.setReadlessIncrementSupport(true);
    // configuring pre-splits
    props.add(HBaseTableAdmin.PROPERTY_SPLITS, GSON.toJson(FactTable.getSplits(DefaultMetricStore.AGGREGATIONS.size())));
    // Disable auto split
    props.add(HBaseTableAdmin.SPLIT_POLICY, cConf.get(Constants.Metrics.METRICS_TABLE_HBASE_SPLIT_POLICY));
    MetricsTable table = getOrCreateResolutionMetricsTable(v3TableName, props, resolution);
    return new FactTable(table, entityTable.get(), resolution, getRollTime(resolution));
}
Also used : FactTable(co.cask.cdap.data2.dataset2.lib.timeseries.FactTable) CombinedHBaseMetricsTable(co.cask.cdap.data2.dataset2.lib.table.hbase.CombinedHBaseMetricsTable) MetricsTable(co.cask.cdap.data2.dataset2.lib.table.MetricsTable) TableProperties(co.cask.cdap.api.dataset.table.TableProperties)

Example 12 with FactTable

use of io.cdap.cdap.data2.dataset2.lib.timeseries.FactTable in project cdap by caskdata.

the class DefaultCube method add.

@Override
public void add(Collection<? extends CubeFact> facts) {
    List<Fact> toWrite = Lists.newArrayList();
    int dimValuesCount = 0;
    for (CubeFact fact : facts) {
        for (Map.Entry<String, ? extends Aggregation> aggEntry : aggregations.entrySet()) {
            Aggregation agg = aggEntry.getValue();
            AggregationAlias aggregationAlias = null;
            if (aggregationAliasMap.containsKey(aggEntry.getKey())) {
                aggregationAlias = aggregationAliasMap.get(aggEntry.getKey());
            }
            if (agg.accept(fact)) {
                List<DimensionValue> dimensionValues = Lists.newArrayList();
                for (String dimensionName : agg.getDimensionNames()) {
                    String dimensionValueKey = aggregationAlias == null ? dimensionName : aggregationAlias.getAlias(dimensionName);
                    dimensionValues.add(new DimensionValue(dimensionName, fact.getDimensionValues().get(dimensionValueKey)));
                    dimValuesCount++;
                }
                toWrite.add(new Fact(fact.getTimestamp(), dimensionValues, fact.getMeasurements()));
            }
        }
    }
    for (FactTable table : resolutionToFactTable.values()) {
        table.add(toWrite);
    }
    incrementMetric("cube.cubeFact.add.request.count", 1);
    incrementMetric("cube.cubeFact.added.count", facts.size());
    incrementMetric("cube.tsFact.created.count", toWrite.size());
    incrementMetric("cube.tsFact.created.dimValues.count", dimValuesCount);
    incrementMetric("cube.tsFact.added.count", toWrite.size() * resolutionToFactTable.size());
}
Also used : CubeFact(co.cask.cdap.api.dataset.lib.cube.CubeFact) FactTable(co.cask.cdap.data2.dataset2.lib.timeseries.FactTable) DimensionValue(co.cask.cdap.api.dataset.lib.cube.DimensionValue) CubeFact(co.cask.cdap.api.dataset.lib.cube.CubeFact) Fact(co.cask.cdap.data2.dataset2.lib.timeseries.Fact) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 13 with FactTable

use of io.cdap.cdap.data2.dataset2.lib.timeseries.FactTable in project cdap by caskdata.

the class DefaultCube method findMeasureNames.

@Override
public Collection<String> findMeasureNames(CubeExploreQuery query) {
    LOG.trace("Searching for measures, query: {}", query);
    // In each aggregation that matches given dimensions, try to find measure names
    SortedSet<String> result = Sets.newTreeSet();
    // todo: the passed query should have map instead
    LinkedHashMap<String, String> slice = Maps.newLinkedHashMap();
    for (DimensionValue dimensionValue : query.getDimensionValues()) {
        slice.put(dimensionValue.getName(), dimensionValue.getValue());
    }
    FactTable table = resolutionToFactTable.get(query.getResolution());
    for (Aggregation agg : aggregations.values()) {
        if (agg.getDimensionNames().containsAll(slice.keySet())) {
            result.addAll(table.findMeasureNames(agg.getDimensionNames(), slice, query.getStartTs(), query.getEndTs()));
        }
    }
    return result;
}
Also used : FactTable(co.cask.cdap.data2.dataset2.lib.timeseries.FactTable) DimensionValue(co.cask.cdap.api.dataset.lib.cube.DimensionValue)

Example 14 with FactTable

use of io.cdap.cdap.data2.dataset2.lib.timeseries.FactTable in project cdap by caskdata.

the class DefaultCube method delete.

@Override
public void delete(CubeDeleteQuery query) {
    // this may be very inefficient and its better to use TTL, this is to only support existing old functionality.
    List<DimensionValue> dimensionValues = Lists.newArrayList();
    // use the dimension values of the aggregation to delete entries in all the fact-tables.
    for (Aggregation agg : aggregations.values()) {
        if (agg.getDimensionNames().containsAll(query.getDimensionValues().keySet())) {
            dimensionValues.clear();
            for (String dimensionName : agg.getDimensionNames()) {
                dimensionValues.add(new DimensionValue(dimensionName, query.getDimensionValues().get(dimensionName)));
            }
            FactTable factTable = resolutionToFactTable.get(query.getResolution());
            FactScan scan = new FactScan(query.getStartTs(), query.getEndTs(), query.getMeasureNames(), dimensionValues);
            factTable.delete(scan);
        }
    }
}
Also used : FactScan(co.cask.cdap.data2.dataset2.lib.timeseries.FactScan) FactTable(co.cask.cdap.data2.dataset2.lib.timeseries.FactTable) DimensionValue(co.cask.cdap.api.dataset.lib.cube.DimensionValue)

Example 15 with FactTable

use of io.cdap.cdap.data2.dataset2.lib.timeseries.FactTable in project cdap by caskdata.

the class DefaultCube method findDimensionValues.

@Override
public Collection<DimensionValue> findDimensionValues(CubeExploreQuery query) {
    LOG.trace("Searching for next-level context, query: {}", query);
    // In each aggregation that matches given dimensions, try to fill in value in a single null-valued given dimension.
    // NOTE: that we try to fill in first value that is non-null-valued in a stored record
    // (see FactTable#findSingleDimensionValue)
    SortedSet<DimensionValue> result = Sets.newTreeSet(DIMENSION_VALUE_COMPARATOR);
    // todo: the passed query should have map instead
    LinkedHashMap<String, String> slice = Maps.newLinkedHashMap();
    for (DimensionValue dimensionValue : query.getDimensionValues()) {
        slice.put(dimensionValue.getName(), dimensionValue.getValue());
    }
    FactTable table = resolutionToFactTable.get(query.getResolution());
    for (Aggregation agg : aggregations.values()) {
        if (agg.getDimensionNames().containsAll(slice.keySet())) {
            result.addAll(table.findSingleDimensionValue(agg.getDimensionNames(), slice, query.getStartTs(), query.getEndTs()));
        }
    }
    return result;
}
Also used : FactTable(co.cask.cdap.data2.dataset2.lib.timeseries.FactTable) DimensionValue(co.cask.cdap.api.dataset.lib.cube.DimensionValue)

Aggregations

Test (org.junit.Test)11 DimensionValue (io.cdap.cdap.api.dataset.lib.cube.DimensionValue)9 DimensionValue (co.cask.cdap.api.dataset.lib.cube.DimensionValue)8 FactTable (co.cask.cdap.data2.dataset2.lib.timeseries.FactTable)7 InMemoryMetricsTable (co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable)6 ImmutableList (com.google.common.collect.ImmutableList)6 InMemoryMetricsTable (io.cdap.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable)6 FactTable (io.cdap.cdap.data2.dataset2.lib.timeseries.FactTable)6 List (java.util.List)6 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 Measurement (io.cdap.cdap.api.dataset.lib.cube.Measurement)3 Measurement (co.cask.cdap.api.dataset.lib.cube.Measurement)2 TimeValue (co.cask.cdap.api.dataset.lib.cube.TimeValue)2 FactScan (co.cask.cdap.data2.dataset2.lib.timeseries.FactScan)2 TimeValue (io.cdap.cdap.api.dataset.lib.cube.TimeValue)2 FactScan (io.cdap.cdap.data2.dataset2.lib.timeseries.FactScan)2 HashMap (java.util.HashMap)2 CubeFact (co.cask.cdap.api.dataset.lib.cube.CubeFact)1