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

Method sqlForTimeRange

runtime/metricsview/ast.go:1398–1415  ·  view source on GitHub ↗

sqlForTimeRange builds a SQL expression and query args for filtering by a time range.

(timeDimExpr string, typeCode runtimev1.Type_Code, start, end time.Time)

Source from the content-addressed store, hash-verified

1396
1397// sqlForTimeRange builds a SQL expression and query args for filtering by a time range.
1398func (a *AST) sqlForTimeRange(timeDimExpr string, typeCode runtimev1.Type_Code, start, end time.Time) (string, []any) {
1399 param := a.Dialect.GetTimeDimensionParameter(typeCode)
1400 var where string
1401 var args []any
1402 if !start.IsZero() && !end.IsZero() {
1403 where = fmt.Sprintf("%s >= %s AND %s < %s", timeDimExpr, param, timeDimExpr, param)
1404 args = []any{start, end}
1405 } else if !start.IsZero() {
1406 where = fmt.Sprintf("%s >= %s", timeDimExpr, param)
1407 args = []any{start}
1408 } else if !end.IsZero() {
1409 where = fmt.Sprintf("%s < %s", timeDimExpr, param)
1410 args = []any{end}
1411 } else {
1412 return "", nil
1413 }
1414 return where, args
1415}
1416
1417// sqlForMeasure builds a SQL expression for a measure, including its window if present.
1418// It uses the provided n to resolve dimensions expressions for window partitions.

Callers 1

AddTimeRangeMethod · 0.95

Calls 2

IsZeroMethod · 0.45

Tested by

no test coverage detected