github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/roachpb/internal.go (about)

     1  // Copyright 2014 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package roachpb
    12  
    13  // IsColumnar returns true if this InternalTimeSeriesData stores its samples
    14  // in columnar format.
    15  func (data *InternalTimeSeriesData) IsColumnar() bool {
    16  	return len(data.Offset) > 0
    17  }
    18  
    19  // IsRollup returns true if this InternalTimeSeriesData is both in columnar
    20  // format and contains "rollup" data.
    21  func (data *InternalTimeSeriesData) IsRollup() bool {
    22  	return len(data.Count) > 0
    23  }
    24  
    25  // SampleCount returns the number of samples contained in this
    26  // InternalTimeSeriesData.
    27  func (data *InternalTimeSeriesData) SampleCount() int {
    28  	if data.IsColumnar() {
    29  		return len(data.Offset)
    30  	}
    31  	return len(data.Samples)
    32  }
    33  
    34  // OffsetForTimestamp returns the offset within this collection that would
    35  // represent the provided timestamp.
    36  func (data *InternalTimeSeriesData) OffsetForTimestamp(timestampNanos int64) int32 {
    37  	return int32((timestampNanos - data.StartTimestampNanos) / data.SampleDurationNanos)
    38  }
    39  
    40  // TimestampForOffset returns the timestamp that would represent the provided
    41  // offset in this collection.
    42  func (data *InternalTimeSeriesData) TimestampForOffset(offset int32) int64 {
    43  	return data.StartTimestampNanos + int64(offset)*data.SampleDurationNanos
    44  }