Search in sources :

Example 16 with MetricsTable

use of co.cask.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.

the class CubeModule method register.

@Override
public void register(DatasetDefinitionRegistry registry) {
    DatasetDefinition<Table, ? extends DatasetAdmin> tableDef = registry.get("table");
    DatasetDefinition<MetricsTable, ? extends DatasetAdmin> metricsTableDef = registry.get(MetricsTable.class.getName());
    registry.add(new CubeDatasetDefinition(FULL_NAME, tableDef, metricsTableDef));
    registry.add(new CubeDatasetDefinition(SHORT_NAME, tableDef, metricsTableDef));
}
Also used : Table(co.cask.cdap.api.dataset.table.Table) CubeDatasetDefinition(co.cask.cdap.data2.dataset2.lib.cube.CubeDatasetDefinition)

Example 17 with MetricsTable

use of co.cask.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.

the class MetricsTableOnTableTest method getTable.

@Override
protected MetricsTable getTable(String name) throws Exception {
    DatasetId id = DatasetFrameworkTestUtil.NAMESPACE_ID.dataset(name);
    if (dsFrameworkUtil.getInstance(id) == null) {
        dsFrameworkUtil.createInstance(Table.class.getName(), id, DatasetProperties.EMPTY);
    }
    Table table = dsFrameworkUtil.getInstance(id);
    return new MetricsTableTxnlWrapper(new MetricsTableOnTable(table), table);
}
Also used : Table(co.cask.cdap.api.dataset.table.Table) MetricsTable(co.cask.cdap.data2.dataset2.lib.table.MetricsTable) DatasetId(co.cask.cdap.proto.id.DatasetId)

Example 18 with MetricsTable

use of co.cask.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.

the class EntityTableTest method testGetId.

@Test
public void testGetId() throws Exception {
    InMemoryTableService.create("testGetId");
    MetricsTable table = new InMemoryMetricsTable("testGetId");
    EntityTable entityTable = new EntityTable(table);
    // Make sure it is created sequentially
    for (int i = 1; i <= 10; i++) {
        Assert.assertEquals((long) i, entityTable.getId("app", "app" + i));
    }
    // It should get the same value (from cache)
    for (int i = 1; i <= 10; i++) {
        Assert.assertEquals((long) i, entityTable.getId("app", "app" + i));
    }
    // Construct another entityTable, it should load from storage.
    entityTable = new EntityTable(table);
    for (int i = 1; i <= 10; i++) {
        Assert.assertEquals((long) i, entityTable.getId("app", "app" + i));
    }
    // ID for different type should have ID starts from 1 again.
    for (int i = 1; i <= 10; i++) {
        Assert.assertEquals((long) i, entityTable.getId("flow", "flow" + i));
    }
}
Also used : InMemoryMetricsTable(co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable) MetricsTable(co.cask.cdap.data2.dataset2.lib.table.MetricsTable) InMemoryMetricsTable(co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable) Test(org.junit.Test)

Example 19 with MetricsTable

use of co.cask.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.

the class EntityTableTest method testRecycleAfterMaxId.

@Test
public void testRecycleAfterMaxId() throws Exception {
    InMemoryTableService.create("testRecycleId");
    MetricsTable table = new InMemoryMetricsTable("testRecycleId");
    EntityTable entityTable = new EntityTable(table, 101);
    // only have 100 entries as maxId.
    for (long i = 1; i <= 500; i++) {
        entityTable.getId("app", "app" + i);
    }
    // we call getName for the 100 entries, it will be the latest entries 401-500
    for (long i = 1; i <= 100; i++) {
        Assert.assertEquals("app" + String.valueOf(400 + i), entityTable.getName(i, "app"));
    }
}
Also used : InMemoryMetricsTable(co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable) MetricsTable(co.cask.cdap.data2.dataset2.lib.table.MetricsTable) InMemoryMetricsTable(co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable) Test(org.junit.Test)

Example 20 with MetricsTable

use of co.cask.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.

the class FactCodecTest method test.

