According to the requirements of the project, it was necessary to write several simple TS-data streams into the database. It is supposed to write data to a simple table:
type | id | taken_at | value click_count | region:spb | 2016-01-01 10:00:00 | 12 view_count | * | 2016-01-01 10:00:02 | {"anonymous": 12, "logged": 3} Naturally, we need to generate reports on this table, including with discretization: the user can indicate that he needs values at a certain interval, for example, on one day, thirty minutes or two hours, that is, organize the following sample in pseudocode:
results = ts.query() pointer = 0 filtered = [] last_date = 0 interval = 3600 // 1 час while results.length < pointer: if last_date + interval < results[pointer].taken_at: filtered[] = results[pointer] last_date = results[pointer].taken_at pointer++ return filtered Is it possible to organize such samples (include a line in the sample; skip lines while they are in the date range of the previous value + user-specified interval; repeat as long as the records remain) at the SQL level? A specific engine, if this is important - MySQL, ideally, of course, I would like to find a solution that does not depend on the engine.