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)
| 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. |
| 1282 | func (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.) |
no test coverage detected