@Test
public void test() {
    InMemoryTableService.create("FactCodecTest");
    MetricsTable table = new InMemoryMetricsTable("FactCodecTest");
    int resolution = 10;
    int rollTimebaseInterval = 2;
    FactCodec codec = new FactCodec(new EntityTable(table), resolution, rollTimebaseInterval);
    // testing encoding with multiple dimensions
    List<DimensionValue> dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value1"), new DimensionValue("dimension2", "value2"), new DimensionValue("dimension3", "value3"));
    // note: we use seconds everywhere and rely on this
    long ts = 1422312915;
    byte[] rowKey = codec.createRowKey(dimensionValues, "myMetric", ts);
    byte[] column = codec.createColumn(ts);
    Assert.assertEquals((ts / resolution) * resolution, codec.getTimestamp(rowKey, column));
    Assert.assertEquals(dimensionValues, codec.getDimensionValues(rowKey));
    Assert.assertEquals("myMetric", codec.getMeasureName(rowKey));
    // testing encoding without one dimension
    dimensionValues = ImmutableList.of(new DimensionValue("myTag", "myValue"));
    rowKey = codec.createRowKey(dimensionValues, "mySingleTagMetric", ts);
    Assert.assertEquals((ts / resolution) * resolution, codec.getTimestamp(rowKey, column));
    Assert.assertEquals(dimensionValues, codec.getDimensionValues(rowKey));
    Assert.assertEquals("mySingleTagMetric", codec.getMeasureName(rowKey));
    // testing encoding without empty dimensions
    rowKey = codec.createRowKey(new ArrayList<DimensionValue>(), "myNoTagsMetric", ts);
    Assert.assertEquals((ts / resolution) * resolution, codec.getTimestamp(rowKey, column));
    Assert.assertEquals(new ArrayList<DimensionValue>(), codec.getDimensionValues(rowKey));
    Assert.assertEquals("myNoTagsMetric", codec.getMeasureName(rowKey));
    // testing null metric
    dimensionValues = ImmutableList.of(new DimensionValue("myTag", "myValue"));
    rowKey = codec.createRowKey(dimensionValues, "mySingleTagMetric", ts);
    Assert.assertEquals((ts / resolution) * resolution, codec.getTimestamp(rowKey, column));
    Assert.assertEquals(dimensionValues, codec.getDimensionValues(rowKey));
    Assert.assertEquals("mySingleTagMetric", codec.getMeasureName(rowKey));
    // testing null value
    dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value1"), new DimensionValue("dimension2", null), new DimensionValue("dimension3", "value3"));
    rowKey = codec.createRowKey(dimensionValues, "myNullTagMetric", ts);
    Assert.assertEquals((ts / resolution) * resolution, codec.getTimestamp(rowKey, column));
    Assert.assertEquals(dimensionValues, codec.getDimensionValues(rowKey));
    Assert.assertEquals("myNullTagMetric", codec.getMeasureName(rowKey));
    // testing fuzzy mask for fuzzy stuff in row key
    dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value1"), // any value is accepted
    new DimensionValue("dimension2", null), new DimensionValue("dimension3", "value3"));
    byte[] mask = codec.createFuzzyRowMask(dimensionValues, "myMetric");
    rowKey = codec.createRowKey(dimensionValues, "myMetric", ts);
    FuzzyRowFilter filter = new FuzzyRowFilter(ImmutableList.of(new ImmutablePair<>(rowKey, mask)));
    dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value1"), new DimensionValue("dimension2", "annnnnnnnnny"), new DimensionValue("dimension3", "value3"));
    rowKey = codec.createRowKey(dimensionValues, "myMetric", ts);
    Assert.assertEquals(FuzzyRowFilter.ReturnCode.INCLUDE, filter.filterRow(rowKey));
    dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value12"), new DimensionValue("dimension2", "value2"), new DimensionValue("dimension3", "value3"));
    rowKey = codec.createRowKey(dimensionValues, "myMetric", ts);
    Assert.assertTrue(FuzzyRowFilter.ReturnCode.INCLUDE != filter.filterRow(rowKey));
    dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value1"), new DimensionValue("dimension2", "value2"), new DimensionValue("dimension3", "value13"));
    rowKey = codec.createRowKey(dimensionValues, "myMetric", ts);
    Assert.assertTrue(FuzzyRowFilter.ReturnCode.INCLUDE != filter.filterRow(rowKey));
    dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value1"), new DimensionValue("dimension3", "value3"));
    rowKey = codec.createRowKey(dimensionValues, "myMetric", ts);
    Assert.assertTrue(FuzzyRowFilter.ReturnCode.INCLUDE != filter.filterRow(rowKey));
    // fuzzy in value should match the "null" value
    dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value1"), new DimensionValue("dimension2", null), new DimensionValue("dimension3", "value3"));
    rowKey = codec.createRowKey(dimensionValues, "myMetric", ts);
    Assert.assertEquals(FuzzyRowFilter.ReturnCode.INCLUDE, filter.filterRow(rowKey));
    dimensionValues = ImmutableList.of(new DimensionValue("dimension1", "value1"), new DimensionValue("dimension2", "value2"), new DimensionValue("dimension3", "value3"));
    rowKey = codec.createRowKey(dimensionValues, "myMetric2", ts);
    Assert.assertTrue(FuzzyRowFilter.ReturnCode.INCLUDE != filter.filterRow(rowKey));
    rowKey = codec.createRowKey(dimensionValues, null, ts);
    Assert.assertTrue(FuzzyRowFilter.ReturnCode.INCLUDE != filter.filterRow(rowKey));
    rowKey = codec.createRowKey(new ArrayList<DimensionValue>(), "myMetric", ts);
    Assert.assertTrue(FuzzyRowFilter.ReturnCode.INCLUDE != filter.filterRow(rowKey));
    // testing fuzzy mask for fuzzy metric
    dimensionValues = ImmutableList.of(new DimensionValue("myTag", "myValue"));
    rowKey = codec.createRowKey(dimensionValues, null, ts);
    mask = codec.createFuzzyRowMask(dimensionValues, null);
    filter = new FuzzyRowFilter(ImmutableList.of(new ImmutablePair<>(rowKey, mask)));
    rowKey = codec.createRowKey(dimensionValues, "annyyy", ts);
    Assert.assertEquals(FuzzyRowFilter.ReturnCode.INCLUDE, filter.filterRow(rowKey));
    rowKey = codec.createRowKey(dimensionValues, "zzzzzzzzzzzz", ts);
    Assert.assertEquals(FuzzyRowFilter.ReturnCode.INCLUDE, filter.filterRow(rowKey));
    dimensionValues = ImmutableList.of(new DimensionValue("myTag", "myValue2"));
    rowKey = codec.createRowKey(dimensionValues, "metric", ts);
    Assert.assertTrue(FuzzyRowFilter.ReturnCode.INCLUDE != filter.filterRow(rowKey));
