Skip to content

Commit 41707fc

Browse files
authored
Add code to handle double NaN, +- inf to Monitor (Azure#25096)
1 parent 861d931 commit 41707fc

File tree

5 files changed

+213
-1
lines changed

5 files changed

+213
-1
lines changed

sdk/monitor/Azure.Monitor.Query/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Breaking Changes
88

99
### Bugs Fixed
10+
- NaN, +inf, and -inf double values can now be retrieved from `LogsQueryResult`
1011

1112
### Other Changes
1213

sdk/monitor/Azure.Monitor.Query/src/Models/LogsTableRow.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,29 @@ internal LogsTableRow(Dictionary<string, int> columnMap, IReadOnlyList<LogsTable
6565
/// </summary>
6666
/// <param name="index">The column index.</param>
6767
/// <returns>The <see cref="Nullable{Double}"/> value of the column.</returns>
68-
public double? GetDouble(int index) => _row[index].ValueKind == JsonValueKind.Null ? null : _row[index].GetDouble();
68+
public double? GetDouble(int index)
69+
{
70+
if (_row[index].ValueKind == JsonValueKind.Null)
71+
{
72+
return null;
73+
}
74+
else
75+
{
76+
if (_row[index].ValueKind == JsonValueKind.String)
77+
{
78+
string result = _row[index].GetString();
79+
switch (result) {
80+
case "NaN":
81+
return Double.NaN;
82+
case "Infinity":
83+
return Double.PositiveInfinity;
84+
case "-Infinity":
85+
return Double.NegativeInfinity;
86+
}
87+
}
88+
return _row[index].GetDouble();
89+
}
90+
}
6991

7092
/// <summary>
7193
/// Gets the value of the column at the specified index as <see cref="string"/>.

sdk/monitor/Azure.Monitor.Query/tests/LogsQueryClientClientLiveTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,5 +753,22 @@ private record TestModelForTypesNullable
753753
public Decimal? Decimal { get; set; }
754754
public BinaryData Dynamic { get; set; }
755755
}
756+
757+
[Test]
758+
public async Task ValidateNanAndInfResultsDoubleAsync()
759+
{
760+
var client = CreateClient();
761+
var results = await client.QueryWorkspaceAsync(TestEnvironment.WorkspaceId, "print real(nan), real(+inf), real(-inf), real(null), real(123)", TimeSpan.FromMinutes(1));
762+
763+
var resultTable = results.Value.Table;
764+
CollectionAssert.IsNotEmpty(resultTable.Columns);
765+
766+
Assert.AreEqual(LogsQueryResultStatus.Success, results.Value.Status);
767+
Assert.AreEqual(double.NaN, resultTable.Rows[0][0]);
768+
Assert.AreEqual(double.PositiveInfinity, resultTable.Rows[0][1]);
769+
Assert.AreEqual(double.NegativeInfinity, resultTable.Rows[0][2]);
770+
Assert.AreEqual(null, resultTable.Rows[0][3]);
771+
Assert.AreEqual(123, resultTable.Rows[0][4]);
772+
}
756773
}
757774
}

sdk/monitor/Azure.Monitor.Query/tests/SessionRecords/LogsQueryClientClientLiveTests/ValidateNanAndInfResultsDoubleAsync.json

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/monitor/Azure.Monitor.Query/tests/SessionRecords/LogsQueryClientClientLiveTests/ValidateNanAndInfResultsDoubleAsyncAsync.json

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)