Skip to content

Commit

Permalink
Runtime: validate measures do not contain a window function (#4103)
Browse files Browse the repository at this point in the history
  • Loading branch information
begelundmuller authored Feb 20, 2024
1 parent 381ac4c commit 182ab98
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion runtime/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func validateDimension(ctx context.Context, olap drivers.OLAPStore, t *drivers.T

func validateMeasure(ctx context.Context, olap drivers.OLAPStore, t *drivers.Table, m *runtimev1.MetricsViewSpec_MeasureV2) error {
err := olap.Exec(ctx, &drivers.Statement{
Query: fmt.Sprintf("SELECT %s from %s", m.Expression, safeSQLName(t.Name)),
Query: fmt.Sprintf("SELECT 1, %s FROM %s GROUP BY 1", m.Expression, safeSQLName(t.Name)),
DryRun: true,
})
return err
Expand Down
4 changes: 3 additions & 1 deletion runtime/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ func TestValidateMetricsView(t *testing.T) {
Measures: []*runtimev1.MetricsViewSpec_MeasureV2{
{Name: "records", Expression: "count(*)"},
{Name: "invalid_nested_aggregation", Expression: "MAX(COUNT(DISTINCT publisher))"},
{Name: "invalid_partition", Expression: "AVG(bid_price) OVER (PARTITION BY publisher)"},
},
})
require.NoError(t, err)
require.Empty(t, res.TimeDimensionErr)
require.Empty(t, res.DimensionErrs)
require.Empty(t, res.OtherErrs)

require.Len(t, res.MeasureErrs, 1)
require.Len(t, res.MeasureErrs, 2)
require.Equal(t, 1, res.MeasureErrs[0].Idx)
require.Equal(t, 2, res.MeasureErrs[1].Idx)
}

0 comments on commit 182ab98

Please sign in to comment.