use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.
the class DataMigration method createRegisteredDatasetFramework.
/**
* Sets up a {@link DatasetFramework} instance for standalone usage. NOTE: should NOT be used by applications!!!
*/
public static DatasetFramework createRegisteredDatasetFramework(Injector injector) throws DatasetManagementException, IOException {
DatasetDefinitionRegistryFactory registryFactory = injector.getInstance(DatasetDefinitionRegistryFactory.class);
DatasetFramework datasetFramework = new InMemoryDatasetFramework(registryFactory);
// TODO: this doesn't sound right. find out why its needed.
datasetFramework.addModule(NamespaceId.SYSTEM.datasetModule("table"), new HBaseTableModule());
datasetFramework.addModule(NamespaceId.SYSTEM.datasetModule("metricsTable"), new HBaseMetricsTableModule());
datasetFramework.addModule(NamespaceId.SYSTEM.datasetModule("core"), new CoreDatasetsModule());
datasetFramework.addModule(NamespaceId.SYSTEM.datasetModule("fileSet"), new FileSetModule());
return datasetFramework;
}
use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.
the class MetricsDataMigrator method migrateMetricsTableFromVersion27.
private void migrateMetricsTableFromVersion27(Version version) throws DataMigrationException {
EntityTable entityTable = new EntityTable(getOrCreateMetricsTable(entityTableName, DatasetProperties.EMPTY));
MetricsTable metricsTable = getOrCreateMetricsTable(metricsTableName, DatasetProperties.EMPTY);
System.out.println("Migrating Metrics Data from table : " + metricsTableName);
migrateMetricsData(entityTable, metricsTable, null, version);
}
use of io.cdap.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);
}
use of io.cdap.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"));
}
}
use of io.cdap.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
}
Aggregations