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

Method getTimeDimensionExpression

runtime/metricsview/ast.go:1282–1304  ·  view source on GitHub ↗

getTimeDimensionExpression returns the SQL expression and data type code for the time dimension specified in the TimeRange or the metrics view's time dimension. It looks up the time dimension definition in the metrics view or returns the escaped column name from the model.

(tr *TimeRange)

Source from the content-addressed store, hash-verified

1280// getTimeDimensionExpression returns the SQL expression and data type code for the time dimension specified in the TimeRange or the metrics view's time dimension.
1281// It looks up the time dimension definition in the metrics view or returns the escaped column name from the model.
1282func (a *AST) getTimeDimensionExpression(tr *TimeRange) (string, runtimev1.Type_Code, error) {
1283 timeDim := a.MetricsView.TimeDimension
1284 if tr.TimeDimension != "" {
1285 timeDim = tr.TimeDimension
1286 }
1287
1288 t, err := a.LookupDimension(timeDim, true)
1289 if err != nil {
1290 return "", runtimev1.Type_CODE_UNSPECIFIED, fmt.Errorf("time dimension %q not found: %w", timeDim, err)
1291 }
1292
1293 expr, err := a.Dialect.MetricsViewDimensionExpression(t)
1294 if err != nil {
1295 return "", runtimev1.Type_CODE_UNSPECIFIED, fmt.Errorf("failed to compile time dimension %q expression: %w", t.Name, err)
1296 }
1297
1298 var typeCode runtimev1.Type_Code
1299 if t.DataType != nil {
1300 typeCode = t.DataType.Code
1301 }
1302
1303 return expr, typeCode, nil
1304}
1305
1306// checkNameForComputedField checks that the name for a computed field does not collide with an existing dimension or measure name.
1307// (This is necessary because even if the other name is not used in the query, it might be referenced by a derived measure.)

Callers 1

AddTimeRangeMethod · 0.95

Calls 3

LookupDimensionMethod · 0.95
ErrorfMethod · 0.65

Tested by

no test coverage detected