group TimelineAggregatorDAO;

getStreamingAggregationCandidates() ::= <<
  select
    chunk_id
  , source_id
  , metric_id
  , start_time
  , end_time
  , in_row_samples
  , blob_samples
  , sample_count
  , aggregation_level
  , not_valid
  , dont_aggregate
  from timeline_chunks
  where source_id != 0 and aggregation_level = :aggregationLevel and not_valid = 0
  order by source_id, metric_id, start_time
 >>

 getAggregationCandidatesForSourceIdAndMetricIds(metricIds) ::= <<
  select
    chunk_id
  , source_id
  , metric_id
  , start_time
  , end_time
  , in_row_samples
  , blob_samples
  , sample_count
  , aggregation_level
  , not_valid
  , dont_aggregate
  from timeline_chunks
  where source_id = :source_id
  and metric_id in (<metricIds>)
  ;
>>

getLastInsertedId() ::= <<
  select last_insert_id();
>>

makeTimelineChunkValid() ::= <<
  update timeline_chunks
  set not_valid = 0
  where chunk_id = :chunkId
  ;
>>

makeTimelineChunksInvalid(chunkIds) ::=<<
  update timeline_chunks
  set not_valid = 1
  where chunk_id in (<chunkIds>)
  ;
>>

deleteTimelineChunks(chunkIds) ::=<<
  delete from timeline_chunks where chunk_id in (<chunkIds>);
>>