// todo: test prefix of multi dimension valued row key is not same one dimension valued row key
// todo: test that rollTimebaseInterval applies well
}
Also used : ArrayList(java.util.ArrayList) FuzzyRowFilter(co.cask.cdap.data2.dataset2.lib.table.FuzzyRowFilter) InMemoryMetricsTable(co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable) MetricsTable(co.cask.cdap.data2.dataset2.lib.table.MetricsTable) DimensionValue(co.cask.cdap.api.dataset.lib.cube.DimensionValue) ImmutablePair(co.cask.cdap.common.utils.ImmutablePair) InMemoryMetricsTable(co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable) Test(org.junit.Test)

Aggregations

MetricsTable (co.cask.cdap.data2.dataset2.lib.table.MetricsTable)14 Test (org.junit.Test)6 InMemoryMetricsTable (co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryMetricsTable)5 DatasetId (co.cask.cdap.proto.id.DatasetId)4 DatasetModule (co.cask.cdap.api.dataset.module.DatasetModule)3 Table (co.cask.cdap.api.dataset.table.Table)3 Constants (co.cask.cdap.common.conf.Constants)3 ExternalDatasetModule (co.cask.cdap.data2.dataset2.lib.external.ExternalDatasetModule)3 MetadataDatasetModule (co.cask.cdap.data2.metadata.dataset.MetadataDatasetModule)3 LineageDatasetModule (co.cask.cdap.data2.metadata.lineage.LineageDatasetModule)3 UsageDatasetModule (co.cask.cdap.data2.registry.UsageDatasetModule)3 HBaseQueueDatasetModule (co.cask.cdap.data2.transaction.queue.hbase.HBaseQueueDatasetModule)3 AbstractModule (com.google.inject.AbstractModule)3 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)2 DimensionValue (co.cask.cdap.api.dataset.lib.cube.DimensionValue)2 EntityTable (co.cask.cdap.data2.dataset2.lib.timeseries.EntityTable)2 FactTable (co.cask.cdap.data2.dataset2.lib.timeseries.FactTable)2 HBaseMetricsTableModule (co.cask.cdap.data2.dataset2.module.lib.hbase.HBaseMetricsTableModule)2 IOException (java.io.IOException)2 DatasetProperties (co.cask.cdap.api.dataset.DatasetProperties)1