Skip to content

Commit 764e7e0

Browse files
committed
Ensure metrics are evaluated strictly.
Metrics should not be evaluated lazily as this delays the calculation until the data is requested. Concretely, this means we should evaluate all intances of `IEnumerable<T>` using `.ToList()` within the publisher's `YieldMetrics` method. This change updates the `PublisherComponent` implementations where necessary.
1 parent be9b6f4 commit 764e7e0

7 files changed

Lines changed: 16 additions & 13 deletions

File tree

src/explorer/Components/Datetime/DatetimeGeneratorComponent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public async IAsyncEnumerable<ExploreMetric> YieldMetrics()
3232
metric: distribution
3333
.Generate(SamplesToPublish)
3434
.OrderBy(_ => _)
35-
.ToArray());
35+
.ToList());
3636
}
3737
}
3838
}

src/explorer/Components/Datetime/TimeUtilities.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ private static object MetricBlob<T>(
3737
{
3838
Total = total,
3939
Suppressed = suppressed,
40-
Counts =
41-
from row in valueCounts
42-
where row.HasValue
43-
orderby row.GroupingIndex ascending
44-
select new
40+
Counts = valueCounts
41+
.Where(row => row.HasValue)
42+
.OrderBy(row => row.GroupingIndex)
43+
.Select(row => new
4544
{
4645
row.Value,
4746
row.Count,
4847
row.CountNoise,
49-
},
48+
})
49+
.ToList(),
5050
};
5151
}
5252

src/explorer/Components/DistinctValuesComponent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ public class Result
8787
{
8888
public Result(IEnumerable<ValueWithCount<JsonElement>> distinctRows)
8989
{
90-
DistinctRows = distinctRows;
90+
DistinctRows = distinctRows.ToList();
9191
ValueCounts = ValueCounts.Compute(distinctRows);
9292
IsCategorical = ValueCounts.SuppressedRowRatio < SuppressedRatioThreshold;
9393
}
9494

95-
public IEnumerable<ValueWithCount<JsonElement>> DistinctRows { get; }
95+
public List<ValueWithCount<JsonElement>> DistinctRows { get; }
9696

9797
public ValueCounts ValueCounts { get; }
9898

src/explorer/Components/DistributionAnalysisComponent.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ ks is null
5757
}
5858
.Where(gm => !(gm is null) && double.IsFinite(gm.PValue)),
5959
};
60-
}));
60+
})
61+
.ToList());
6162
}
6263

6364
protected override async Task<GoodnessOfFitCollection?> Explore()

src/explorer/Components/DistributionPublishers/NumericSampleGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public async IAsyncEnumerable<ExploreMetric> YieldMetrics()
4747
.Generate(SamplesToPublish)
4848
.Select(s => Context.ColumnInfo.Type == Diffix.DValueType.Real ? s : Convert.ToInt64(s))
4949
.OrderBy(_ => _)
50-
.ToArray());
50+
.ToList());
5151
}
5252
}
5353
}

src/explorer/Components/HistogramSelectorComponent.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public async IAsyncEnumerable<ExploreMetric> YieldMetrics()
3535
b.LowerBound,
3636
b.Count,
3737
b.CountNoise,
38-
}));
38+
})
39+
.ToList());
3940
yield return new UntypedMetric("histogram.suppressed_count", result.ValueCounts.SuppressedCount);
4041
yield return new UntypedMetric("histogram.suppressed_ratio", result.ValueCounts.SuppressedCountRatio);
4142
yield return new UntypedMetric("histogram.value_counts", result.ValueCounts);

src/explorer/Components/TextLengthComponent.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public async IAsyncEnumerable<ExploreMetric> YieldMetrics()
2626
result.DistinctRows
2727
.Where(r => r.HasValue)
2828
.OrderBy(r => r.Value.GetInt32())
29-
.Select(r => new { r.Value, r.Count }));
29+
.Select(r => new { r.Value, r.Count })
30+
.ToList());
3031
yield return new UntypedMetric("text.length.counts", result.ValueCounts);
3132
}
3233

0 commit comments

Comments
 (0)