@Override public CounterTimeseriesTable getDataset(DatasetContext datasetContext, DatasetSpecification spec, Map<String, String> arguments, ClassLoader classLoader) throws IOException { return new CounterTimeseriesTable(spec, this.<Table>getDataset(datasetContext, "ts", spec, arguments, classLoader)); } }
/** * Increments the value for a counter for a row and timestamp. * * @param counter the name of the counter to increment * @param amount the amount to increment by * @param timestamp timestamp of the entry * @param tags optional list of tags associated with the counter. See {@link TimeseriesTable} class description * for more details. * @return value of the entry after increment */ @ReadWrite public long increment(byte[] counter, long amount, long timestamp, byte[]... tags) { return internalIncrement(counter, amount, timestamp, tags); }
final Iterator<Entry> internalItor = readInternal(counter, startTime, endTime, tags); return new Iterator<Counter>() { @Override
assertEquals(2L, table.increment(rowKey1, 2L, timestamp1)); assertEquals(2L, table.increment(rowKey1, 0L, timestamp1)); assertEquals(7L, table.increment(rowKey1, 5L, timestamp1)); assertEquals(-2L, table.increment(rowKey2, -2L, timestamp1)); assertEquals(0L, table.increment(rowKey3, 0L, timestamp1)); assertEquals(5L, table.increment(rowKey1, 5L, timestamp2)); assertEquals(10L, table.increment(rowKey1, 5L, timestamp2)); assertEquals(7L, table.increment(rowKey1, 7L, timestamp3)); assertEquals(-2L, table.increment(rowKey2, 0L, timestamp1)); table.set(rowKey1, 20L, timestamp4); Iterator<CounterTimeseriesTable.Counter> result = table.read(rowKey1, timestamp4, timestamp4); assertCounterEquals(rowKey1, 20L, timestamp4, result.next()); assertFalse(result.hasNext()); result = table.read(rowKey1, timestamp1, timestamp4); assertCounterEquals(rowKey1, 7L, timestamp1, result.next()); assertCounterEquals(rowKey1, 10L, timestamp2, result.next()); result = table.read(rowKey1, timestamp1, timestamp3, 1, 2); assertCounterEquals(rowKey1, 10L, timestamp2, result.next()); assertCounterEquals(rowKey1, 7L, timestamp3, result.next()); assertFalse(result.hasNext()); table.set(rowKey4, 3L, timestamp1, tag1); table.increment(rowKey4, 5L, timestamp2); table.increment(rowKey4, 7L, timestamp3); table.increment(rowKey4, 11L, timestamp3, tag1); table.increment(rowKey4, 13L, timestamp3);
final Iterator<Counter> iterator = read(counter, startTime, endTime, tags);
/** * Set the value for a counter. * * @param counter the name of the counter to set * @param value the value to set * @param timestamp timestamp of the entry * @param tags optional list of tags associated with the counter. See {@link TimeseriesTable} class description * for more details. */ @WriteOnly public void set(byte[] counter, long value, long timestamp, byte[]... tags) { write(counter, Bytes.toBytes(value), timestamp, tags); }