MCPcopy Create free account
hub / github.com/rilldata/rill / applyAdditionalTimeRange

Function applyAdditionalTimeRange

runtime/resolvers/metrics_sql.go:173–214  ·  view source on GitHub ↗

applyAdditionalTimeRange merges the existing time range with the additional time range

(current, additional *metricsview.TimeRange)

Source from the content-addressed store, hash-verified

171
172// applyAdditionalTimeRange merges the existing time range with the additional time range
173func applyAdditionalTimeRange(current, additional *metricsview.TimeRange) *metricsview.TimeRange {
174 if current == nil {
175 return additional
176 }
177 if additional == nil {
178 return current
179 }
180
181 timeRange := &metricsview.TimeRange{
182 Start: current.Start,
183 End: current.End,
184 Expression: current.Expression,
185 IsoDuration: current.IsoDuration,
186 IsoOffset: current.IsoOffset,
187 RoundToGrain: current.RoundToGrain,
188 TimeDimension: current.TimeDimension,
189 }
190
191 if !additional.Start.IsZero() && (timeRange.Start.IsZero() || additional.Start.After(timeRange.Start)) {
192 timeRange.Start = additional.Start
193 }
194 if !additional.End.IsZero() && (timeRange.End.IsZero() || additional.End.Before(timeRange.End)) {
195 timeRange.End = additional.End
196 }
197 if additional.Expression != "" && timeRange.Expression == "" {
198 timeRange.Expression = additional.Expression
199 }
200 if additional.IsoDuration != "" && timeRange.IsoDuration == "" {
201 timeRange.IsoDuration = additional.IsoDuration
202 }
203 if additional.IsoOffset != "" && timeRange.IsoOffset == "" {
204 timeRange.IsoOffset = additional.IsoOffset
205 }
206 if additional.RoundToGrain != metricsview.TimeGrainUnspecified && timeRange.RoundToGrain == metricsview.TimeGrainUnspecified {
207 timeRange.RoundToGrain = additional.RoundToGrain
208 }
209 if additional.TimeDimension != "" && timeRange.TimeDimension == "" {
210 timeRange.TimeDimension = additional.TimeDimension
211 }
212
213 return timeRange
214}

Callers 1

newMetricsSQLFunction · 0.85

Calls 1

IsZeroMethod · 0.45

Tested by

no test coverage detected