use of co.cask.cdap.api.dataset.table.Row in project cdap by caskdata.
the class ProgramScheduleStoreDataset method getSchedule.
/**
* Read a schedule from the store.
*
* @param scheduleId the id of the schedule to read
* @return the schedule from the store
* @throws NotFoundException if the schedule does not exist in the store
*/
public ProgramSchedule getSchedule(ScheduleId scheduleId) throws NotFoundException {
Row row = store.get(new Get(rowKeyForSchedule(scheduleId)));
byte[] serialized = row.get(SCHEDULE_COLUMN_BYTES);
if (serialized == null) {
throw new NotFoundException(scheduleId);
}
return GSON.fromJson(Bytes.toString(serialized), ProgramSchedule.class);
}
use of co.cask.cdap.api.dataset.table.Row in project cdap by caskdata.
the class DatasetBasedTimeScheduleStore method upgradeJobs.
private void upgradeJobs(Table table) {
Row result = table.get(JOB_KEY);
if (result.isEmpty()) {
return;
}
for (byte[] column : result.getColumns().values()) {
JobDetail oldJobDetail = (JobDetail) SerializationUtils.deserialize(column);
JobDetail jobDetail = addDefaultAppVersionIfNeeded(oldJobDetail);
if (!jobDetail.equals(oldJobDetail)) {
// Write the new jobDetail only if the upgraded key doesn't exist already
if (readJob(table, jobDetail.getKey()) == null) {
persistJob(table, jobDetail);
}
removeJob(table, oldJobDetail.getKey());
}
}
}
use of co.cask.cdap.api.dataset.table.Row in project cdap by caskdata.
the class DatasetBasedTimeScheduleStore method readTrigger.
private TriggerStatusV2 readTrigger(TriggerKey key) {
byte[][] col = new byte[1][];
col[0] = Bytes.toBytes(key.getName());
Row result = table.get(TRIGGER_KEY, col);
byte[] bytes = null;
if (!result.isEmpty()) {
bytes = result.get(col[0]);
}
if (bytes != null) {
return (TriggerStatusV2) SerializationUtils.deserialize(bytes);
} else {
return null;
}
}
use of co.cask.cdap.api.dataset.table.Row in project cdap by caskdata.
the class FactScanner method createIterator.
private Iterator<FactScanResult> createIterator() {
return new AbstractIterator<FactScanResult>() {
@Override
protected FactScanResult computeNext() {
Row rowResult;
while ((rowResult = scanner.next()) != null) {
rowScanned++;
byte[] rowKey = rowResult.getRow();
// Decode context and metric from key
String measureName = codec.getMeasureName(rowKey);
// if measureNames is empty we include all metrics
if (!measureNames.isEmpty() && !measureNames.contains(measureName)) {
continue;
}
// todo: codec.getDimensionValues(rowKey) needs to un-encode dimension names which may result in read in
// entity table (depending on the cache and its state). To avoid that, we can pass to scanner the
// list of dimension names as we *always* know it (it is given) at the time of scanning
List<DimensionValue> dimensionValues = codec.getDimensionValues(rowKey);
boolean exhausted = false;
List<TimeValue> timeValues = Lists.newLinkedList();
// todo: entry set is ordered by ts?
for (Map.Entry<byte[], byte[]> columnValue : rowResult.getColumns().entrySet()) {
long ts = codec.getTimestamp(rowKey, columnValue.getKey());
if (ts < startTs) {
continue;
}
if (ts > endTs) {
exhausted = true;
break;
}
// todo: move Bytes.toLong into codec?
TimeValue timeValue = new TimeValue(ts, Bytes.toLong(columnValue.getValue()));
timeValues.add(timeValue);
}
if (timeValues.isEmpty() && exhausted) {
break;
}
// todo: can return empty list, if all data is < startTs or > endTs
return new FactScanResult(measureName, dimensionValues, timeValues);
}
scanner.close();
return endOfData();
}
};
}
use of co.cask.cdap.api.dataset.table.Row in project cdap by caskdata.
the class MetricsTableTest method testFuzzyScan.
@Test
public void testFuzzyScan() throws Exception {
MetricsTable table = getTable("testFuzzyScan");
NavigableMap<byte[], SortedMap<byte[], Long>> writes = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
byte[] abc = { 'a', 'b', 'c' };
for (byte b1 : abc) {
for (byte b2 : abc) {
for (byte b3 : abc) {
for (byte b4 : abc) {
// we put two columns, but will scan only one column
writes.put(new byte[] { b1, b2, b3, b4 }, mapOf(A, Bytes.toLong(X)));
}
}
}
}
table.put(writes);
// we should have 81 (3^4) rows now
Assert.assertEquals(81, countRange(table, null, null));
// now do a fuzzy scan of the table
FuzzyRowFilter filter = new FuzzyRowFilter(ImmutableList.of(ImmutablePair.of(new byte[] { '*', 'b', '*', 'b' }, new byte[] { 0x01, 0x00, 0x01, 0x00 })));
Scanner scanner = table.scan(null, null, filter);
int count = 0;
while (true) {
Row entry = scanner.next();
if (entry == null) {
break;
}
Assert.assertTrue(entry.getRow()[1] == 'b' && entry.getRow()[3] == 'b');
Assert.assertEquals(1, entry.getColumns().size());
Assert.assertTrue(entry.getColumns().containsKey(A));
count++;
}
Assert.assertEquals(9, count);
}
Aggregations