Search in sources :

Example 6 with FactTable

use of co.cask.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 tableName = cConf.get(Constants.Metrics.METRICS_TABLE_PREFIX, Constants.Metrics.DEFAULT_METRIC_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())));
    MetricsTable table = getOrCreateMetricsTable(tableName, props.build());
    return new FactTable(table, entityTable.get(), resolution, getRollTime(resolution));
}
Also used : FactTable(co.cask.cdap.data2.dataset2.lib.timeseries.FactTable) MetricsTable(co.cask.cdap.data2.dataset2.lib.table.MetricsTable) TableProperties(co.cask.cdap.api.dataset.table.TableProperties)

Example 7 with FactTable

use of co.cask.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 8 with FactTable

use of co.cask.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 9 with FactTable

use of co.cask.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)

Example 10 with FactTable

use of co.cask.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)

Aggregations

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 Test (org.junit.Test)5 ImmutableList (com.google.common.collect.ImmutableList)3 List (java.util.List)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 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 CubeFact (co.cask.cdap.api.dataset.lib.cube.CubeFact)1 TimeSeries (co.cask.cdap.api.dataset.lib.cube.TimeSeries)1 Row (co.cask.cdap.api.dataset.table.Row)1 Scanner (co.cask.cdap.api.dataset.table.Scanner)1 TableProperties (co.cask.cdap.api.dataset.table.TableProperties)1 MetricsTable (co.cask.cdap.data2.dataset2.lib.table.MetricsTable)1 EntityTable (co.cask.cdap.data2.dataset2.lib.timeseries.EntityTable)1 Fact (co.cask.cdap.data2.dataset2.lib.timeseries.Fact)1 FactScanner (co.cask.cdap.data2.dataset2.lib.timeseries.FactScanner)1